diff --git a/hammond-gtk/resources/gtk/inapp_notif.ui b/hammond-gtk/resources/gtk/inapp_notif.ui index 443be4a..4074fd8 100644 --- a/hammond-gtk/resources/gtk/inapp_notif.ui +++ b/hammond-gtk/resources/gtk/inapp_notif.ui @@ -2,13 +2,13 @@ - + True False center start - + True False @@ -29,7 +29,7 @@ 6 12 - + True False center @@ -43,7 +43,31 @@ - + + True + True + False + True + center + center + none + + + True + False + window-close-symbolic + + + + + False + False + end + 1 + + + + Undo True True @@ -55,7 +79,7 @@ False False end - 1 + 2 diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index 0f48e97..9a4e8b1 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -174,7 +174,9 @@ impl App { let sender = sender.clone(); let notif = InAppNotification::new(text.into(), callback, sender); overlay.add_overlay(¬if.overlay); - overlay.show_all(); + // We need to display the notification after the widget is added to the overlay + // so there will be a nice animation. + notif.show(); } Err(_) => (), } diff --git a/hammond-gtk/src/appnotif.rs b/hammond-gtk/src/appnotif.rs index 879f2f2..a949fae 100644 --- a/hammond-gtk/src/appnotif.rs +++ b/hammond-gtk/src/appnotif.rs @@ -14,22 +14,25 @@ pub struct InAppNotification { revealer: gtk::Revealer, text: gtk::Label, undo: gtk::Button, + close: gtk::Button, } impl Default for InAppNotification { fn default() -> Self { let builder = gtk::Builder::new_from_resource("/org/gnome/hammond/gtk/inapp_notif.ui"); - let overlay: gtk::Overlay = builder.get_object("notif_overlay").unwrap(); - let revealer: gtk::Revealer = builder.get_object("notif_revealer").unwrap(); - let text: gtk::Label = builder.get_object("notif_label").unwrap(); - let undo: gtk::Button = builder.get_object("undo_button").unwrap(); + let overlay: gtk::Overlay = builder.get_object("overlay").unwrap(); + let revealer: gtk::Revealer = builder.get_object("revealer").unwrap(); + let text: gtk::Label = builder.get_object("text").unwrap(); + let undo: gtk::Button = builder.get_object("undo").unwrap(); + let close: gtk::Button = builder.get_object("close").unwrap(); InAppNotification { overlay, revealer, text, undo, + close, } } } @@ -40,11 +43,9 @@ impl InAppNotification { F: FnMut() -> glib::Continue + 'static, { let notif = InAppNotification::default(); - notif.text.set_text(&text); - notif.revealer.set_reveal_child(true); - let id = timeout_add_seconds(60, callback); + let id = timeout_add_seconds(6, callback); let id = Rc::new(RefCell::new(Some(id))); // Cancel the callback @@ -66,6 +67,20 @@ impl InAppNotification { } }); + // Hide the revealer when the close button is clicked + let revealer = notif.revealer.clone(); + notif.close.connect_clicked(move |_| { + revealer.set_reveal_child(false); + }); + notif } + + // This is a seperate method cause in order to get a nice animation + // the revealer should be attached to something that will display it. + // Previouslyi we where doing it in the constructor, which had the result + // of the animation being skipped cause there was no parent widget to display it. + pub fn show(&self) { + self.revealer.set_reveal_child(true); + } }