Resizable
Panels split by handles the person drags, side by side or stacked, each with a least and greatest size. A narrow window takes room back, and a wider one returns it.
Nested panels
ResizablePanelGroup::vertical("nested")
.panel(ResizablePanel::new())
.panel(ResizablePanel::new().size(80.0).size_range(80.0..=150.0))
.show(ui, |ui, index| {
if index == 1 {
panel_box(ui, "Bottom (80 .. 150)");
return;
}
ResizablePanelGroup::horizontal("nested-top")
.panel(ResizablePanel::new().size(150.0).size_range(120.0..=300.0))
.panel(ResizablePanel::new())
.panel(ResizablePanel::new().size(200.0))
.show(ui, |ui, index| {
let text = ["Left (120 .. 300)", "Centre", "Right"][index];
panel_box(ui, text);
});
});
Collapsible
// Drag the sidebar below half its least size, or double-click
// its handle, to fold it away.
let shown = ResizablePanelGroup::horizontal("collapsible")
.panel(
ResizablePanel::new()
.size(200.0)
.size_range(140.0..=320.0)
.collapsible(),
)
.panel(ResizablePanel::new())
.show(ui, |ui, index| {
panel_box(ui, ["Sidebar", "Content"][index]);
});
if shown.changed {
state.sizes = format!("{:?}", shown.sizes);
}
Visibility
ResizablePanelGroup::horizontal("visibility")
.panel(
ResizablePanel::new()
.size(200.0)
.size_range(150.0..=400.0)
.visible(state.show_left),
)
.panel(ResizablePanel::new())
.panel(
ResizablePanel::new()
.size(240.0)
.size_range(200.0..=400.0)
.fixed(),
)
.show(ui, |ui, index| {
panel_box(ui, ["Left", "Centre (grows)", "Right (fixed)"][index]);
});
Programmatic resize
for (label, size) in [("Narrow", 120.0), ("Wide", 360.0)] {
if ui.add(Button::new(label).small()).clicked() {
ResizablePanelGroup::set_size(ui.ctx(), "programmatic", 0, Some(size));
}
}
The story above is gallery/src/stories/resizable.rs, running in your browser. Every snippet on this page is cut from it.