Show notification summary

This commit is contained in:
Ian Douglas Scott 2021-09-09 08:47:35 -07:00
parent efcb3c5aec
commit cc9961c634
2 changed files with 27 additions and 9 deletions

View file

@ -1,15 +1,18 @@
use cascade::cascade;
use gtk4::{
glib::{self, clone},
pango,
prelude::*,
subclass::prelude::*,
};
use crate::deref_cell::DerefCell;
use crate::notifications::Notification;
#[derive(Default)]
pub struct NotificationPopoverInner {
label: DerefCell<gtk4::Label>,
summary_label: DerefCell<gtk4::Label>,
body_label: DerefCell<gtk4::Label>,
}
#[glib::object_subclass]
@ -28,7 +31,15 @@ impl ObjectImpl for NotificationPopoverInner {
}));
});
let label = cascade! {
let summary_label = cascade! {
gtk4::Label::new(None);
..set_attributes(Some(&cascade! {
pango::AttrList::new();
..insert(pango::Attribute::new_weight(pango::Weight::Bold));
}));
};
let body_label = cascade! {
gtk4::Label::new(None);
};
@ -37,10 +48,15 @@ impl ObjectImpl for NotificationPopoverInner {
..set_autohide(false);
..set_has_arrow(false);
..set_offset(0, 12);
..set_child(Some(&label));
..set_child(Some(&cascade! {
gtk4::Box::new(gtk4::Orientation::Vertical, 0);
..append(&summary_label);
..append(&body_label);
}));
};
self.label.set(label);
self.summary_label.set(summary_label);
self.body_label.set(body_label);
}
}
@ -62,7 +78,8 @@ impl NotificationPopover {
NotificationPopoverInner::from_instance(self)
}
pub fn set_body(&self, body: &str) {
self.inner().label.set_label(body);
pub fn set_notification(&self, notification: &Notification) {
self.inner().summary_label.set_label(&notification.summary);
self.inner().body_label.set_label(&notification.body);
}
}

View file

@ -135,8 +135,9 @@ impl TimeButton {
fn handle_notification(&self, notification: &Notification) {
println!("{:?}", notification);
let popover = &self.inner().notification_popover;
popover.set_body(&notification.body);
popover.popup();
self.inner()
.notification_popover
.set_notification(notification);
self.inner().notification_popover.popup();
}
}