pub struct LayoutContext<'a> {
pub stack_main_axis: Option<StackAxis>,
pub theme: &'a Theme,
pub layout_direction: LayoutDirection,
pub scale_factor: f32,
pub text_scale: f32,
pub text_backend: Option<&'a Rc<RefCell<dyn TextBackend>>>,
/* private fields */
}Expand description
Context available during layout.
Fields§
§stack_main_axis: Option<StackAxis>The enclosing linear stack’s main axis, when a stack is querying this
child (see StackAxis). None otherwise.
theme: &'a Theme§layout_direction: LayoutDirection§scale_factor: f32Host window HiDPI device scale (physical px per logical px). The layout
pass is otherwise fully logical, and the renderer applies this scale at
the vertex stage — so ordinary widgets must ignore this. It exists
only as the escape hatch for widgets that bridge to a device-pixel OS
resource (e.g. a WebView sizing its native subview, which on some
toolkits — WebKitGTK on X11 — ignores fractional scaling and needs
device pixels). 1.0 in headless / test contexts.
text_scale: f32Combined user×OS text-scale factor (1.0 = 100 %). Distinct from
scale_factor (HiDPI device pixels): this is the logical accessibility
magnification. Widgets that size text from Theme.typography already
scale via the effective theme and should ignore this; it exists for
widgets that size from another source (IconWidget, the rich-text engine
default size, scene text) and need the raw factor. 1.0 in test contexts.
text_backend: Option<&'a Rc<RefCell<dyn TextBackend>>>Text backend for accurate text measurement during layout.
Implementations§
Source§impl<'a> LayoutContext<'a>
impl<'a> LayoutContext<'a>
Sourcepub fn for_testing(theme: &'a Theme) -> Self
pub fn for_testing(theme: &'a Theme) -> Self
Create a LayoutContext for testing (no arena access).
Sourcepub fn stack_main_axis(&self) -> Option<StackAxis>
pub fn stack_main_axis(&self) -> Option<StackAxis>
The enclosing linear stack’s main axis, if a stack is currently
querying this child. See StackAxis.
Sourcepub fn with_stack_main_axis(&self, axis: StackAxis) -> LayoutContext<'a>
pub fn with_stack_main_axis(&self, axis: StackAxis) -> LayoutContext<'a>
Derive a context that advertises axis as the enclosing stack’s main
axis. Used by HStack/VStack when querying children so a Spacer
(and any other orientation-agnostic flexible leaf) can size correctly
per axis. All other fields are shared with self.
Sourcepub fn focused(&self) -> Option<WidgetId>
pub fn focused(&self) -> Option<WidgetId>
The currently focused widget id, if any. Returns None when
the layout pass is unrelated to a tree (test contexts).
Sourcepub fn shortcut_registry(&self) -> Option<&ShortcutRegistry>
pub fn shortcut_registry(&self) -> Option<&ShortcutRegistry>
Borrow the tree’s shortcut registry. Returns None outside a
real layout pass. Intended for read-only inspection by the
debug inspector.
Sourcepub fn overlay_manager(&self) -> Option<&OverlayManager>
pub fn overlay_manager(&self) -> Option<&OverlayManager>
Borrow the tree’s overlay manager. Returns None outside a
real layout pass. Intended for read-only inspection by the
debug inspector.
Sourcepub fn child_layout_response(
&self,
child_id: WidgetId,
proposal: SizeProposal,
) -> Option<LayoutResponse>
pub fn child_layout_response( &self, child_id: WidgetId, proposal: SizeProposal, ) -> Option<LayoutResponse>
Query a child widget’s full layout response (wanted size + flex weight). Returns None if the child doesn’t exist, is dormant, or the arena is not available.
Sourcepub fn measure_intrinsic(
&self,
id: WidgetId,
proposal: SizeProposal,
) -> Option<Size>
pub fn measure_intrinsic( &self, id: WidgetId, proposal: SizeProposal, ) -> Option<Size>
Measure a widget’s intrinsic size for proposal, regardless of
activation — works even for dormant/collapsed widgets (and their
dormant subtrees), unlike child_size /
child_layout_response, which return
None for inactive widgets.
Intended for adaptive layouts that hide some children but still need
their size to decide when to reveal them — e.g. an overflow Toolbar
collapsing actions into a chevron menu. Runs uncached and re-entrant-
safe; calls layout_response, which must be idempotent.
Sourcepub fn child_size(
&self,
child_id: WidgetId,
proposal: SizeProposal,
) -> Option<Size>
pub fn child_size( &self, child_id: WidgetId, proposal: SizeProposal, ) -> Option<Size>
Query a child widget’s wanted size only (drops the flex weight).
Convenience over child_layout_response.
Sourcepub fn widget_bounds(&self, id: WidgetId) -> Option<Rect>
pub fn widget_bounds(&self, id: WidgetId) -> Option<Rect>
Query the laid-out bounds of any active widget. Returns None
when the arena is not available (test contexts) — otherwise
returns the widget’s current bounds (Rect::ZERO if unknown).
Useful for inspector-style widgets that need to mirror another
widget’s geometry into a Signal during the layout pass.
Sourcepub fn widget_at_point(
&self,
point: Point,
exclude: Option<WidgetId>,
) -> Option<WidgetId>
pub fn widget_at_point( &self, point: Point, exclude: Option<WidgetId>, ) -> Option<WidgetId>
Hit-test the active widget tree at point and return the
deepest widget under it. Honors event_pass_through. The
exclude argument lets the caller skip a specific subtree
(e.g. the inspector’s picker overlay so it doesn’t pick
itself). Returns None outside layout (no arena available).
Sourcepub fn arena(&self) -> Option<&WidgetArena>
pub fn arena(&self) -> Option<&WidgetArena>
Borrow the underlying arena. Returns None outside a layout
pass (test contexts). Intended for read-only introspection by
debug tooling (the inspector’s tree view) — use the typed
accessors above when possible.
Sourcepub fn child_alignment(&self, child_id: WidgetId) -> Option<Alignment>
pub fn child_alignment(&self, child_id: WidgetId) -> Option<Alignment>
Query a child’s per-widget alignment override, if any.