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 cascade::cascade;
use gtk4::{ use gtk4::{
glib::{self, clone}, glib::{self, clone},
pango,
prelude::*, prelude::*,
subclass::prelude::*, subclass::prelude::*,
}; };
use crate::deref_cell::DerefCell; use crate::deref_cell::DerefCell;
use crate::notifications::Notification;
#[derive(Default)] #[derive(Default)]
pub struct NotificationPopoverInner { pub struct NotificationPopoverInner {
label: DerefCell<gtk4::Label>, summary_label: DerefCell<gtk4::Label>,
body_label: DerefCell<gtk4::Label>,
} }
#[glib::object_subclass] #[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); gtk4::Label::new(None);
}; };
@ -37,10 +48,15 @@ impl ObjectImpl for NotificationPopoverInner {
..set_autohide(false); ..set_autohide(false);
..set_has_arrow(false); ..set_has_arrow(false);
..set_offset(0, 12); ..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) NotificationPopoverInner::from_instance(self)
} }
pub fn set_body(&self, body: &str) { pub fn set_notification(&self, notification: &Notification) {
self.inner().label.set_label(body); 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) { fn handle_notification(&self, notification: &Notification) {
println!("{:?}", notification); println!("{:?}", notification);
let popover = &self.inner().notification_popover; self.inner()
popover.set_body(&notification.body); .notification_popover
popover.popup(); .set_notification(notification);
self.inner().notification_popover.popup();
} }
} }