Sheet
A modal panel that slides in from an edge of the window, with a title, a scrolling body and a footer. It closes on Escape or a click outside, and gives focus back to the button that opened it.
Placement
for (label, placement) in [
("Left Sheet...", SheetPlacement::Left),
("Top Sheet...", SheetPlacement::Top),
("Right Sheet...", SheetPlacement::Right),
("Bottom Sheet...", SheetPlacement::Bottom),
] {
if ui.add(Button::new(label)).clicked() {
state.open = Some(placement);
}
}
let placement = state.open.unwrap_or_default();
let mut open = state.open.is_some();
let size = match placement {
SheetPlacement::Left | SheetPlacement::Right => 350.0,
SheetPlacement::Top | SheetPlacement::Bottom => 280.0,
};
let confirmed = &mut state.confirmed;
Sheet::new("placement")
.title("Sheet Title")
.placement(placement)
.size(size)
.overlay(state.overlay)
.overlay_closable(state.overlay_closable)
.footer(|ui| {
if ui.add(Button::primary("Confirm")).clicked() {
*confirmed += 1;
ui.close();
}
if ui.add(Button::new("Cancel")).clicked() {
ui.close();
}
})
.show(&ctx, &mut open, |ui| {
ui.label("Your name");
ui.add(fastframe_ui::Input::new(&mut state.name));
ui.label("Escape, a click outside or the close button closes the sheet.");
});
if !open {
state.open = None;
}
Scrollable Sheet
if ui.add(Button::new("Scrollable Sheet...")).clicked() {
state.scrollable = true;
}
Sheet::new("scrollable")
.title("Scrollable Sheet")
.size(400.0)
.show(&ctx, &mut state.scrollable, |ui| {
for line in 1..=80 {
ui.label(format!("Line {line}: the body scrolls under the title."));
}
});
The story above is gallery/src/stories/sheet.rs, running in your browser. Every snippet on this page is cut from it.