class Opal::UI::Engine

Overview

Focus coordinator and input router for interactive Control instances. Coordinates Tab / Shift+Tab focus navigation, dispatches keyboard and mouse events to the active control, and provides synthetic event injection for automated testing and puppeting.

Defined in:

opal/ui/engine.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(controls : Enumerable(Control) = [] of Control) #

[View source]

Instance Method Detail

def add(control : Control) : self #

Adds a control to the engine. If it's the first control, it receives focus.


[View source]
def blur : self #

Blurs all controls (unsets focused? on all).


[View source]
def controls : Array(Control) #

[View source]
def controls=(controls : Array(Control)) #

[View source]
def focus(control : Control) : self #

Moves focus to the given control.


[View source]
def focus_at(index : Int32) : self #

Moves focus to the control at the specified index.


[View source]
def focus_next : self #

Cycles focus forward to the next control.


[View source]
def focus_prev : self #

Cycles focus backward to the previous control.


[View source]
def focused_control : Control | Nil #

Returns the currently focused control, if any.


[View source]
def focused_index : Int32 #

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

[View source]
def handle_input(event : InputEvent) : Bool #

General input event router (dispatches KeyEvent or MouseEvent).


[View source]
def handle_key(key : Terminal::KeyEvent) : Bool #

Dispatches a key event. Intercepts Tab / Shift+Tab for navigation if enabled, otherwise routes to the focused control.


[View source]
def handle_mouse(mouse : Terminal::MouseEvent) : Bool #

Dispatches a mouse event to the focused control.


[View source]
def on_focus_change : Proc(Control | Nil, Control | Nil, Nil) | Nil #

[View source]
def on_focus_change=(on_focus_change : Proc(Control | Nil, Control | Nil, Nil) | Nil) #

[View source]
def puppet(control : Control, &block : Control, InputEvent -> Bool) : self #

Attaches a puppeting hook to a managed control.


[View source]
def puppet_step(&block : Control -> Nil) : self #

Executes an arbitrary mutation step on the currently focused control.


[View source]
def remove(control : Control) : self #

Removes a control from the engine and adjusts the active focus.


[View source]
def send_key(name : String, char : Char | Nil = nil, ctrl : Bool = false, alt : Bool = false, shift : Bool = false) : Bool #

Injects a synthetic key event for automated scripting or testing.


[View source]
def send_mouse(x : Int32, y : Int32, button : Terminal::MouseButton = Terminal::MouseButton::Left, action : Terminal::MouseAction = Terminal::MouseAction::Press, ctrl : Bool = false, alt : Bool = false, shift : Bool = false) : Bool #

Injects a synthetic mouse event for automated scripting or testing.


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

[View source]
def tab_navigation? : Bool #

[View source]