Expand description
Widget trait, tree traversal, and the top-level App struct.
§Coordinate system
Widget bounds are expressed in parent-local first-quadrant (Y-up)
coordinates. A widget at bounds.x = 10, bounds.y = 20 is drawn 10 units
right and 20 units up from its parent’s bottom-left corner.
OS/browser mouse events arrive in Y-down screen coordinates. The single
conversion y_up = viewport_height - y_down happens inside
App::on_mouse_move / App::on_mouse_down / App::on_mouse_up.
All widget code sees Y-up coordinates only.
§Tree traversal
Paint: root → leaves (children painted on top of parents). Hit test: root → leaves (deepest child under cursor wins). Event dispatch: leaf → root (events bubble up; any widget can consume).
Structs§
- App
- Owns the widget tree, handles focus, and converts OS events to Y-up coords.
- Backbuffer
Cache - A CPU bitmap owned by a widget that opts into backbuffer caching.
- Backbuffer
Spec - Widget-owned backbuffer request. Windows use this for retained GL FBOs, while existing label/text-field CPU caches map naturally to the software variants.
- Backbuffer
State - Retained widget backbuffer state shared by software and GL implementations.
- Compositing
Layer - Offscreen compositing layer requested by a widget for itself and its descendants.
- Inspector
Edit - A pending inspector edit: navigate to the widget at
path, look upfield_pathvia reflection, and applynew_value. - Inspector
Node - Flat snapshot of one widget for the inspector panel.
- Inspector
Overlay - Snapshot pushed to the platform render loop so the host can draw a Chrome F12-style three-band overlay (margin + bounds + padding) around the widget the inspector is hovering.
- Widget
Base Edit - Queued mutation for a widget’s
WidgetBase. The inspector pushes these; the host frame loop drains and applies viaapply_widget_base_edit.
Enums§
- Backbuffer
Kind - Unified backbuffer target kind requested by a widget.
- Backbuffer
Mode - How a widget’s backbuffer stores pixels.
- Widget
Base Field - One field in a widget’s
crate::layout_props::WidgetBasethat the inspector can change at runtime.
Traits§
- Widget
- Every visible element in the UI is a widget.
Functions§
- active_
modal_ path - Return the path to the topmost active modal subtree, ignoring normal hit-testing bounds. Modal overlays paint at app level, so their event routing must also bypass regular child clipping/window hit regions.
- apply_
inspector_ edit - Apply a single queued inspector edit against the live widget tree.
Returns
trueif the edit landed;falseif the path was stale or the field path didn’t resolve. - apply_
widget_ base_ edit - Apply a single queued
WidgetBaseEditagainst the live widget tree. Returnstruewhen the edit landed,falseif the path was stale or the widget does not expose aWidgetBase. - collect_
inspector_ nodes - Walk the subtree rooted at
widgetand collect anInspectorNodeper widget in DFS paint order (root first). - current_
mouse_ world - Retrieve the latest world-space mouse position. Widgets doing a
drag gesture that needs invariance against ancestor-layout shifts
(e.g. a nested
Resizeinside an auto-sizedWindow, where the window grows/shrinks as the user drags and moves the widget’s ancestor frame) should prefer this over the widget-localposcarried inEvent::Mouse*. - current_
paint_ clip - Current visible paint clip in root coordinates, if painting is inside a clipped subtree. Widgets can use this to avoid starting expensive work for content that traversal visits but the active clip will discard.
- current_
viewport - Retrieve the latest app-level viewport in logical coordinates.
- dispatch_
event - Dispatch
eventthrough a path (list of child indices from the root). The event bubbles leaf → root; returnsConsumedif any widget consumed it. - dispatch_
unconsumed_ key - Give visible widgets a chance to handle a key ignored by the focused path.
- find_
widget_ by_ id - Depth-first search the subtree rooted at
widgetfor one whoseWidget::idmatchesid. Returns the first match in paint order, includingwidgetitself. Used primarily by tests to locate a specificWindowby its title without knowing the tree shape. - find_
widget_ by_ id_ mut - Mutable counterpart to
find_widget_by_id. Required when a test needs to poke at a sub-widget’s mutable state (e.g. calling aScrollView::set_scroll_offset) after finding it by id. - find_
widget_ by_ type - Depth-first search for a widget by its
Widget::type_name. Returns the first match in paint order. Used by tests that want to assert on a specific widget kind inside an opaque content subtree (e.g. “find the ScrollView inside this window”). - global_
overlay_ hit_ path - Return the topmost widget whose app-level overlay contains
local_pos. - hit_
test_ subtree - Walk the subtree rooted at
widgetand return the path (list of child indices) to the deepest widget that passeshit_testatlocal_pos. - mark_
subtree_ dirty - Recursively call
mark_dirtyonwidgetand every visible descendant. Used by the host frame loop after an async data source (image fetch + decode, font load, etc.) finishes outside the normal event-dispatch path that would otherwise mark widgets dirty as the event bubbles. Called explicitly at the top of the frame so the user-visible “freshly-decoded data lands in stale FBO contents” bug never opens a one-frame race window. - paint_
global_ overlays - Paint app-level overlays after the whole tree has rendered.
- paint_
subtree - Paint
widgetand all its descendants. The caller must ensurectxis already translated so that (0,0) maps towidget’s bottom-left corner. - reflect_
fields - Walk a reflected struct’s fields and produce
(name, display)pairs suitable for the inspector’s property pane. Public so callers can build the same typed dump for ad-hoc reflectable values (e.g. a debug hover inspector outside the widget tree). - set_
current_ mouse_ world - Record the current mouse cursor position in app-level (world / Y-up
logical) coordinates. Called by
App’s mouse entry points. - set_
current_ viewport - Record the current app-level viewport in logical Y-up coordinates.
- walk_
path_ mut - Walk the widget tree from
rootalongpathand return the deepest reachable widget as a mutable reference. ReturnsNoneif the path indexes past the available children at any level — useful when the path is stale (e.g. the tree shape changed since the inspector snapshot).