|
Portals0.7.0 · dev (544a5c68c72e · 2026-11-28 UTC)
|
Exclusive parent/child ownership on Scheduler's UI thread. Scheduler must outlive this object. Destruction on another thread or inside a tree callback terminates; request close instead. All operations check affinity first. Logical removal is immediate and allocation-free, reclamation waits for the outermost borrow. References cannot escape edit/withScope/frame callbacks. Library allocations become NO_MEMORY; callback exceptions become CALLBACK_FAILED without undoing user effects. More...
#include <widget.hpp>
Public Types | |
| using | ErrorSink = void (*)(void *, NodeId, TreeError) noexcept |
| Nonthrowing UI error sink; context is borrowed until tree destruction. | |
Public Member Functions | |
| ~WidgetTree () | |
| Close and reclaim on UI, outside all callbacks. | |
| WidgetTree (const WidgetTree &)=delete | |
| WidgetTree & | operator= (const WidgetTree &)=delete |
| std::expected< Node< Widget >, TreeError > | root () const |
| Checked observing root; stale after root removal. | |
| std::expected< NodeSnapshot, TreeError > | inspect (Node< Widget > node) const |
| Copy live structure; may allocate. | |
| std::expected< bool, TreeError > | contains (Node< Widget > ancestor, Node< Widget > node) const |
| Test inclusive ancestry without allocating or invoking callbacks. | |
| std::expected< void, TreeError > | remove (Node< Widget > node) |
| Invalidate subtree/scopes now, reclaim at safe point. | |
| std::expected< void, TreeError > | close () |
| Idempotent coordinated shutdown, including during edit. | |
| template<class T, class Callback> | |
| std::expected< void, TreeError > | read (Node< T > node, Callback &&callback) |
| Borrow a const extension object, including inside frame traversal. The external layout owner can read its custom layout interface, then measure/arrange children using inspect snapshots. No reference may escape; callback returns void. | |
| template<class T, class... Args> requires std::derived_from<T, Widget> | |
| std::expected< Node< T >, TreeError > | emplace (Node< Widget > parent, Args &&...args) |
| Construct and exclusively attach a new child; constructors run only after validation. No attach/reparent exists, so cycles cannot be formed. Structural insertion during lifecycle or frame callbacks returns WOULD_BLOCK. A committed mount exception is reported to the sink; insertion still succeeds. Mount can remove itself, so a successful handle can already be stale. | |
| template<class T, class... Args> requires std::derived_from<T, Widget> | |
| std::expected< Node< T >, TreeError > | emplaceChecked (Node< Widget > parent, Args &&...args) |
| Checked construction, including mount and deferred reclamation. Uses the validation and construction boundary of emplace. Mount exceptions reach the error sink and retire the attempted subtree. External effects of constructors, lifecycle hooks and the sink are not rolled back. | |
| template<class T, class Callback> | |
| std::expected< void, TreeError > | edit (Node< T > node, Callback &&callback) |
| Borrow T only during a void callback; nested edit/removal is supported. Forbidden during measure/arrange/paint. No automatic invalidation: request it explicitly. | |
| template<class Callback> | |
| std::expected< void, TreeError > | withScope (Node< Widget > node, Callback &&callback) |
| Borrow the node-owned scope for registration with the existing Scheduler. Registrations borrowing widgets must use edit for their entire external callback, or connect/at below. The const scope must not be retained or moved out of the node. | |
| template<class Value, class T, class Callback> | |
| std::expected< SchedulerConnection< Value >, TreeError > | connect (Node< T > node, Callback &&callback, SchedulerLane lane=SchedulerLane::DATA, SchedulerOverflow overflow=SchedulerOverflow::REJECT) |
| Node-scoped typed delivery; the whole callback borrows T until return. Owns callback captures, returns the ordinary Scheduler token/publisher; no second bus. Exceptions report to the tree sink and disconnect through Scheduler's error boundary. | |
| template<class T, class Callback> | |
| std::expected< Subscription, TreeError > | at (Node< T > node, SchedulerTime deadline, Callback &&callback) |
| Node-scoped one-shot timer, with the same checked borrow as connect. | |
| std::expected< void, TreeError > | setVisible (Node< Widget > node, bool visible) |
| No-op if equal; otherwise layout. | |
| std::expected< void, TreeError > | setEnabled (Node< Widget > node, bool enabled) |
| No-op if equal; otherwise paint. | |
| std::expected< bool, TreeError > | inputEligible (Node< Widget > node) const |
| Live/visible/enabled ancestors; hit-test also needs valid geometry. | |
| std::expected< void, TreeError > | invalidate (Node< Widget > node, Invalidation kind) |
| Coalesce one frame request. | |
| std::expected< Invalidation, TreeError > | consumeFrameRequest () |
| Clear pending flags before processing the frame. | |
| Diagnostics * | diagnostics () const noexcept |
| Borrow the scheduler recorder without changing ownership. | |
| DiagnosticContext | diagnosticFrame () const noexcept |
| Get the most recently consumed frame's causal token on the UI thread. Pass this token to FrameWriter::submit after rendering. Multiple invalidations share a frameId and each retains its own causal record; the token identifies the first recorded cause. | |
| std::expected< CellSize, TreeError > | measure (Node< Widget > node, CellSize available) |
| Guarded extension call. | |
| std::expected< void, TreeError > | arrange (Node< Widget > node, CellRect local, CellRect viewport) |
| Arrange local geometry against the arranged parent and root viewport; invalidate on failure. The layout owner calls parent before children. Root uses viewport; descendants inherit clip. | |
| std::expected< void, TreeError > | arrange (Node< Widget > node, CellRect local, CellRect viewport, CellRect contentClip) |
| Arrange with an additional surface clip, inherited by this node's descendants. | |
| std::expected< void, TreeError > | paint (Node< Widget > node, PaintContext &context) |
| Requires an active frame borrow. | |
| template<class Callback> | |
| std::expected< void, TreeError > | frame (Callback &&callback) |
| Keep widget/text storage alive through traversal AND rendering of borrowed commands. Run layout/paint and renderFullFrame before returning. Tree/domain edit is rejected; inspect, measure, arrange and paint remain available. Callback must return void. | |
Static Public Member Functions | |
| static std::expected< std::unique_ptr< WidgetTree >, TreeError > | create (Scheduler &scheduler, WidgetTreeOptions options={}, ErrorSink sink=nullptr, void *context=nullptr) |
| Create a mounted plain root and bounded registry; no partial tree on failure. | |
Friends | |
| struct | detail::LayoutTraversalAccess |
| struct | detail::RowTreeAccess |
| class | EventRouter |
| class | RadioGroup |
| class | LayoutSnapshot |
| class | ManagedScene |
| class | StyleEngine |
Exclusive parent/child ownership on Scheduler's UI thread. Scheduler must outlive this object. Destruction on another thread or inside a tree callback terminates; request close instead. All operations check affinity first. Logical removal is immediate and allocation-free, reclamation waits for the outermost borrow. References cannot escape edit/withScope/frame callbacks. Library allocations become NO_MEMORY; callback exceptions become CALLBACK_FAILED without undoing user effects.
| std::expected< void, TreeError > portals::WidgetTree::arrange | ( | Node< Widget > | node, |
| CellRect | local, | ||
| CellRect | viewport ) |
Arrange local geometry against the arranged parent and root viewport; invalidate on failure. The layout owner calls parent before children. Root uses viewport; descendants inherit clip.
| node | Live widget whose geometry is replaced. |
| local | Parent-relative rectangle; for the root it is already in surface coordinates. |
| viewport | Root clipping rectangle; descendants inherit their parent's clip instead. |
| std::expected< void, TreeError > portals::WidgetTree::arrange | ( | Node< Widget > | node, |
| CellRect | local, | ||
| CellRect | viewport, | ||
| CellRect | contentClip ) |
Arrange with an additional surface clip, inherited by this node's descendants.
| node | Live widget whose geometry is replaced after its arranged parent. |
| local | Parent-relative allocation; root coordinates are already on the surface. |
| viewport | Root surface clip, with the unchanged three-argument semantics. |
| contentClip | Extra surface-cell clip intersected with the ordinary inherited/root clip. |
|
inline |
Node-scoped one-shot timer, with the same checked borrow as connect.
| T | Widget or a publicly derived extension type represented by node. |
| Callback | Copy-constructible callable accepting T& as an lvalue; its return value is ignored. |
| node | Live receiver whose scope cancels the timer on removal. |
| deadline | Absolute millisecond deadline in the scheduler clock. |
| callback | Callable copied/moved into the scheduler; widget references must not escape. |
| std::expected< void, TreeError > portals::WidgetTree::close | ( | ) |
Idempotent coordinated shutdown, including during edit.
|
inline |
Node-scoped typed delivery; the whole callback borrows T until return. Owns callback captures, returns the ordinary Scheduler token/publisher; no second bus. Exceptions report to the tree sink and disconnect through Scheduler's error boundary.
| Value | Transitively immutable snapshot type supporting destruction on any releasing thread. |
| T | Widget or a publicly derived extension type represented by node. |
| Callback | Copy-constructible callable accepting T& and std::shared_ptr<const Value> as an lvalue; its return value is ignored. |
| node | Live receiver whose scope cancels delivery on removal. |
| callback | Callable copied/moved into the scheduler; widget references must not escape. |
| lane | Scheduler queue whose capacity and budget apply. |
| overflow | Queue rejection or sender-local pending data replacement policy. |
| std::expected< Invalidation, TreeError > portals::WidgetTree::consumeFrameRequest | ( | ) |
Clear pending flags before processing the frame.
| std::expected< bool, TreeError > portals::WidgetTree::contains | ( | Node< Widget > | ancestor, |
| Node< Widget > | node ) const |
Test inclusive ancestry without allocating or invoking callbacks.
| ancestor | Live candidate ancestor in this tree. |
| node | Live candidate descendant in this tree. |
|
static |
Create a mounted plain root and bounded registry; no partial tree on failure.
| scheduler | Borrowed UI executor that must outlive the tree; call on its owner thread. |
| options | Positive registry and depth bounds; max_depth must not exceed 256. |
| sink | Optional nonthrowing UI failure sink; recursive reports are suppressed. |
| context | Borrowed sink context that must outlive the tree. |
|
noexcept |
Get the most recently consumed frame's causal token on the UI thread. Pass this token to FrameWriter::submit after rendering. Multiple invalidations share a frameId and each retains its own causal record; the token identifies the first recorded cause.
|
noexcept |
Borrow the scheduler recorder without changing ownership.
|
inline |
Borrow T only during a void callback; nested edit/removal is supported. Forbidden during measure/arrange/paint. No automatic invalidation: request it explicitly.
| T | Widget or a publicly derived extension type represented by the checked observer. |
| Callback | Callable accepting T& and returning void. |
| node | Live widget to borrow for the duration of the callback. |
| callback | Synchronous editor; must not retain references and must request its own invalidation. |
|
inline |
Construct and exclusively attach a new child; constructors run only after validation. No attach/reparent exists, so cycles cannot be formed. Structural insertion during lifecycle or frame callbacks returns WOULD_BLOCK. A committed mount exception is reported to the sink; insertion still succeeds. Mount can remove itself, so a successful handle can already be stale.
| T | Publicly derived Widget constructible from the forwarded Args. |
| Args | Argument types accepted by T's constructor; perfect-forwarded without library copies. |
| parent | Live parent whose ownership will contain the new child. |
| args | Constructor arguments forwarded only after insertion checks. |
|
inline |
Checked construction, including mount and deferred reclamation. Uses the validation and construction boundary of emplace. Mount exceptions reach the error sink and retire the attempted subtree. External effects of constructors, lifecycle hooks and the sink are not rolled back.
| T | Publicly derived Widget constructible from Args. |
| Args | Constructor argument types, perfectly forwarded without library copies. |
| parent | Live parent that will own the child. |
| args | Constructor arguments forwarded after insertion checks. |
|
inline |
Keep widget/text storage alive through traversal AND rendering of borrowed commands. Run layout/paint and renderFullFrame before returning. Tree/domain edit is rejected; inspect, measure, arrange and paint remain available. Callback must return void.
| Callback | Callable without arguments returning void. |
| callback | Synchronous traversal and rendering operation; frame borrows must not escape. |
Live/visible/enabled ancestors; hit-test also needs valid geometry.
| node | Live node whose ancestry is checked. |
| std::expected< NodeSnapshot, TreeError > portals::WidgetTree::inspect | ( | Node< Widget > | node | ) | const |
Copy live structure; may allocate.
| node | Checked identity whose live structure is copied. |
| std::expected< void, TreeError > portals::WidgetTree::invalidate | ( | Node< Widget > | node, |
| Invalidation | kind ) |
Coalesce one frame request.
| node | Live node authorizing invalidation of the tree. |
| kind | Work to coalesce; layout invalidates all arranged geometry and includes paint. |
| std::expected< CellSize, TreeError > portals::WidgetTree::measure | ( | Node< Widget > | node, |
| CellSize | available ) |
Guarded extension call.
| node | Live widget to measure; hidden ancestry returns an empty size without invoking its hook. |
| available | Cell constraints normalized before calling the extension. |
| std::expected< void, TreeError > portals::WidgetTree::paint | ( | Node< Widget > | node, |
| PaintContext & | context ) |
Requires an active frame borrow.
| node | Live, arranged widget to paint; hidden ancestry skips the hook. |
| context | Sink borrowed for this hook and the enclosing frame only. |
|
inline |
Borrow a const extension object, including inside frame traversal. The external layout owner can read its custom layout interface, then measure/arrange children using inspect snapshots. No reference may escape; callback returns void.
| T | Widget or a publicly derived extension type represented by the checked observer. |
| Callback | Callable accepting const T& and returning void. |
| node | Live widget to borrow without permitting tree mutation through this reference. |
| callback | Synchronous reader; must not retain the widget reference. |
Invalidate subtree/scopes now, reclaim at safe point.
| node | Root of the subtree to invalidate and eventually destroy. |
Checked observing root; stale after root removal.
| std::expected< void, TreeError > portals::WidgetTree::setEnabled | ( | Node< Widget > | node, |
| bool | enabled ) |
No-op if equal; otherwise paint.
| node | Live node whose flag is changed. |
| enabled | Whether this node and its subtree can receive input; layout/paint remain available. |
| std::expected< void, TreeError > portals::WidgetTree::setVisible | ( | Node< Widget > | node, |
| bool | visible ) |
No-op if equal; otherwise layout.
| node | Live node whose flag is changed. |
| visible | Whether this node and its subtree participate in layout, paint and input. |
|
inline |
Borrow the node-owned scope for registration with the existing Scheduler. Registrations borrowing widgets must use edit for their entire external callback, or connect/at below. The const scope must not be retained or moved out of the node.
| Callback | Callable accepting const UiScope&; its return value is ignored. |
| node | Live node whose scope is borrowed outside a frame. |
| callback | Synchronous registration code; must not retain the scope reference. |