Class: Layouter::Leaf::Base
- Defined in:
- lib/layouter/leaf/base.rb
Direct Known Subclasses
Constant Summary collapse
- INF =
Float::INFINITY
- EPS =
Float::EPSILON
Instance Attribute Summary collapse
-
#importance ⇒ Object
readonly
Returns the value of attribute importance.
Attributes inherited from Element
#calculated_height, #calculated_width
Instance Method Summary collapse
-
#initialize(importance:) ⇒ Base
constructor
A new instance of Base.
- #layout(width, height) ⇒ Object
Methods inherited from Element
Constructor Details
#initialize(importance:) ⇒ Base
Returns a new instance of Base.
10 11 12 13 14 15 16 |
# File 'lib/layouter/leaf/base.rb', line 10 def initialize(importance:) super() if !importance.is_a?(Numeric) || importance < 0 raise(ArgumentError, "Invalid importance") end @importance = importance == 0 ? EPS : importance end |
Instance Attribute Details
#importance ⇒ Object (readonly)
Returns the value of attribute importance.
8 9 10 |
# File 'lib/layouter/leaf/base.rb', line 8 def importance @importance end |
Instance Method Details
#layout(width, height) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/layouter/leaf/base.rb', line 18 def layout(width, height) # These layout errors could occur in the dimension not being # distributed by the parent, or if the leaf is layed our directly. raise(LayoutError.new(:width, :too_small)) if width < min_width raise(LayoutError.new(:width, :too_big)) if width > max_width raise(LayoutError.new(:height, :too_small)) if height < min_height raise(LayoutError.new(:height, :too_big)) if height > max_height @calculated_width, @calculated_height = width, height end |