Class: RatatuiRuby::Layout::Size
- Inherits:
-
Object
- Object
- RatatuiRuby::Layout::Size
- Defined in:
- lib/ratatui_ruby/layout/size.rb
Overview
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
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
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)
– SPDX-SnippetEnd ++
Instance Method Summary collapse
-
#initialize(width: 0, height: 0) ⇒ Size
constructor
Creates a new Size.
Constructor Details
#initialize(width: 0, height: 0) ⇒ Size
Creates a new Size.
- width
-
Width in columns (Integer, coerced via Integer()).
- height
-
Height in rows (Integer, coerced via Integer()).
57 58 59 |
# File 'lib/ratatui_ruby/layout/size.rb', line 57 def initialize(width: 0, height: 0) super(width: Integer(width), height: Integer(height)) end |