class

Opal::UI::ContentSwitcher

Inherits Opal::UI::Control < Opal::UI::InputHookable < Opal::UI::Element < Opal::UI::Themable < Reference < Object

Container that manages multiple child views and displays only the active one by key. Inspired by Python Textual's ContentSwitcher. Preserves child element states across view switches without rebuilding trees.

Constructors

new(views : Hash(String, Element) = {} of String => Element, current : String | Nil = nil)
Source

Instance methods

active_element

Returns currently active element

Source
children

Returns child elements for hierarchical tree traversal and DOM querying

Source
current
Source
current=(current : String | Nil)
Source
handle_key(event : Terminal::KeyEvent) : Bool

Default key event handler. Override in subclasses if not using @default_input_proc.

Source
handle_mouse(event : Terminal::MouseEvent) : Bool

Default mouse event handler. Override in subclasses if not using @default_input_proc.

Source
preferred_size(available_w : Int32, available_h : Int32) : Tuple(Int32, Int32)
Source
render(buffer : Buffer, x : Int32, y : Int32, width : Int32, height : Int32) : Nil
Source
set_view(name : String, element : Element) : self

Adds a named child view to the switcher

Source
switch_to(name : String) : self

Switches active view by name

Source
views
Source