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 + 'static)) -> LayoutCtx<'a>
pub fn with_text_context(text_ctx: &'a mut (dyn Any + 'static)) -> LayoutCtx<'a>
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 + 'static)>,
theme: Option<&'a (dyn Any + 'static)>,
) -> LayoutCtx<'a>
pub fn with_resources( text_ctx: Option<&'a mut (dyn Any + 'static)>, theme: Option<&'a (dyn Any + 'static)>, ) -> LayoutCtx<'a>
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 + 'static)) -> LayoutCtx<'a>
pub fn with_theme(self, theme: &'a (dyn Any + 'static)) -> LayoutCtx<'a>
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>(&mut self) -> &mut Twhere
T: Any,
pub fn text_context<T>(&mut self) -> &mut Twhere
T: Any,
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>(&self) -> Option<&T>where
T: Any,
pub fn theme_as<T>(&self) -> Option<&T>where
T: Any,
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 LayoutCtx<'a>) -> R,
) -> R
pub fn with_window_insets<R>( &mut self, insets: WindowInsets, f: impl FnOnce(&mut LayoutCtx<'a>) -> 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.
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for LayoutCtx<'a>
impl<'a> !Send for LayoutCtx<'a>
impl<'a> !Sync for LayoutCtx<'a>
impl<'a> !UnwindSafe for LayoutCtx<'a>
impl<'a> Freeze for LayoutCtx<'a>
impl<'a> Unpin for LayoutCtx<'a>
impl<'a> UnsafeUnpin for LayoutCtx<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.