Class: Tuile::Component::Layout::Expand

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

Overview

A share of whatever a Box has left once its Fixed and Percent children have taken theirs, split between the Expand children in proportion to their weights:

add(header, Fixed[1])
add(body, Expand[2])    # gets twice…
add(side, Expand[1])    # …what this one gets

Main axis only — Box#add rejects one passed as cross:, where a child has no siblings to compete with and so nothing for a weight to mean.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(weight:) ⇒ Expand

@param weight — relative share; >= 1.

Parameters:

  • weight: (Integer)


79
80
81
82
83
84
85
# File 'lib/tuile/component/layout.rb', line 79

def initialize(weight:)
  unless weight.is_a?(Integer) && weight.positive?
    raise ArgumentError, "Expand expects a positive Integer weight, got #{weight.inspect}"
  end

  super
end

Instance Attribute Details

#weightInteger (readonly)

@return — relative share of the leftover space.

Returns:

  • (Integer)


76
77
78
79
80
81
82
83
84
85
86
# File 'lib/tuile/component/layout.rb', line 76

class Expand < Data.define(:weight)
  # @param weight [Integer] relative share; `>= 1`.
  # @raise [ArgumentError] unless `weight` is a positive Integer.
  def initialize(weight:)
    unless weight.is_a?(Integer) && weight.positive?
      raise ArgumentError, "Expand expects a positive Integer weight, got #{weight.inspect}"
    end

    super
  end
end