class

Tui::Widget

Inherits Tui::Reactive / Reference / Object

Forward declaration for Widget (defined in widget.cr)

Constructors

new(id : String | Nil = nil)
Source

Class methods

focused_widget

Global focus and hover tracking

Source
focused_widget=(focused_widget : Widget | Nil)

Global focus and hover tracking

Source
handling_capture=(handling_capture : Bool)

Flag to prevent re-redirect when processing captured widget's children

Source
handling_capture?

Flag to prevent re-redirect when processing captured widget's children

Source
hovered_widget
Source
hovered_widget=(hovered_widget : Widget | Nil)
Source
mouse_capture

Mouse capture - widget that captures gets all mouse events

Source
mouse_capture=(mouse_capture : Widget | Nil)

Mouse capture - widget that captures gets all mouse events

Source

Instance methods

add_child(child : Widget) : Nil
Source
add_class(name : String) : Nil
Source
app

Find app (if attached)

Source
apply_css_style(style : Hash(String, CSS::Value)) : Nil

Apply CSS style properties to this widget Override in subclasses to handle specific properties

Source
blur
Source
capture_mouse

Capture all mouse events (for dragging)

Source
children
Source
classes
Source
classes=(classes : Set(String))
Source
clear_children
Source
collect_focusable

Collect all focusable widgets in tree order (depth-first)

Source
compose

Override to return child widgets

Source
constraints

Layout constraints (CSS-driven)

Source
constraints=(constraints : Constraints)

Layout constraints (CSS-driven)

Source
dirty?
Source
dock
Source
dock=(dock : Dock)
Source
find_widget_at(x : Int32, y : Int32) : Widget | Nil

Find the deepest visible widget at given coordinates

Source
focus

Request focus (convenience method)

Source
focus!

Alias for focus (bang version for Button etc.)

Source
focus_next

Focus next focusable widget (Tab behavior)

Source
focus_prev

Focus previous focusable widget (Shift+Tab behavior)

Source
focusable=(focusable : Bool)
Source
focusable?
Source
focused=(value : Bool) : Nil
Source
focused?

Focus management

Source
handle_event(event : Event) : Bool

KISS event handling with capture support Flow: on_capture → children → on_event Override on_capture to intercept before children Override on_event to handle after children

Source
has_class?(name : String) : Bool
Source
hovered=(value : Bool) : Nil
Source
hovered?

Hover management

Source
id

Identity

Source
id=(id : String | Nil)

Identity

Source
margin
Source
margin=(margin : BoxModel)
Source
mark_clean!
Source
mark_dirty!
Source
matches_selector?(selector : String) : Bool

Check if widget matches a simple selector

Source
mounted=(mounted : Bool)
Source
mounted?
Source
offset_x

Offset (shifts widget from calculated position)

Source
offset_x=(offset_x : Int32)

Offset (shifts widget from calculated position)

Source
offset_y
Source
offset_y=(offset_y : Int32)
Source
on_capture(event : Event) : Bool

Override to intercept events BEFORE they reach children (capture phase) Return true to stop propagation to children Use for: global hotkeys, modal dialogs, event filtering

Source
on_event(event : Event) : Bool

Override to handle events for this widget (target/bubble phase) Called after children have had a chance to handle the event

Source
on_key(event : KeyEvent) : Bool

Handle key event specifically (convenience method)

Source
on_mount

Called when widget is added to tree

Source
on_mouse(event : MouseEvent) : Bool

Handle mouse event specifically (convenience method)

Source
on_unmount

Called when widget is removed from tree

Source
opacity

Opacity (0.0 = transparent, 1.0 = opaque)

Source
opacity=(opacity : Float64)

Opacity (0.0 = transparent, 1.0 = opaque)

Source
padding
Source
padding=(padding : BoxModel)
Source
parent

Hierarchy

Source
parent=(parent : Widget | Nil)

Hierarchy

Source
query_all(selector : String) : Array(Widget)

Find all widgets matching selector

Source
query_one(selector : String, type : T.class) : T | Nil forall T

Find single widget by selector and type

Source
query_one(selector : String) : Widget | Nil

Find single widget by selector

Source
rect

Geometry (set by layout engine)

Source
rect=(rect : Rect)

Geometry (set by layout engine)

Source
release_mouse

Release mouse capture

Source
remove_child(child : Widget) : Nil
Source
remove_class(name : String) : Nil
Source
render(buffer : Buffer, clip : Rect) : Nil

Override to render widget content

Source
render_rect

Returns the rect needed for rendering (may be larger than layout rect) Override for widgets like dropdowns that render outside their bounds

Source
request_render

Request re-render (to be implemented by Widget)

Source
root_widget

Find root widget (named root_widget to avoid conflict with WindowManager.root)

Source
toggle_class(name : String) : Nil
Source
visible=(visible : Bool)

State

Source
visible?

State

Source
z_index

Z-order (higher = on top)

Source
z_index=(z_index : Int32)

Z-order (higher = on top)

Source

Nested types