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

Inherits:
Object
  • Object
show all
Includes:
Constraint
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)


150
151
152
153
154
155
156
# File 'lib/tuile/component/layout.rb', line 150

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

#weight ⇒ Integer (readonly)

@return — relative share of the leftover space.

Returns:

  • (Integer)


145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/tuile/component/layout.rb', line 145

class Expand < Data.define(:weight)
  include Constraint

  # @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

  # @api private
  # @param _available [Integer]
  # @return [nil] an Expand has no size of its own — see {Constraint#resolve}.
  def resolve(_available) = nil
end

Instance Method Details

#resolve(_available) ⇒ void

This method returns an undefined value.

@param _available

@return — an Expand has no size of its own — see Constraint#resolve.

Parameters:

  • _available (Integer)


161
# File 'lib/tuile/component/layout.rb', line 161

def resolve(_available) = nil