|
Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
|
UI-owned focus and synchronous bubbling over an existing WidgetTree. Tree and Scheduler must outlive the router. Destroy on its creating UI thread outside a router callback; violation terminates. All operations reject wrong-thread calls before touching user state. Dispatch/invoke/bind reject nested dispatch with WOULD_BLOCK. References borrowed by handlers cannot escape. No terminal bytes or queue are produced. Allocation failures become NO_MEMORY; callback exceptions become CALLBACK_FAILED. Focus changes request paint; geometry invalidation never disables keyboard access. More...
#include <action.hpp>
Public Member Functions | |
| ~EventRouter () | |
| Disconnect and reclaim all captures on UI; tree must still exist. | |
| EventRouter (const EventRouter &)=delete | |
| EventRouter & | operator= (const EventRouter &)=delete |
| std::expected< void, TreeError > | setPointerCaptureCapabilities (PointerCaptureCapabilities capabilities) |
| Declare host motion/release guarantees, without terminal I/O. | |
| std::expected< PointerCapture, TreeError > | capturePointer (Node< Widget > owner, Node< Widget > focusRoot={}) |
| Capture LEFT continuation from this owner's currently admitted LEFT PRESS handler. | |
| std::expected< Node< Widget >, TreeError > | pointerCapture () |
| Revalidate action identity and visible/enabled ancestry without consulting geometry. | |
| std::expected< void, TreeError > | cancelPointerCapture (bool requestPaint=true) |
| Explicitly end capture for host resize, stop, capability loss or application policy. | |
| template<class T, class Callback> | |
| std::expected< ActionBinding, TreeError > | bind (Node< T > node, Callback &&callback, bool focusable=true) |
| Register one typed handler; the scoped token owns disconnect responsibility. Callback must be copy-constructible and return EventReply. Invocation uses tree.edit, retaining the widget and callback captures even if either is removed during the call. Duplicate registration is INVALID_ARGUMENT; full registry is NODE_LIMIT. Removed or disconnected records are reclaimed before accepting a new registration. | |
| template<class T, class Callback, class FocusCallback> requires std::invocable<FocusCallback &, T &, bool> | |
| std::expected< ActionBinding, TreeError > | bind (Node< T > node, Callback &&callback, FocusCallback &&focusCallback, bool focusable=true) |
| Register input and optional synchronous focus delivery in one scoped registration. Focus loss precedes gain and the next routed input. Delivery does not bubble; a live hidden or disabled previous target still receives loss. Removed/disconnected targets are skipped. Callbacks may remove nodes; nested focus changes or input delivery return WOULD_BLOCK. A callback error does not undo the published focus or model effects. | |
| std::expected< ActionBinding, TreeError > | focusScope (Node< Widget > root, Node< Widget > defaultTarget={}) |
| Declare a nested focus scope using an existing owning disconnect token. Scope and action records share max_registrations. A scope can share its root with an action. | |
| std::expected< void, TreeError > | focusDefault (Node< Widget > node) |
| Set the default of the nearest live enclosing scope without changing current focus. | |
| std::expected< Node< Widget >, TreeError > | enterScope (Node< Widget > root) |
| Enter a declared scope at its eligible last/default/preorder target. | |
| std::expected< Node< Widget >, TreeError > | enterFocusScope (Node< Widget > root) |
| Enter a scope while saving exact focus and ancestry for a later return. This focus-only stack does not shield input or restrict global Tab traversal. | |
| std::expected< Node< Widget >, TreeError > | leaveFocusScope (Node< Widget > root) |
| Leave the top scope and restore eligible saved focus, scope fallback or global fallback. Ended outer records unwind together. Hidden/disabled/removed/disconnected scope roots also unwind lazily on the next focus query or input dispatch. Saved identities include generations. | |
| std::expected< Node< Widget >, TreeError > | focused () |
| Recover focus if needed; empty Node means no eligible focusable registration. Recovery tries containing scopes, then global history and the first preorder node. If its callbacks retire the selected target, return empty; the next call may recover again. | |
| std::expected< void, TreeError > | setFocus (Node< Widget > node) |
| Focus a live eligible registered node, or return INVALID_ARGUMENT; requests paint. | |
| std::expected< Node< Widget >, TreeError > | traverse (bool reverse=false) |
| Traverse eligible registrations in tree preorder with wrap; reverse implements Shift+Tab. Scope boundaries preserve the full global order; remembered/default entry is explicit via enterScope. A managed modal restricts traversal to its active subtree. | |
| std::expected< Node< Widget >, TreeError > | hitTest (CellPoint point) |
| Hit target in paint order; descendants and later sibling subtrees take precedence. Only fresh, clipped geometry participates. Returns an empty Node for a miss. Nonregistered nodes may be targets and bubble to ancestors. | |
| std::expected< DispatchResult, TreeError > | dispatch (const InputEvent &event) |
| Deliver decoded input synchronously; replies/issues are ignored. Unmodified Tab/Shift+Tab traverse. Enter/Escape/arrows/Home/End/Backspace/Delete map to actions; release and other keys remain KeyEvent. Text (including space), paste and mouse retain type. Left press focuses the nearest focusable target ancestor before bubbling the mouse event. If focus callbacks retire the original hit, suppress delivery without retargeting it. Managed nonmodal pointer input does not steal focus. A modal consumes outside physical input, and layer bubbling stops at the structural dialog root. | |
| std::expected< DispatchResult, TreeError > | invoke (Node< Widget > target, ActionEvent action) |
| Invoke the same handler path with a semantic command; target need not be focusable. Foreign/stale targets return their tree error. Ineligible targets return DispatchStatus::NO_TARGET. A managed modal rejects an explicit outside target with INVALID_ARGUMENT. | |
Static Public Member Functions | |
| static std::expected< std::unique_ptr< EventRouter >, TreeError > | create (WidgetTree &tree, EventRouterOptions options={}) |
| Validate the tree's owner thread and create a bounded router. | |
Friends | |
| class | ManagedScene |
| struct | detail::RowTreeAccess |
| struct | detail::EventRouterAccess |
UI-owned focus and synchronous bubbling over an existing WidgetTree. Tree and Scheduler must outlive the router. Destroy on its creating UI thread outside a router callback; violation terminates. All operations reject wrong-thread calls before touching user state. Dispatch/invoke/bind reject nested dispatch with WOULD_BLOCK. References borrowed by handlers cannot escape. No terminal bytes or queue are produced. Allocation failures become NO_MEMORY; callback exceptions become CALLBACK_FAILED. Focus changes request paint; geometry invalidation never disables keyboard access.
|
inline |
Register one typed handler; the scoped token owns disconnect responsibility. Callback must be copy-constructible and return EventReply. Invocation uses tree.edit, retaining the widget and callback captures even if either is removed during the call. Duplicate registration is INVALID_ARGUMENT; full registry is NODE_LIMIT. Removed or disconnected records are reclaimed before accepting a new registration.
| T | Widget or a publicly derived extension type represented by node. |
| Callback | Copy-constructible callable invocable as an lvalue with T& and const RoutedEvent&, returning exactly EventReply. |
| node | Live target; hidden or disabled nodes can register but cannot receive input until eligible. |
| callback | Owned handler; borrowed widget/event references must not escape the invocation. |
| focusable | Whether this registration participates in keyboard focus and traversal. |
|
inline |
Register input and optional synchronous focus delivery in one scoped registration. Focus loss precedes gain and the next routed input. Delivery does not bubble; a live hidden or disabled previous target still receives loss. Removed/disconnected targets are skipped. Callbacks may remove nodes; nested focus changes or input delivery return WOULD_BLOCK. A callback error does not undo the published focus or model effects.
| T | Registered widget type. |
| Callback | Owning copyable input handler returning EventReply. |
| FocusCallback | Owning copyable callable returning expected<void, TreeError>. |
| node | Live target of both callbacks. |
| callback | Input handler; widget/event borrows expire upon return. |
| focusCallback | Optional handler taking (T&, bool), true for gain and false for loss. |
| focusable | Whether the node participates in focus selection. |
| std::expected< void, TreeError > portals::EventRouter::cancelPointerCapture | ( | bool | requestPaint = true | ) |
Explicitly end capture for host resize, stop, capability loss or application policy.
| requestPaint | Whether a surviving owner needs one PAINT; false is appropriate during stop/cleanup. |
| std::expected< PointerCapture, TreeError > portals::EventRouter::capturePointer | ( | Node< Widget > | owner, |
| Node< Widget > | focusRoot = {} ) |
Capture LEFT continuation from this owner's currently admitted LEFT PRESS handler.
| owner | Live full identity of the currently executing action registration, inside any active managed modal. |
| focusRoot | Optional live ancestor containing owner, defaulting to owner. Only a subsequent focus transition outside this subtree cancels capture; existing external/empty focus is permitted. |
|
static |
Validate the tree's owner thread and create a bounded router.
| tree | Borrowed live tree whose UI thread owns this router; it must outlive the router. |
| options | Positive maximum number of live registrations. |
| std::expected< DispatchResult, TreeError > portals::EventRouter::dispatch | ( | const InputEvent & | event | ) |
Deliver decoded input synchronously; replies/issues are ignored. Unmodified Tab/Shift+Tab traverse. Enter/Escape/arrows/Home/End/Backspace/Delete map to actions; release and other keys remain KeyEvent. Text (including space), paste and mouse retain type. Left press focuses the nearest focusable target ancestor before bubbling the mouse event. If focus callbacks retire the original hit, suppress delivery without retargeting it. Managed nonmodal pointer input does not steal focus. A modal consumes outside physical input, and layer bubbling stops at the structural dialog root.
| event | Decoded input borrowed for this call; handlers must not retain references. |
| std::expected< Node< Widget >, TreeError > portals::EventRouter::enterFocusScope | ( | Node< Widget > | root | ) |
Enter a scope while saving exact focus and ancestry for a later return. This focus-only stack does not shield input or restrict global Tab traversal.
| root | Eligible declared scope, absent from the existing return stack. |
Enter a declared scope at its eligible last/default/preorder target.
| root | Live registered scope root; hidden/disabled subtrees select empty focus. |
Set the default of the nearest live enclosing scope without changing current focus.
| node | Live descendant to use when its scope has no eligible remembered target. |
Recover focus if needed; empty Node means no eligible focusable registration. Recovery tries containing scopes, then global history and the first preorder node. If its callbacks retire the selected target, return empty; the next call may recover again.
| std::expected< ActionBinding, TreeError > portals::EventRouter::focusScope | ( | Node< Widget > | root, |
| Node< Widget > | defaultTarget = {} ) |
Declare a nested focus scope using an existing owning disconnect token. Scope and action records share max_registrations. A scope can share its root with an action.
| root | Live subtree root; duplicate scopes return INVALID_ARGUMENT. |
| defaultTarget | Optional live descendant (including root), skipped while ineligible or stale. |
Hit target in paint order; descendants and later sibling subtrees take precedence. Only fresh, clipped geometry participates. Returns an empty Node for a miss. Nonregistered nodes may be targets and bubble to ancestors.
| point | Surface cell coordinate tested against arranged rectangles and ancestor clips. |
| std::expected< DispatchResult, TreeError > portals::EventRouter::invoke | ( | Node< Widget > | target, |
| ActionEvent | action ) |
Invoke the same handler path with a semantic command; target need not be focusable. Foreign/stale targets return their tree error. Ineligible targets return DispatchStatus::NO_TARGET. A managed modal rejects an explicit outside target with INVALID_ARGUMENT.
| target | Explicit live destination; focus is unchanged. |
| action | Owning semantic command and modifier intent to bubble along the original ancestry. |
| std::expected< Node< Widget >, TreeError > portals::EventRouter::leaveFocusScope | ( | Node< Widget > | root | ) |
Leave the top scope and restore eligible saved focus, scope fallback or global fallback. Ended outer records unwind together. Hidden/disabled/removed/disconnected scope roots also unwind lazily on the next focus query or input dispatch. Saved identities include generations.
| root | Exact top activation root; other roots return INVALID_ARGUMENT. |
Revalidate action identity and visible/enabled ancestry without consulting geometry.
Focus a live eligible registered node, or return INVALID_ARGUMENT; requests paint.
| node | Live, eligible node with a focusable registration. |
| std::expected< void, TreeError > portals::EventRouter::setPointerCaptureCapabilities | ( | PointerCaptureCapabilities | capabilities | ) |
Declare host motion/release guarantees, without terminal I/O.
| capabilities | Owning capability value; defaults are all false until explicitly declared. |
Traverse eligible registrations in tree preorder with wrap; reverse implements Shift+Tab. Scope boundaries preserve the full global order; remembered/default entry is explicit via enterScope. A managed modal restricts traversal to its active subtree.
| reverse | Traverse backward when true, forward otherwise; wrap at either end. |