reset notice banner on page update

This commit is contained in:
yggverse 2025-03-05 16:55:38 +02:00
parent f7b653f36a
commit c8607e151a
4 changed files with 24 additions and 14 deletions

View file

@ -1,24 +1,33 @@
use adw::Banner;
pub trait Notice {
fn notice() -> Self;
fn show(&self, title: &str);
pub struct Notice {
pub banner: Banner,
}
impl Notice for Banner {
impl Notice {
// Constructors
/// Create new `Self`
fn notice() -> Self {
pub fn new() -> Self {
let banner = Banner::builder().button_label("Ok").build();
banner.connect_button_clicked(|this| this.set_revealed(false));
banner
Self { banner }
}
// Actions
fn show(&self, title: &str) {
self.set_title(title);
self.set_revealed(true);
pub fn show(&self, title: &str) {
self.banner.set_title(title);
self.banner.set_revealed(true);
}
pub fn unset(&self) {
self.banner.set_revealed(false);
}
}
impl Default for Notice {
fn default() -> Self {
Self::new()
}
}