Class: Layouter::Leaf::Base

Inherits:
Element
  • Object
show all
Defined in:
lib/layouter/leaf/base.rb

Direct Known Subclasses

Annotation, Custom, Spacer

Constant Summary collapse

INF =
Float::INFINITY
EPS =
Float::EPSILON

Instance Attribute Summary collapse

Attributes inherited from Element

#calculated_height, #calculated_width

Instance Method Summary collapse

Methods inherited from Element

#layout?

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

#importanceObject (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

Raises:



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