abstract class TUI::Widget

Direct Known Subclasses

Defined in:

tui/widget/widget.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(x : Int32, y : Int32, width : Int32, height : Int32) #

[View source]

Instance Method Detail

def absolute(row : Int32, col : Int32) : NamedTuple(row: Int32, col: Int32) #

Translate a LOCAL (row, col) offset — as used by #render's own coordinate space, e.g. Form#cursor_offset — into absolute 1-based terminal coordinates suitable for Term.move. Mirrors the arithmetic #composite already performs internally via Screen#blit.


[View source]
def composite(screen : Screen) : Nil #

Called by the compositor (App) once per frame instead of #render. Owns the buffer lifecycle: resizes/clears it, invokes the subclass's #render, then blits the result onto the screen at (x, y).


[View source]
def focus_if(condition : Bool) : Nil #

The recommended way to manage focus when multiple widgets are visible at once: recompute it every frame from whatever state determines which widget is active (e.g. table_list.focus_if(nav.current.is_a?(NavTableList))) rather than mutating #focused= incrementally at scattered call sites.


[View source]
def focused=(focused : Bool) #

[View source]
def focused? : Bool #

[View source]
abstract def handle_key(ev : KeyEvent) : Bool #

Returns true if the key was consumed.


[View source]
def height : Int32 #

[View source]
def height=(height : Int32) #

[View source]
def local(row : Int32, col : Int32) : NamedTuple(row: Int32, col: Int32) #

Inverse of #absolute: translate an ABSOLUTE 1-based terminal coordinate (e.g. a KeyEvent's mouse row/col) into this widget's LOCAL coordinate space. Result may fall outside [0, width)/[0, height) if the point is outside this widget's bounds — callers should bounds-check.


[View source]
abstract def render : Nil #

Draw into @buffer using LOCAL coordinates (0, 0 = this widget's own top-left). Widgets never need to know their own x/y offset to draw themselves — that arithmetic is handled entirely by #composite.


[View source]
def render_to(buffer : Buffer) : Nil #

Draws this widget into an arbitrary caller-supplied buffer instead of the screen — for a host that owns its own composed buffer rather than the real screen (e.g. ScrollableWidget, adapting a plain Widget into a SplitWindow pane, which only blits Scrollable content into a sub-buffer it controls). buffer must already be sized to width/height; unlike #composite this never blits anywhere itself, leaving that to the caller.


[View source]
abstract def status_hint : String #

Plain text describing the actions available in the widget's current state. Rendered by the App in the global status bar at the bottom of the screen — widgets must NOT draw their own hint lines.


[View source]
def width : Int32 #

[View source]
def width=(width : Int32) #

[View source]
def x : Int32 #

1-based absolute terminal coordinates and size of this widget within the compositor (see #composite/Screen#blit) — never touched by the widget's own #render, which always draws in its own local (0, 0) space. #focused? gates whether this widget's #handle_key should be given a chance to consume the current event; toggle it via #focus_if.


[View source]
def x=(x : Int32) #

1-based absolute terminal coordinates and size of this widget within the compositor (see #composite/Screen#blit) — never touched by the widget's own #render, which always draws in its own local (0, 0) space. #focused? gates whether this widget's #handle_key should be given a chance to consume the current event; toggle it via #focus_if.


[View source]
def y : Int32 #

[View source]
def y=(y : Int32) #

[View source]