1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Drag-to-close panels (#8182)

* Closes https://github.com/emilk/egui/pull/7254

You can now drag-to-close a panel. Also drag-to-expand panels.

This is a breaking change: the animated panel functions now take a
`open: &mut bool` instead of `open: bool`.

This is only enabled for resizable panels
This commit is contained in:
Emil Ernerfeldt
2026-05-22 16:05:39 +02:00
committed by GitHub
parent dcefb2e3b8
commit 3cf844c542
10 changed files with 463 additions and 53 deletions

View File

@@ -49,7 +49,7 @@ impl crate::View for Panels {
egui::Panel::top("top_panel")
.resizable(true)
.min_size(32.0)
.show_animated_inside(ui, *top, |ui| {
.show_animated_inside(ui, top, |ui| {
egui::ScrollArea::vertical().show(ui, |ui| {
ui.vertical_centered(|ui| {
ui.heading("Expandable Upper Panel");
@@ -62,7 +62,7 @@ impl crate::View for Panels {
.resizable(true)
.default_size(150.0)
.size_range(80.0..=200.0)
.show_animated_inside(ui, *left, |ui| {
.show_animated_inside(ui, left, |ui| {
ui.vertical_centered(|ui| {
ui.heading("Left Panel");
});
@@ -75,7 +75,7 @@ impl crate::View for Panels {
.resizable(true)
.default_size(150.0)
.size_range(80.0..=200.0)
.show_animated_inside(ui, *right, |ui| {
.show_animated_inside(ui, right, |ui| {
ui.vertical_centered(|ui| {
ui.heading("Right Panel");
});
@@ -84,24 +84,31 @@ impl crate::View for Panels {
});
});
// Bottom panel: drag the top edge down past the expanded panel's min size
// to collapse; drag it back up past the collapsed panel's max size to
// re-expand. Both panels are `.resizable(true)` so each one's edge accepts
// the gesture; the collapsed panel uses `exact_size` so even a tiny
// outward drag is enough to trigger the swap.
egui::Panel::show_animated_between_inside(
ui,
*bottom,
egui::Panel::bottom("bottom_panel_collapsed"),
egui::Panel::bottom("bottom_panel_expanded"),
bottom,
egui::Panel::bottom("bottom_panel_collapsed")
.resizable(true)
.exact_size(16.0),
egui::Panel::bottom("bottom_panel_expanded")
.resizable(true)
.max_size(128.0),
|ui, expanded| {
if expanded {
ui.vertical_centered(|ui| {
if ui.button("Collapse bottom panel").clicked() {
*bottom = false;
}
ui.heading("Bottom panel");
});
egui::ScrollArea::vertical().show(ui, |ui| {
lorem_ipsum(ui);
});
ui.label(egui::RichText::new(crate::LOREM_IPSUM_LONG).small().weak());
} else {
ui.vertical_centered(|ui| {
if ui.button("Expand bottom panel").clicked() {
*bottom = true;
}
ui.label("Bottom panel (collapsed)");
});
}
},

View File

@@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b339d04f331a5d5f7ea17a1c68f61626e08ad5199aec9181080c711a60f07d53
size 344102
oid sha256:b2d186d7404839e1b8d33ea186751035362a085e5f60a774a5f1bd66dd3e1442
size 347049