Class: Tuile::Component::Layout::Fixed

Inherits:
Object
  • Object
show all
Defined in:
lib/tuile/component/layout.rb,
sig/tuile.rbs

Overview

How much space a child gets along one axis of a Box: exactly #cells, clamped to whatever is still unassigned.

add(prompt, Fixed[4])                    # 4 rows in a Vertical
add(field, Fixed[1], cross: Fixed[30])   # 1 row, 30 columns wide

Fixed[0] hides the child — it gets an empty rect and paints nothing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cells:) ⇒ Fixed

@param cells — cell count along the axis; >= 0.

Parameters:

  • cells: (Integer)


33
34
35
36
37
38
39
# File 'lib/tuile/component/layout.rb', line 33

def initialize(cells:)
  unless cells.is_a?(Integer) && !cells.negative?
    raise ArgumentError, "Fixed expects a non-negative Integer, got #{cells.inspect}"
  end

  super
end

Instance Attribute Details

#cellsInteger (readonly)

@return — cell count along the axis.

Returns:

  • (Integer)


30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tuile/component/layout.rb', line 30

class Fixed < Data.define(:cells)
  # @param cells [Integer] cell count along the axis; `>= 0`.
  # @raise [ArgumentError] unless `cells` is a non-negative Integer.
  def initialize(cells:)
    unless cells.is_a?(Integer) && !cells.negative?
      raise ArgumentError, "Fixed expects a non-negative Integer, got #{cells.inspect}"
    end

    super
  end
end