Class: Milktea::Container
Overview
Container model with layout capabilities using Flexbox
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bounds ⇒ Object
readonly
Returns the value of attribute bounds.
Attributes inherited from Model
Class Method Summary collapse
-
.child(klass, mapper = nil, flex: 1) ⇒ Object
Define a child model with optional state mapping and flex properties.
-
.direction(dir) ⇒ Object
Set the flex direction for the container.
-
.flex_direction ⇒ Symbol
Get the flex direction (defaults to :column).
Instance Method Summary collapse
-
#initialize(state = {}) ⇒ Container
constructor
A new instance of Container.
- #view ⇒ Object
Methods inherited from Model
children, #children_views, #screen_height, #screen_size, #screen_width, #update, #with
Constructor Details
#initialize(state = {}) ⇒ Container
Returns a new instance of Container.
35 36 37 38 39 |
# File 'lib/milktea/container.rb', line 35 def initialize(state = {}) @bounds = extract_bounds(state) # Remove bounds keys from state before passing to parent super(state.except(:width, :height, :x, :y)) end |
Instance Attribute Details
#bounds ⇒ Object (readonly)
Returns the value of attribute bounds.
6 7 8 |
# File 'lib/milktea/container.rb', line 6 def bounds @bounds end |
Class Method Details
.child(klass, mapper = nil, flex: 1) ⇒ Object
Define a child model with optional state mapping and flex properties
13 14 15 16 17 18 19 20 |
# File 'lib/milktea/container.rb', line 13 def child(klass, mapper = nil, flex: 1) @children ||= [] @children << { class: klass, mapper: mapper || ->(_state) { {} }, flex: flex } end |
.direction(dir) ⇒ Object
Set the flex direction for the container
24 25 26 |
# File 'lib/milktea/container.rb', line 24 def direction(dir) @direction = dir end |
.flex_direction ⇒ Symbol
Get the flex direction (defaults to :column)
30 31 32 |
# File 'lib/milktea/container.rb', line 30 def flex_direction @direction || :column end |
Instance Method Details
#view ⇒ Object
41 |
# File 'lib/milktea/container.rb', line 41 def view = children_views |