Class: Tuile::Component::Layout::Percent

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

Overview

A percentage of the space available along a Box's axis — measured after Box#padding and Box#spacing have come off, so two Percent[50] children fit exactly rather than overflowing by the gap between them.

add(left, Percent[60])
add(right, Percent[40])

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(percent:) ⇒ Percent

@param percent — percentage of the available extent, 0..100.

Parameters:

  • percent: (Numeric)


54
55
56
57
58
59
60
# File 'lib/tuile/component/layout.rb', line 54

def initialize(percent:)
  unless percent.is_a?(Numeric) && percent.between?(0, 100)
    raise ArgumentError, "Percent expects a Numeric in 0..100, got #{percent.inspect}"
  end

  super
end

Instance Attribute Details

#percentNumeric (readonly)

@return — percentage of the available extent, 0..100.

Returns:

  • (Numeric)


51
52
53
54
55
56
57
58
59
60
61
# File 'lib/tuile/component/layout.rb', line 51

class Percent < Data.define(:percent)
  # @param percent [Numeric] percentage of the available extent, `0..100`.
  # @raise [ArgumentError] unless `percent` is a Numeric in `0..100`.
  def initialize(percent:)
    unless percent.is_a?(Numeric) && percent.between?(0, 100)
      raise ArgumentError, "Percent expects a Numeric in 0..100, got #{percent.inspect}"
    end

    super
  end
end