pub struct LayoutCtx<'a> { /* private fields */ }Expand description
Context passed to Widget::layout.
Beyond the (still-empty) container seam, it optionally carries the shared,
heavyweight text-shaping context the render root threads down for text
layout, plus the app’s active theme (design tokens).
Both resources are type-erased (&mut dyn Any / &dyn Any) so
frust-core stays independent of frust-text (and thus of parley)
and of frust-theme; text widgets recover the shaping context with
LayoutCtx::text_context and themed widgets recover the theme with
LayoutCtx::theme_as.
Implementations§
Source§impl<'a> LayoutCtx<'a>
impl<'a> LayoutCtx<'a>
Sourcepub fn new() -> LayoutCtx<'static>
pub fn new() -> LayoutCtx<'static>
Create a layout context with no shared resources.
Used by leaf-only unit tests and by containers that never lay out text.
Sourcepub fn with_text_context(text_ctx: &'a mut dyn Any) -> Self
pub fn with_text_context(text_ctx: &'a mut dyn Any) -> Self
Create a layout context carrying the shared text-shaping context.
The render root builds this so text widgets can shape their content
during the layout pass; the concrete type is erased to keep this crate
free of a frust-text dependency.
Sourcepub fn with_resources(
text_ctx: Option<&'a mut dyn Any>,
theme: Option<&'a dyn Any>,
) -> Self
pub fn with_resources( text_ctx: Option<&'a mut dyn Any>, theme: Option<&'a dyn Any>, ) -> Self
Create a layout context carrying both an optional text-shaping context and an optional type-erased theme.
The render root uses this to thread both resources it owns into the
layout pass in one shot (see crate::app::RenderRoot::layout).
Sourcepub fn with_theme(self, theme: &'a dyn Any) -> Self
pub fn with_theme(self, theme: &'a dyn Any) -> Self
Attach the app’s active theme, type-erased. Chainable builder used by the render root when it lends a stored theme into the layout pass.
Sourcepub fn text_context<T: Any>(&mut self) -> &mut T
pub fn text_context<T: Any>(&mut self) -> &mut T
Recover the shared text-shaping context as &mut T.
Panics if no context was threaded into this pass, or if its concrete
type differs from T — both are shell-wiring bugs, not runtime-data
conditions.
Sourcepub fn theme_as<T: Any>(&self) -> Option<&T>
pub fn theme_as<T: Any>(&self) -> Option<&T>
Recover the threaded theme as &T, or None if no theme was threaded
into this pass (a supported state — bare-core tests and pre-theme apps)
or its concrete type differs from T.
Mirrors LayoutCtx::text_context but returns Option rather than
panicking, because a missing theme is a valid runtime state, not a
wiring bug. Widgets that read frust_theme::Theme downcast through
this (or the Theme::from_layout_ctx convenience wrapper).
Sourcepub fn window_insets(&self) -> WindowInsets
pub fn window_insets(&self) -> WindowInsets
The window’s insets (WindowInsets) for this layout pass (a cheap
copy). Global and origin-independent (see the crate::insets module
docs), so every widget reads the same value regardless of its position —
save that a consuming ancestor may have narrowed it for its subtree via
LayoutCtx::with_window_insets; defaults to the zero inset when no
shell pushed one. A SafeArea widget insets by WindowInsets::padding.
Sourcepub fn with_window_insets<R>(
&mut self,
insets: WindowInsets,
f: impl FnOnce(&mut Self) -> R,
) -> R
pub fn with_window_insets<R>( &mut self, insets: WindowInsets, f: impl FnOnce(&mut Self) -> R, ) -> R
Run f with insets installed as this context’s window insets, then
restore the previous value and return f’s result.
The window insets are otherwise a single root-seeded, global value that
every widget reads unchanged. This scoped override is how a widget that
has already padded its subtree by some inset edges removes them from
that subtree (Flutter’s MediaQuery.removePadding): SafeArea lays its
child out inside
ctx.with_window_insets(ctx.window_insets().consuming(..), |ctx| ..), so
a self-insetting descendant reads zero padding on the consumed edges
instead of insetting a second time. Pair it with
PaintCtx::with_window_insets around the matching paint_child so a
paint-time read agrees with the layout-time one.
The restore is a plain assignment after f returns — there is no drop
guard, so if f panics the override is not undone (the pass is being
unwound anyway).
Sourcepub fn window_size(&self) -> Size
pub fn window_size(&self) -> Size
The window’s logical size for this layout pass (a cheap copy).
Global and origin-independent like LayoutCtx::window_insets, so every
widget in the tree reads the same value regardless of where it sits or
what constraints its parent handed it; Size::ZERO when no root has laid
out yet (bare-core leaf tests).
The constraint an overlay pod is laid out against. A widget floating a
pod through crate::overlay sizes it with
BoxConstraints::loose(ctx.window_size()) rather than with its own bc:
the pod escapes its owner’s box entirely, so the owner’s constraints say
nothing about how much room the floated surface has, and the window is the
only bound that does.