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. It exists for exactly one job: sizing a
Component::Popup against the screen. A popup has no siblings competing for
space and no rectangle in a tiled layout, so "half the screen, centered" is
the sensible default, and that wants a ratio rather than a hard-coded cell
count that would be wrong on the next terminal size.
Tiled components are not sized this way: their parent computes explicit
integer rects in its own rect= and hands them down. Fraction is
deliberately scoped to Component::Popup#size= and is not a general layout
primitive.
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.
25 26 27 |
# File 'lib/tuile/fraction.rb', line 25 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).
34 35 36 37 |
# File 'lib/tuile/fraction.rb', line 34 def resolve(reference) Size.new([(reference.width * width).round, 1].max, [(reference.height * height).round, 1].max) end |