class RatatuiRuby::Layout::Position
A position in terminal coordinates.
Layout code passes x/y pairs between functions. Bundling them into separate variables is verbose and prone to ordering mistakes.
This class wraps column and row into a single immutable object. Pass it around, destructure it, or convert from a Rect.
Use it for cursor positioning, mouse coordinates, or anywhere you need to represent a single point on the terminal grid.
Example
pos = Layout::Position.new(x: 10, y: 5) puts "Cursor at column #{pos.x}, row #{pos.y}" # Extract from a Rect rect = Layout::Rect.new(x: 10, y: 5, width: 80, height: 24) pos = rect.as_position # => Position(x: 10, y: 5)
Attributes
Column index (0-indexed from left edge).
Row index (0-indexed from top edge).
Public Class Methods
Source
# File lib/ratatui_ruby/layout/position.rb, line 50 def initialize(x: 0, y: 0) super(x: Integer(x), y: Integer(y)) end
Creates a new Position.
- x
-
Column index (Integer, coerced via +Integer()+).
- y
-
Row index (Integer, coerced via +Integer()+).
Public Instance Methods
Source
# File lib/ratatui_ruby/layout/position.rb, line 71 def deconstruct [x, y] end
Enables array destructuring for convenient coordinate extraction.
- Returns
-
Array of [x, y] coordinates.
Example
pos = Position.new(x: 10, y: 5) x, y = pos # Uses deconstruct puts "Column: #{x}, Row: #{y}"
Alias for implicit array conversion.
Enables ‘x, y = position` syntax by making Position respond to to_ary.