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] collapses the child: it and its whole subtree get an empty rect and paint nothing. That is not the same as hiding it — an empty rect is a paint convention and gates nothing else, so the subtree keeps its tab stops and still takes keys. To hide a child, set Tuile::Component#visible= false; it then costs no Box#spacing gap either, where a collapsed child still does. The difference is exactly that: a collapsed child is still a member of the sequence, a hidden one is not (D_visibility).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cells:) ⇒ Fixed

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

Parameters:

  • cells: (Integer)


40
41
42
43
44
45
46
# File 'lib/tuile/component/layout.rb', line 40

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)


37
38
39
40
41
42
43
44
45
46
47
# File 'lib/tuile/component/layout.rb', line 37

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