Method: Teacup::Layout#auto
- Defined in:
- lib/teacup/layout.rb
#auto(layout_view = top_level_view, layout_subviews = {}, &layout_block) ⇒ Object
Calling this method uses Nick Quaranto’s motion-layout gem to provide ASCII art style access to autolayout. It assigns all the subviews by stylename, and assigns self.view as the target view. Beyond that, it’s up to you to implement the layout methods:
auto do
metrics 'margin' => 20
vertical "|-[top]-margin-[bottom]-|"
horizontal "|-margin-[top]-margin-|"
horizontal "|-margin-[bottom]-margin-|"
end
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/teacup/layout.rb', line 241 def auto(layout_view=top_level_view, layout_subviews={}, &layout_block) raise "gem install 'motion-layout'" unless defined? Motion::Layout styled_subviews = layout_view.teacup_subviews.select { |v| v.stylename } styled_subviews.each do |view| if ! layout_subviews[view.stylename.to_s] layout_subviews[view.stylename.to_s] = view end end Motion::Layout.new do |layout| layout.view layout_view layout.subviews layout_subviews layout.instance_eval(&layout_block) end end |