Class: RubyTUI::Layout::Constraint
- Inherits:
-
Object
- Object
- RubyTUI::Layout::Constraint
- Defined in:
- lib/rubytui/layout/constraint.rb
Overview
A sizing rule for one segment of a Layout split.
Create instances with the factory methods; Layout#split resolves them. Fixed constraints (Constraint.length, Constraint.percentage, Constraint.ratio) are allocated first, then the remaining space is shared among Constraint.fill, Constraint.min and Constraint.max constraints.
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.fill(weight = 1) ⇒ Constraint
A share of the space left after fixed constraints, proportional to
weight(+min+ andmaxconstraints count as weight 1). -
.length(n) ⇒ Constraint
Fixed size, reduced if less space remains.
-
.max(n) ⇒ Constraint
A weight-1 share of the space left after fixed constraints, capped at
ncells. -
.min(n) ⇒ Constraint
At least
ncells when space allows, plus a weight-1 share of the space left after fixed constraints. -
.percentage(n) ⇒ Constraint
Percentage of the available space, rounded; reduced if less space remains.
-
.ratio(num, den) ⇒ Constraint
Fraction num / den of the available space, rounded; reduced if less space remains.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Value equality: same kind and value.
-
#initialize(kind, value) ⇒ Constraint
constructor
A new instance of Constraint.
-
#inspect ⇒ String
Same as #to_s.
-
#to_s ⇒ String
Human-readable form, e.g.
Constructor Details
#initialize(kind, value) ⇒ Constraint
Returns a new instance of Constraint.
25 26 27 28 |
# File 'lib/rubytui/layout/constraint.rb', line 25 def initialize(kind, value) @kind = kind @value = value end |
Instance Attribute Details
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
20 21 22 |
# File 'lib/rubytui/layout/constraint.rb', line 20 def kind @kind end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
20 21 22 |
# File 'lib/rubytui/layout/constraint.rb', line 20 def value @value end |
Class Method Details
.fill(weight = 1) ⇒ Constraint
A share of the space left after fixed constraints, proportional to
weight (+min+ and max constraints count as weight 1).
59 60 61 62 63 64 65 |
# File 'lib/rubytui/layout/constraint.rb', line 59 def fill(weight = 1) = new(:fill, weight) # Fraction <tt>num / den</tt> of the available space, rounded; reduced if # less space remains. # # @param num [Integer] numerator # @param den [Integer] denominator # @return [Constraint] |
.length(n) ⇒ Constraint
Fixed size, reduced if less space remains.
36 37 38 39 40 |
# File 'lib/rubytui/layout/constraint.rb', line 36 def length(n) = new(:length, n) # Percentage of the available space, rounded; reduced if less space remains. # # @param n [Numeric] percentage (0-100) # @return [Constraint] |
.max(n) ⇒ Constraint
A weight-1 share of the space left after fixed constraints, capped
at n cells.
53 54 55 56 57 58 |
# File 'lib/rubytui/layout/constraint.rb', line 53 def max(n) = new(:max, n) # A share of the space left after fixed constraints, proportional to # +weight+ (+min+ and +max+ constraints count as weight 1). # # @param weight [Integer] relative weight (default: 1) # @return [Constraint] |
.min(n) ⇒ Constraint
At least n cells when space allows, plus a weight-1 share of the
space left after fixed constraints.
47 48 49 50 51 52 |
# File 'lib/rubytui/layout/constraint.rb', line 47 def min(n) = new(:min, n) # A weight-1 share of the space left after fixed constraints, capped # at +n+ cells. # # @param n [Integer] maximum size in cells # @return [Constraint] |
.percentage(n) ⇒ Constraint
Percentage of the available space, rounded; reduced if less space remains.
41 42 43 44 45 46 |
# File 'lib/rubytui/layout/constraint.rb', line 41 def percentage(n) = new(:percentage, n) # At least +n+ cells when space allows, plus a weight-1 share of the # space left after fixed constraints. # # @param n [Integer] minimum size in cells # @return [Constraint] |
.ratio(num, den) ⇒ Constraint
Fraction num / den of the available space, rounded; reduced if less space remains.
66 |
# File 'lib/rubytui/layout/constraint.rb', line 66 def ratio(num, den) = new(:ratio, [num, den].freeze) |
Instance Method Details
#==(other) ⇒ Boolean
Value equality: same kind and value.
73 74 75 |
# File 'lib/rubytui/layout/constraint.rb', line 73 def ==(other) other.is_a?(Constraint) && @kind == other.kind && @value == other.value end |
#inspect ⇒ String
Returns same as #to_s.
80 |
# File 'lib/rubytui/layout/constraint.rb', line 80 def inspect = to_s |
#to_s ⇒ String
Returns human-readable form, e.g. Constraint(length: 3).
78 79 |
# File 'lib/rubytui/layout/constraint.rb', line 78 def to_s = "Constraint(#{@kind}: #{@value})" # @return [String] same as {#to_s} |