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
ViewCtxper inserted view - it assigns rectangles to those views in insertion order
- it tracks the interactive navigation list
- it exposes cached layout helpers for the
areasclosure
The key rule is simple: the areas closure must consume exactly as many
rectangles as the views closure inserted views.
Typical patterns:
simple_pages: useskip_areasfor hidden page views while preserving the required rectangle countscroll_layout: usesplit_extto drive a shared scroll statewrap_with_scroll: usesplit_exttogether with wrapping so the layout scrolls by wrapped rows
Implementations§
Source§impl CtxStore
impl CtxStore
Sourcepub fn split(&mut self, layout: Layout, area: Rect) -> Vec<Rect>
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.
Sourcepub fn split_ext(
&mut self,
layout: Layout,
area: Rect,
scrollstate: &mut u16,
scroll: &mut u16,
) -> Vec<Rect>
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.
Sourcepub fn next_area(&mut self, area: Rect)
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_areasfor assigning multiple rectangles at once.skip_areasfor efficiently skipping areas without splits.
Sourcepub fn next_areas(&mut self, areas: &[Rect])
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 ofRectelements 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_areafor assigning a single rectangle.skip_areasfor efficiently skipping areas without splits.
Sourcepub fn skip_areas(&mut self, number: usize)
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