From d525d1fe594b8ee5816be7539d41ff8e18448d4b Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Tue, 27 Mar 2018 12:01:53 +0300 Subject: [PATCH] InAppNofitication: Make revealer field private, change show signature Accept an overlay widget that the revealer will be attached to into the show method. Thus revealer field no longer need to be public. --- hammond-gtk/src/app.rs | 15 ++++----------- hammond-gtk/src/appnotif.rs | 11 +++++++---- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index 6277887..4fa1b83 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -196,13 +196,9 @@ impl App { glib::Continue(false) }); - let text = "Marked all episodes as listened"; - let notif = - InAppNotification::new(text.into(), callback, || {}, sender.clone()); - overlay.add_overlay(¬if.revealer); - // We need to display the notification after the widget is added to the overlay - // so there will be a nice animation. - notif.show(); + let text = "Marked all episodes as listened".into(); + let notif = InAppNotification::new(text, callback, || {}, sender.clone()); + notif.show(&overlay); } Ok(Action::RemoveShow(pd)) => { let text = format!("Unsubscribed from {}", pd.title()); @@ -244,10 +240,7 @@ impl App { let sender_ = sender.clone(); let notif = InAppNotification::new(text, callback, undo_callback, sender_); - overlay.add_overlay(¬if.revealer); - // We need to display the notification after the widget is added to the overlay - // so there will be a nice animation. - notif.show(); + notif.show(&overlay); } Err(_) => (), } diff --git a/hammond-gtk/src/appnotif.rs b/hammond-gtk/src/appnotif.rs index 67168c1..19284fe 100644 --- a/hammond-gtk/src/appnotif.rs +++ b/hammond-gtk/src/appnotif.rs @@ -10,7 +10,7 @@ use std::sync::mpsc::Sender; #[derive(Debug, Clone)] pub struct InAppNotification { - pub revealer: gtk::Revealer, + revealer: gtk::Revealer, text: gtk::Label, undo: gtk::Button, close: gtk::Button, @@ -83,10 +83,13 @@ impl InAppNotification { } // 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 + // the revealer should be attached to something that displays it. + // Previously 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) { + pub fn show(&self, overlay: >k::Overlay) { + overlay.add_overlay(&self.revealer); + // We need to display the notification after the widget is added to the overlay + // so there will be a nice animation. self.revealer.set_reveal_child(true); } }