diff --git a/motion/ruby_motion_query/stylers/ui_view_styler.rb b/motion/ruby_motion_query/stylers/ui_view_styler.rb index 1b8c0dd..1e1c878 100644 --- a/motion/ruby_motion_query/stylers/ui_view_styler.rb +++ b/motion/ruby_motion_query/stylers/ui_view_styler.rb @@ -34,12 +34,13 @@ module RubyMotionQuery elsif value.is_a?(Hash) f = @view.frame h = value - h[:l] ||= (h[:left] || f.origin.x) - h[:t] ||= (h[:top] || f.origin.y) - h[:w] ||= (h[:width] || f.size.width) - h[:h] ||= (h[:height] || f.size.width) - @view.frame = [[h[:l], h[:t]], [h[:w], h[:h]]] + f.origin.x = h[:l] || h[:left] || f.origin.x + f.origin.y = h[:t] || h[:top] || f.origin.y + f.size.width = h[:w] || h[:width] || f.size.width + f.size.height =h[:h] || h[:height] || f.size.height + + @view.frame = f end end def frame @@ -47,8 +48,6 @@ module RubyMotionQuery end def padded=(value) - #st.padded = {l: 10, t: 10, b:10, r: 10} - if value.is_a?(Hash) h = value h[:l] ||= (h[:left] || 0) @@ -67,7 +66,6 @@ module RubyMotionQuery @view.frame = value end - end def left=(value) diff --git a/spec/stylers/_ui_view_styler.rb b/spec/stylers/_ui_view_styler.rb index 53fbe6d..1e4cb89 100644 --- a/spec/stylers/_ui_view_styler.rb +++ b/spec/stylers/_ui_view_styler.rb @@ -5,6 +5,18 @@ class SyleSheetForUIViewStylerTests < RubyMotionQuery::Stylesheet st.background_color = color.red end + def complete_frame(st) + st.frame = {l: 5, top: 10, w: 20, height: 30} + end + + def partial_frame_size(st) + st.frame = {width: 20, h: 30} + end + + def partial_frame_location(st) + st.frame = {left: 5, t: 10} + end + def ui_view_kitchen_sink(st) st.frame = {l: 1, t: 2, w: 3, h: 4} st.frame = {left: 1, top: 2, width: 3, height: 4} @@ -35,6 +47,7 @@ class SyleSheetForUIViewStylerTests < RubyMotionQuery::Stylesheet st.scale = 1.5 end + end shared 'styler' do @@ -88,6 +101,8 @@ shared 'styler' do view.backgroundColor.should == UIColor.blueColor end + + it 'should apply a style with every UIViewStyler wrapper method' do view = @vc.rmq.append(@view_klass, :ui_view_kitchen_sink).get @@ -106,4 +121,31 @@ describe 'ui_view_styler' do end behaves_like "styler" + + it 'should set frame' do + view = @vc.rmq.append(@view_klass, :complete_frame).get + view.frame.origin.x.should == 5 + view.frame.origin.y.should == 10 + view.frame.size.width.should == 20 + view.frame.size.height.should == 30 + end + + it 'should keep existing frame values if not an entire frame is specified' do + view = @vc.rmq.append(@view_klass).get + view.frame = [[1,2],[3,4]] + view.frame.size.width.should == 3 + + @vc.rmq(view).apply_style(:partial_frame_size) + view.frame.origin.x.should == 1 + view.frame.origin.y.should == 2 + view.frame.size.width.should == 20 + view.frame.size.height.should == 30 + + view.frame = [[1,2],[3,4]] + @vc.rmq(view).apply_style(:partial_frame_location) + view.frame.origin.x.should == 5 + view.frame.origin.y.should == 10 + view.frame.size.width.should == 3 + view.frame.size.height.should == 4 + end end