pub struct Grid { /* private fields */ }Expand description
A fixed-column grid. Children flow left→right, top→bottom into columns
equal-width cells; each row’s height is its tallest child. Lays out
something new (not a Column/Row) — see D095.
Two additional placement modes (D115/Phase 32 Step 1):
Grid::staggered— masonry packing (Pinterest-style): children keep their own measured heights and fill the shortest column first.Grid::bento— a fixed lattice where children added viaGrid::child_spancover multiple columns/rows (dashboard tiles).
Implementations§
Source§impl Grid
impl Grid
Sourcepub fn run_spacing(self, s: f32) -> Self
pub fn run_spacing(self, s: f32) -> Self
Vertical gap between rows (logical px).
Sourcepub fn children(self, ws: Vec<BoxedWidget>) -> Self
pub fn children(self, ws: Vec<BoxedWidget>) -> Self
Append several children (each span 1×1 in bento mode).
Sourcepub fn builder(
columns: usize,
count: usize,
builder: impl Fn(usize) -> BoxedWidget,
) -> Self
pub fn builder( columns: usize, count: usize, builder: impl Fn(usize) -> BoxedWidget, ) -> Self
A uniform columns-wide grid of count items, each built by calling
builder(i) — a convenience constructor for the common “N items from
a data source” case, so callers don’t have to hand-build a Vec
first. Eager, not virtualized (all count children build up front;
for large counts where that matters, ListView::builder is the
virtualized one).
Sourcepub fn staggered(self) -> Self
pub fn staggered(self) -> Self
Switch to masonry placement: each child keeps its own measured height at the column width and is placed into the currently-shortest column (leftmost wins ties). Layout height = the tallest column.
Sourcepub fn bento(self) -> Self
pub fn bento(self) -> Self
Switch to bento placement: children occupy whole cells of a fixed
lattice (columns wide, rows of Grid::row_height), spanning
multiple columns/rows per Grid::child_span. Items are placed
first-fit: top-to-bottom, left-to-right, into the first free block
that fits their span.
Sourcepub fn child_span(
self,
w: impl Widget + 'static,
col_span: u16,
row_span: u16,
) -> Self
pub fn child_span( self, w: impl Widget + 'static, col_span: u16, row_span: u16, ) -> Self
Append a child spanning col_span × row_span lattice cells and
switch to bento mode.
A per-child span (rather than a parallel .bento(Vec<(u16, u16)>)
span list) was chosen deliberately: the span lives at the same call
site as the child it describes, so conditionally-added children can
never silently desynchronize an index-aligned spans vector.
Sourcepub fn row_height(self, h: f32) -> Self
pub fn row_height(self, h: f32) -> Self
Lattice row height for bento mode (logical px, default 96.0).
Trait Implementations§
Source§impl Widget for Grid
impl Widget for Grid
Source§fn children(&self) -> Children<'_>
fn children(&self) -> Children<'_>
Source§fn layout(&self, ctx: &LayoutCtx<'_>) -> Size
fn layout(&self, ctx: &LayoutCtx<'_>) -> Size
ctx.constraints and return a size within them. Read more