class RatatuiRuby::Layout::Size
Generic dimensions as width and height.
Layout calculations need sizes. Passing width and height as separate arguments is verbose and easy to swap by mistake.
This class bundles dimensions into a single immutable object. Extract it from a Rect or create it directly for sizing operations.
Following upstream Ratatui’s design, the same Size type represents both character-grid dimensions (columns × rows) and pixel dimensions. The semantic meaning depends on the source:
-
From
Terminal.sizeorWindowSize#columns_rows: columns and rows -
From
WindowSize#pixels: pixel width and height
Use it for terminal dimensions, widget sizing constraints, or anywhere you need width/height without position.
Example
size = Layout::Size.new(width: 80, height: 24) puts "Terminal is #{size.width} columns by #{size.height} rows" # Extract from a Rect rect = Layout::Rect.new(x: 10, y: 5, width: 80, height: 24) size = rect.as_size # => Size(width: 80, height: 24)
Attributes
Height dimension (rows for character grids, pixels for pixel sizes).
Width dimension (columns for character grids, pixels for pixel sizes).
Public Class Methods
Source
# File lib/ratatui_ruby/layout/size.rb, line 57 def initialize(width: 0, height: 0) super(width: Integer(width), height: Integer(height)) end
Creates a new Size.
- width
-
Width in columns (Integer, coerced via +Integer()+).
- height
-
Height in rows (Integer, coerced via +Integer()+).