Grid layout
A grid whose items the person drags and resizes into place. Others make way and float up; the keyboard moves and resizes the selected item; narrow widths reflow it.
Dashboard
let compaction = state.compact.then_some(GridAxis::Vertical);
let shown = GridLayout::new("dashboard", &mut state.dashboard)
.draggable(state.draggable)
.resizable(state.resizable)
.compaction(compaction)
.breakpoints([(0.0, 1), (560.0, 12)])
.label("Dashboard")
.show(ui, card);
if shown.changed {
state.saved += 1; // save the areas here
}
state.selected = shown.selected;
Responsive tiles
// Read-only tiles that flow into rows: three across when wide,
// two below 720 points and one below 420.
GridLayout::new("tiles", &mut state.tiles)
.draggable(false)
.resizable(false)
.compaction(Some(GridAxis::Horizontal))
.row_height(32.0)
.breakpoints([(0.0, 1), (420.0, 2), (720.0, 12)])
.show(ui, card);
The story above is gallery/src/stories/grid_layout.rs, running in your browser. Every snippet on this page is cut from it.