Class: Tuile::Fraction
- Inherits:
-
Object
- Object
- Tuile::Fraction
- Defined in:
- lib/tuile/fraction.rb,
sig/tuile.rbs
Overview
A width/height ratio, each a float in 0.0..1.0 — the single relational
sizing primitive in Tuile, scoped to one job: sizing a Component::Popup
against the screen (a popup has no siblings competing for space, so "half
the screen, centered" beats a hard-coded cell count that breaks on the next
terminal size). It is deliberately not a general layout primitive — tiled
components get explicit integer rects computed by their parent's rect=.
See book ch3 for the layout model.
Resolve it against a reference Size (the screen) to get concrete integer cells:
Fraction::HALF.resolve(Size.new(80, 24)) # => 40x12
Integer arguments are coerced to float, so Fraction.new(1, 1) == FULL.
Constant Summary collapse
- HALF =
Half the reference size on each axis — the default Component::Popup size.
new(0.5, 0.5)
- FULL =
The full reference size on each axis — fullscreen for a Component::Popup.
new(1.0, 1.0)
Instance Method Summary collapse
-
#initialize(width:, height:) ⇒ Fraction
constructor
@param
width— fraction of the reference width,0.0..1.0. -
#resolve(reference) ⇒ Size
Resolves this fraction against a reference size, rounding each axis to the nearest cell and flooring at 1 — so a fraction never yields a zero-size result on a tiny terminal.
Constructor Details
#initialize(width:, height:) ⇒ Fraction
@param width — fraction of the reference width, 0.0..1.0.
@param height — fraction of the reference height, 0.0..1.0.
21 22 23 |
# File 'lib/tuile/fraction.rb', line 21 def initialize(width:, height:) super(width: width.to_f, height: height.to_f) end |
Instance Method Details
#resolve(reference) ⇒ Size
Resolves this fraction against a reference size, rounding each axis to the nearest cell and flooring at 1 — so a fraction never yields a zero-size result on a tiny terminal.
@param reference — the size to take a fraction of (usually the screen).
30 31 32 33 |
# File 'lib/tuile/fraction.rb', line 30 def resolve(reference) Size.new([(reference.width * width).round, 1].max, [(reference.height * height).round, 1].max) end |