Skip to main content

LayoutCtx

Struct LayoutCtx 

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

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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

Source

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.

Source

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

Source

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§

Source§

impl Default for LayoutCtx<'static>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> 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> StorageAccess<T> for T

Source§

fn as_borrowed(&self) -> &T

Borrows the value.
Source§

fn into_taken(self) -> T

Takes the value.
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.