class RatatuiRuby::Constraint
Defines the sizing rule for a layout section.
Flexible layouts need rules. You canβt just place widgets at absolute coordinates; they must adapt to changing terminal sizes.
This class defines the rules of engagement. It tells the layout engine exactly how much space a section requires relative to others.
Mix and match fixed lengths, percentages, ratios, and minimums. Build layouts that breathe.
Examples
Constraint.length(5) # Exactly 5 cells Constraint.percentage(50) # Half the available space Constraint.min(10) # At least 10 cells, maybe more Constraint.fill(1) # Fill remaining space (weight 1)
Attributes
The type of constraint.
:length, :percentage, :min, :max, :fill, or :ratio.
The numeric value (or array for ratio) associated with the rule.
Public Class Methods
Source
# File lib/ratatui_ruby/schema/constraint.rb, line 79 def self.fill(v = 1) new(type: :fill, value: Integer(v)) end
Fills remaining space proportionally.
Constraint.fill(1) # Equal share Constraint.fill(2) # Double share
Fill constraints distribute any space left after satisfying strict rules. They behave like flex-grow. A fill(2) takes twice as much space as a fill(1).
- v
-
Proportional weight (Integer, default: 1).
Source
# File lib/ratatui_ruby/schema/constraint.rb, line 37 def self.length(v) new(type: :length, value: Integer(v)) end
Requests a fixed size.
Constraint.length(10) # 10 characters wide/high
- v
-
Number of cells (Integer).
Source
# File lib/ratatui_ruby/schema/constraint.rb, line 66 def self.max(v) new(type: :max, value: Integer(v)) end
Enforces a maximum size.
Constraint.max(10) # At most 10 cells
- v
-
Maximum cells (Integer).
Source
# File lib/ratatui_ruby/schema/constraint.rb, line 57 def self.min(v) new(type: :min, value: Integer(v)) end
Enforces a minimum size.
Constraint.min(5) # At least 5 cells
This section will grow if space permits, but never shrink below v.
- v
-
Minimum cells (Integer).
Source
# File lib/ratatui_ruby/schema/constraint.rb, line 46 def self.percentage(v) new(type: :percentage, value: Integer(v)) end
Requests a percentage of available space.
Constraint.percentage(25) # 25% of the area
- v
-
Percentage 0-100 (Integer).
Source
# File lib/ratatui_ruby/schema/constraint.rb, line 89 def self.ratio(numerator, denominator) new(type: :ratio, value: [Integer(numerator), Integer(denominator)]) end
Requests a specific ratio of the total space.
Constraint.ratio(1, 3) # 1/3rd of the area
- numerator
-
Top part of fraction (Integer).
- denominator
-
Bottom part of fraction (Integer).