Skip to main content

LayoutContext

Struct LayoutContext 

Source
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: f32

Host 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: f32

Combined 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>

Source

pub fn for_testing(theme: &'a Theme) -> Self

Create a LayoutContext for testing (no arena access).

Source

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.

Source

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.

Source

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).

Source

pub fn for_each_interaction_ancestor(&self, f: impl FnMut(WidgetId))

Call f with every widget that holds live interaction state, and with each of its ancestors up to a root.

“Live interaction state” is what the framework destroys when it parks a subtree dormant: the keyboard focus (cleared by WidgetTree::revalidate_interaction_state), a captured pointer and an in-flight drag source (both cancelled with CancelReason::SubtreeParked). Losing any of them is fine when the user navigated away and wrong when the container moved.

So a container that culls by viewport intersects this with its own children and pins whichever of them the user is in the middle of: a card being typed in, or drag-selected inside, stays live wherever the camera goes.

Reported from the anchors upward rather than tested per child on purpose — that makes the pin cost proportional to the number of live interactions (almost always zero or one, times the tree depth) instead of to the number of children, which is the quantity a culling container exists to stop paying. Nothing is reported outside a real layout pass.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn child_alignment(&self, child_id: WidgetId) -> Option<Alignment>

Query a child’s per-widget alignment override, if any.

Source

pub fn is_rtl(&self) -> bool

Whether the layout direction is right-to-left.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for LayoutContext<'a>

§

impl<'a> !Send for LayoutContext<'a>

§

impl<'a> !Sync for LayoutContext<'a>

§

impl<'a> !UnwindSafe for LayoutContext<'a>

§

impl<'a> Freeze for LayoutContext<'a>

§

impl<'a> Unpin for LayoutContext<'a>

§

impl<'a> UnsafeUnpin for LayoutContext<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.