diff --git a/src/gui/header_bar.rs b/src/gui/header_bar.rs index 46566e1..01636c1 100644 --- a/src/gui/header_bar.rs +++ b/src/gui/header_bar.rs @@ -60,6 +60,8 @@ pub mod imp { pub struct HeaderBar { #[template_child] child_box: TemplateChild, + #[template_child] + titlebar: TemplateChild, title: RefCell>, child: RefCell>, @@ -118,6 +120,21 @@ pub mod imp { fn constructed(&self, obj: &Self::Type) { self.parent_constructed(obj); self.setup_actions(obj); + + obj.connect_root_notify(clone!(@strong self.titlebar as titlebar => move |o| { + if let Some(root) = o.root() { + let window = root + .downcast::() + .expect("Root to be window"); + window.connect_realize(clone!(@strong titlebar => move |w| { + let stack = &w.imp().application_stack; + let stack_switcher = &w.imp().application_stack_bar; + titlebar + .set_stack(Some(stack)); + titlebar.bind_property("title-visible", &stack_switcher.get(), "reveal").build(); + })); + } + })); obj.connect_notify_local( Some("child"), clone!(@strong self.child_box as b => move |obj, _| { diff --git a/src/gui/window.rs b/src/gui/window.rs index 097ae2a..a0a5e45 100644 --- a/src/gui/window.rs +++ b/src/gui/window.rs @@ -34,8 +34,6 @@ gtk::glib::wrapper! { impl Window { pub fn new(app: >k::Application) -> Self { - // Make sure HeaderBar is loaded. - let _ = super::header_bar::HeaderBar::new(); Object::new(&[("application", app)]).expect("Failed to create Window") } @@ -82,7 +80,10 @@ pub mod imp { #[template(resource = "/ui/window.ui")] pub struct Window { #[template_child] - application_stack: TemplateChild, + pub(in crate::gui) application_stack: TemplateChild, + + #[template_child] + pub(in crate::gui) application_stack_bar: TemplateChild, #[template_child] pub(super) feed_page: TemplateChild, @@ -225,6 +226,8 @@ pub mod imp { type ParentType = libadwaita::ApplicationWindow; fn class_init(klass: &mut Self::Class) { + // Make sure HeaderBar is loaded. + crate::gui::header_bar::HeaderBar::ensure_type(); Self::bind_template(klass); } diff --git a/ui/header_bar.ui b/ui/header_bar.ui index 383d382..4526e22 100644 --- a/ui/header_bar.ui +++ b/ui/header_bar.ui @@ -14,13 +14,17 @@ True GTK_ALIGN_FILL GTK_ALIGN_FILL - - - - - + + + + + + + + + - + diff --git a/ui/window.ui b/ui/window.ui index b7b01c9..dbacc3b 100644 --- a/ui/window.ui +++ b/ui/window.ui @@ -55,7 +55,7 @@ - + True False GTK_ALIGN_FILL