Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows you to specify right and bottom padding for resize_to_fit_subviews #195

Merged
merged 1 commit into from Feb 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions motion/ruby_motion_query/position.rb
Expand Up @@ -106,7 +106,7 @@ def distribute(type = :vertical, params = {})
self
end

def resize_to_fit_subviews
def resize_to_fit_subviews(padding = {})
selected.each do |view|
w = 0
h = 0
Expand All @@ -121,7 +121,7 @@ def resize_to_fit_subviews
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
Expand Down
29 changes: 29 additions & 0 deletions spec/position.rb
Expand Up @@ -118,6 +118,35 @@
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
Expand Down