mirror of
https://github.com/zhigang1992/rmq.git
synced 2026-01-12 17:52:17 +08:00
Merge pull request #195 from infinitered/resize_to_fit_subviews_padding
Allows you to specify right and bottom padding for resize_to_fit_subviews
This commit is contained in:
@@ -106,7 +106,7 @@ module RubyMotionQuery
|
||||
self
|
||||
end
|
||||
|
||||
def resize_to_fit_subviews
|
||||
def resize_to_fit_subviews(padding = {})
|
||||
selected.each do |view|
|
||||
w = 0
|
||||
h = 0
|
||||
@@ -121,7 +121,7 @@ module RubyMotionQuery
|
||||
w = rect.width if w == 0
|
||||
h = rect.height if h == 0
|
||||
|
||||
view.rmq.layout(w: w, h: h)
|
||||
view.rmq.layout(w: (w + (padding[:right] || 0)), h: (h + (padding[:bottom] || 0)))
|
||||
end
|
||||
|
||||
self
|
||||
|
||||
@@ -118,6 +118,35 @@ describe 'position' do
|
||||
view.size.height.should == 500
|
||||
end
|
||||
|
||||
it 'should resize to fit subviews with padding' do
|
||||
view = @vc.rmq.append(UIView).layout(h: 100, w: 20).get
|
||||
view.rmq.append(UIButton).layout(h: 50, w: 10)
|
||||
view.rmq.append(UILabel).layout(h: 500, w: 70)
|
||||
view.rmq.append(UIView).layout(h: 5, w: 1)
|
||||
view.size.width.should == 20
|
||||
view.size.height.should == 100
|
||||
|
||||
# Just right
|
||||
view.rmq.resize_to_fit_subviews({right: 101})
|
||||
view.size.width.should == 171
|
||||
view.size.height.should == 500
|
||||
|
||||
# Just bottom
|
||||
view.rmq.resize_to_fit_subviews({bottom: 13})
|
||||
view.size.width.should == 70
|
||||
view.size.height.should == 513
|
||||
|
||||
# Both right & bottom
|
||||
view.rmq.resize_to_fit_subviews({right: 101, bottom: 13})
|
||||
view.size.width.should == 171
|
||||
view.size.height.should == 513
|
||||
|
||||
# Negative values
|
||||
view.rmq.resize_to_fit_subviews({right: -1, bottom: -1})
|
||||
view.size.width.should == 69
|
||||
view.size.height.should == 499
|
||||
end
|
||||
|
||||
it 'should nudge a view in various directions' do
|
||||
view = @vc.rmq.append(UILabel).get
|
||||
view.origin.x.should == 0
|
||||
|
||||
Reference in New Issue
Block a user