class RatatuiRuby::Rect
Defines a rectangular area in the terminal grid.
Geometry management involves passing groups of four integers (‘x, y, width, height`) repeatedly. This is verbose and prone to parameter mismatch errors.
This class encapsulates the geometry. It provides a standard primitive for passing area definitions between layout engines and rendering functions.
Use it when manual positioning is required or when querying layout results.
Examples
area = Rect.new(x: 0, y: 0, width: 80, height: 24) puts area.width # => 80
Attributes
Height in characters (Integer, coerced via to_int or to_i).
Width in characters (Integer, coerced via to_int or to_i).
X coordinate (column) of the top-left corner (Integer, coerced via to_int or to_i).
Y coordinate (row) of the top-left corner (Integer, coerced via to_int or to_i).
Public Class Methods
Source
# File lib/ratatui_ruby/schema/rect.rb, line 46 def initialize(x: 0, y: 0, width: 0, height: 0) super( x: Integer(x), y: Integer(y), width: Integer(width), height: Integer(height) ) end
Creates a new Rect.
All parameters accept any object responding to to_int or to_i (duck-typed).
- x
-
Column index (Numeric).
- y
-
Row index (Numeric).
- width
-
Width in columns (Numeric).
- height
-
Height in rows (Numeric).
Public Instance Methods
Source
# File lib/ratatui_ruby/schema/rect.rb, line 69 def contains?(px, py) px >= x && px < x + width && py >= y && py < y + height end
Tests whether a point is inside this rectangle.
Essential for hit testing mouse clicks against layout regions.
area = Rect.new(x: 10, y: 5, width: 20, height: 10) area.contains?(15, 8) # => true area.contains?(5, 8) # => false
- px
-
X coordinate to test (column).
- py
-
Y coordinate to test (row).
Returns true if the point (px, py) is within the rectangle bounds.