Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #64 from Tubefeeder/title-header-bar
Browse files Browse the repository at this point in the history
Adaptive Title/Bar ViewSwitcher
  • Loading branch information
Schmiddiii authored Jun 21, 2022
2 parents cf963dd + d9dbdcd commit 1eadd16
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
17 changes: 17 additions & 0 deletions src/gui/header_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub mod imp {
pub struct HeaderBar {
#[template_child]
child_box: TemplateChild<gtk::Box>,
#[template_child]
titlebar: TemplateChild<libadwaita::ViewSwitcherTitle>,

title: RefCell<Option<String>>,
child: RefCell<Option<Object>>,
Expand Down Expand Up @@ -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::<crate::gui::window::Window>()
.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, _| {
Expand Down
9 changes: 6 additions & 3 deletions src/gui/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ gtk::glib::wrapper! {

impl Window {
pub fn new(app: &gtk::Application) -> Self {
// Make sure HeaderBar is loaded.
let _ = super::header_bar::HeaderBar::new();
Object::new(&[("application", app)]).expect("Failed to create Window")
}

Expand Down Expand Up @@ -82,7 +80,10 @@ pub mod imp {
#[template(resource = "/ui/window.ui")]
pub struct Window {
#[template_child]
application_stack: TemplateChild<libadwaita::ViewStack>,
pub(in crate::gui) application_stack: TemplateChild<libadwaita::ViewStack>,

#[template_child]
pub(in crate::gui) application_stack_bar: TemplateChild<libadwaita::ViewSwitcherBar>,

#[template_child]
pub(super) feed_page: TemplateChild<FeedPage>,
Expand Down Expand Up @@ -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);
}

Expand Down
16 changes: 10 additions & 6 deletions ui/header_bar.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
<property name="vexpand">True</property>
<property name="halign">GTK_ALIGN_FILL</property>
<property name="valign">GTK_ALIGN_FILL</property>
<property name="title-widget">
<object class="AdwWindowTitle">
<binding name="title">
<lookup name="title" type="TFHeaderBar"/>
</binding>
<child type="title">
<object class="GtkBox">
<child>
<object class="AdwViewSwitcherTitle" id="titlebar">
<binding name="title">
<lookup name="title" type="TFHeaderBar"/>
</binding>
</object>
</child>
</object>
</property>
</child>

<child>
<object class="GtkBox" id="child_box">
Expand Down
2 changes: 1 addition & 1 deletion ui/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</child>

<child>
<object class = "AdwViewSwitcher">
<object class="AdwViewSwitcherBar" id="application_stack_bar">
<property name="hexpand">True</property>
<property name="vexpand">False</property>
<property name="halign">GTK_ALIGN_FILL</property>
Expand Down

0 comments on commit 1eadd16

Please sign in to comment.