From 8fbb1349a3bc033759d601ff9657afca8816087a Mon Sep 17 00:00:00 2001 From: jprochazk Date: Mon, 16 Dec 2024 18:14:40 +0100 Subject: [PATCH] add clear all + escape key --- crates/viewer/re_ui/src/notifications.rs | 28 ++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/crates/viewer/re_ui/src/notifications.rs b/crates/viewer/re_ui/src/notifications.rs index 9d70660b9dff..b061d786174e 100644 --- a/crates/viewer/re_ui/src/notifications.rs +++ b/crates/viewer/re_ui/src/notifications.rs @@ -117,6 +117,12 @@ impl NotificationUi { pub fn ui(&mut self, egui_ctx: &egui::Context, is_panel_visible: &mut bool) { if *is_panel_visible { + let escape_pressed = + egui_ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape)); + if escape_pressed { + *is_panel_visible = false; + } + self.has_unread_notifications = false; } @@ -159,6 +165,8 @@ impl NotificationPanel { let panel_width = 356.0; let panel_max_height = 320.0; + let mut to_dismiss = None; + let notification_list = |ui: &mut egui::Ui| { if notifications.is_empty() { ui.label( @@ -170,17 +178,15 @@ impl NotificationPanel { return; } - let mut to_dismiss = None; for (i, notification) in notifications.iter().enumerate().rev() { show_notification(ui, notification, DisplayMode::Panel, || { to_dismiss = Some(i); }); } - if let Some(to_dismiss) = to_dismiss { - notifications.remove(to_dismiss); - } }; + let mut clear = false; + egui::Area::new(self.id) .anchor(egui::Align2::RIGHT_TOP, egui::vec2(-8.0, 32.0)) .order(egui::Order::Foreground) @@ -204,8 +210,22 @@ impl NotificationPanel { egui::ScrollArea::vertical() .min_scrolled_height(panel_max_height) .show(ui, notification_list); + + if !notifications.is_empty() { + ui.horizontal_top(|ui| { + if ui.button("Clear all").clicked() { + clear = true; + }; + }); + } }); }); + + if clear { + notifications.clear(); + } else if let Some(to_dismiss) = to_dismiss { + notifications.remove(to_dismiss); + } } }