Skip to main content

CtxStore

Struct CtxStore 

Source
pub struct CtxStore { /* private fields */ }
Expand description

Layout context manager used by the areas closure.

CtxStore is the runtime-side companion of ViewFactory:

  • it stores one ViewCtx per inserted view
  • it assigns rectangles to those views in insertion order
  • it tracks the interactive navigation list
  • it exposes cached layout helpers for the areas closure

The key rule is simple: the areas closure must consume exactly as many rectangles as the views closure inserted views.

Typical patterns:

  • simple_pages: use skip_areas for hidden page views while preserving the required rectangle count
  • scroll_layout: use split_ext to drive a shared scroll state
  • wrap_with_scroll: use split_ext together with wrapping so the layout scrolls by wrapped rows

Implementations§

Source§

impl CtxStore

Source

pub fn split(&mut self, layout: Layout, area: Rect) -> Vec<Rect>

Splits an area for use in the areas closure.

This is the usual helper for non-scrolling layouts such as page shells, button rows, or fixed sections. It uses AreaCache under the hood, so repeated frames avoid unnecessary work when the same layout is reused.

Use this in the areas closure, not inside render. For render-time local layout work, use the AreaCache passed to the view instead.

Source

pub fn split_ext( &mut self, layout: Layout, area: Rect, scrollstate: &mut u16, scroll: &mut u16, ) -> Vec<Rect>

Scrolling variant of split for the areas closure.

This is the main helper for scroll-aware page layout. It is used when the layout itself depends on an external scroll state, as in scroll_layout and wrap_with_scroll.

scrollstate is the current position, while scroll stores the total content length reported by the layout.

Source

pub fn next_area(&mut self, area: Rect)

Assigns one rectangle to the next view in insertion order.

This is the most explicit way to bind a computed rectangle to one view. Areas are consumed in FIFO order: the first call to next_area corresponds to the first inserted view, the second call to the second view, and so on.

§Arguments
  • area – The rectangle to assign to the next view.
§Important

The number of areas passed across all calls to next_area and next_areas must exactly match the total number of views. Otherwise altui runtime will panic.

§See also
  • next_areas for assigning multiple rectangles at once.
  • skip_areas for efficiently skipping areas without splits.
Source

pub fn next_areas(&mut self, areas: &[Rect])

Assigns several consecutive rectangles to the next views.

This is a convenience wrapper around repeated next_area calls and is useful when a split already produced an ordered batch of areas that map directly to a consecutive group of views.

§Arguments
  • areas - A slice of Rect elements to be assigned in order.
§Important

The number of areas passed across all calls to next_areas and next_area must exactly match the total number of views. Otherwise altui runtime will panic.

§See also
  • next_area for assigning a single rectangle.
  • skip_areas for efficiently skipping areas without splits.
Source

pub fn skip_areas(&mut self, number: usize)

Skips the next number views by assigning EMPTY_AREA to them.

This is the main tool for conditional pages and layers. It lets the runtime keep the required view/area alignment without spending time on real layout work for views that are currently hidden.

The simple_pages example uses this pattern: hidden pages still own two views, so the areas closure must still provide two rectangles. Instead of splitting a real layout, skip_areas(2) injects two empty rectangles.

§Arguments
  • number - Number of areas to skip.
§Example
// Before:
// const HIDDEN_AREAS: &[Rect; 2] = &[EMPTY_AREA; 2];
// ctx.next_areas(HIDDEN_AREAS);

// After:
ctx.skip_areas(2);

See: https://altlinux.space/writers/altui/src/branch/main/examples/simple_pages

Trait Implementations§

Source§

impl Default for CtxStore

Source§

fn default() -> Self

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

Auto Trait Implementations§

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

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more