window: collapse sidebar when dragged too narrow; keep controls accessible

When the paned divider is dragged left below 120 px, snap the sidebar
closed instead of leaving a sliver. This replaces the previous
minimum-width approach.

When the sidebar is hidden (via toggle or snap-close), show the refresh
button and primary menu in the content header so they remain reachable.
Both stacks are kept in sync (spinner/button) with their sidebar
counterparts during article fetches.
This commit is contained in:
Jeena 2026-03-22 02:10:37 +00:00
parent db41a691e6
commit 6d6d928733
2 changed files with 55 additions and 11 deletions

View file

@ -11,7 +11,6 @@ template $FeedTheMonkeyWindow : Adw.ApplicationWindow {
focusable: false;
shrink-start-child: false;
resize-start-child: false;
shrink-end-child: false;
start-child: Adw.ToolbarView sidebar_toolbar {
top-bar-style: raised;
@ -108,7 +107,6 @@ template $FeedTheMonkeyWindow : Adw.ApplicationWindow {
end-child: Adw.ToolbarView {
top-bar-style: raised;
width-request: 360;
[top]
Adw.HeaderBar {
@ -119,10 +117,39 @@ template $FeedTheMonkeyWindow : Adw.ApplicationWindow {
action-name: "win.toggle-sidebar";
}
[start]
Stack content_refresh_stack {
visible: false;
StackPage {
name: "button";
child: Button {
icon-name: "view-refresh-symbolic";
tooltip-text: _("Refresh");
action-name: "win.reload";
};
}
StackPage {
name: "spinner";
child: Spinner {
spinning: true;
width-request: 16;
height-request: 16;
};
}
}
title-widget: Adw.WindowTitle {
title: _("FeedTheMonkey");
};
[end]
MenuButton content_menu_button {
icon-name: "open-menu-symbolic";
primary: true;
menu-model: primary_menu;
visible: false;
}
[end]
MenuButton article_menu_button {
icon-name: "view-more-symbolic";

View file

@ -45,6 +45,10 @@ pub mod imp {
#[template_child]
pub article_menu_button: TemplateChild<gtk4::MenuButton>,
#[template_child]
pub content_refresh_stack: TemplateChild<gtk4::Stack>,
#[template_child]
pub content_menu_button: TemplateChild<gtk4::MenuButton>,
#[template_child]
pub sidebar_content: TemplateChild<gtk4::Stack>,
#[template_child]
pub article_list_view: TemplateChild<gtk4::ListView>,
@ -164,12 +168,18 @@ pub mod imp {
self.sidebar_zoom_css.set(zoom_css).ok();
self.update_sidebar_zoom(zoom);
// Persist sidebar width while dragging (only when visible)
// Persist sidebar width while dragging; collapse when dragged too narrow.
let s2 = settings.clone();
let sidebar_weak = self.sidebar_toolbar.downgrade();
let win_weak = self.obj().downgrade();
self.paned.connect_notify_local(Some("position"), move |paned, _| {
if sidebar_weak.upgrade().map(|s| s.is_visible()).unwrap_or(false) {
s2.set_int("sidebar-width", paned.position()).ok();
let Some(win) = win_weak.upgrade() else { return };
let imp = win.imp();
if !imp.sidebar_toolbar.is_visible() { return; }
let pos = paned.position();
if pos < 120 {
imp.set_sidebar_visible(false);
} else {
s2.set_int("sidebar-width", pos).ok();
}
});
@ -409,11 +419,16 @@ pub mod imp {
fn setup_sidebar_toggle(&self) {}
fn do_toggle_sidebar(&self) {
let sidebar = &*self.sidebar_toolbar;
if sidebar.is_visible() {
sidebar.set_visible(false);
} else {
sidebar.set_visible(true);
self.set_sidebar_visible(!self.sidebar_toolbar.is_visible());
}
fn set_sidebar_visible(&self, visible: bool) {
self.sidebar_toolbar.set_visible(visible);
// Mirror refresh stack state and primary menu in the content header
// when the sidebar is hidden, so those controls remain accessible.
self.content_refresh_stack.set_visible(!visible);
self.content_menu_button.set_visible(!visible);
if visible {
let settings = gio::Settings::new("net.jeena.FeedTheMonkey");
let saved = settings.int("sidebar-width");
self.paned.set_position(if saved > 0 { saved } else { 280 });
@ -630,6 +645,7 @@ pub mod imp {
*self.filter_rules.borrow_mut() = crate::filters::load_rules();
self.refresh_stack.set_visible_child_name("spinner");
self.content_refresh_stack.set_visible_child_name("spinner");
// Only show the loading screen if there's nothing to show yet.
let has_articles = self.article_store.borrow()
@ -725,6 +741,7 @@ pub mod imp {
}
}
imp.refresh_stack.set_visible_child_name("button");
imp.content_refresh_stack.set_visible_child_name("button");
},
);
}