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.
This commit is contained in:
Jordan Petridis 2018-03-27 12:01:53 +03:00
parent bdc6264701
commit d525d1fe59
No known key found for this signature in database
GPG Key ID: CEABAD9F5683B9A6
2 changed files with 11 additions and 15 deletions

View File

@ -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(&notif.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(&notif.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(_) => (),
}

View File

@ -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: &gtk::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);
}
}