Skip to content

Commit

Permalink
feat(volumes-panel): Improve adaptability
Browse files Browse the repository at this point in the history
This commit rearranges the controls of the header bar into a bottom bar
if space becomes too tight. In addition, a toggle button is used for the
selection mode instead of a separate “Cancel” button.
  • Loading branch information
marhkb committed Oct 11, 2024
1 parent 2a8cea9 commit 5a0391b
Show file tree
Hide file tree
Showing 2 changed files with 275 additions and 262 deletions.
31 changes: 29 additions & 2 deletions src/view/volumes_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ mod imp {
#[property(get, set = Self::set_volume_list, explicit_notify, nullable)]
pub(super) volume_list: glib::WeakRef<model::VolumeList>,
#[property(get, set)]
pub(super) collapsed: Cell<bool>,
#[property(get, set)]
pub(super) show_only_used_volumes: Cell<bool>,
#[template_child]
pub(super) main_stack: TemplateChild<gtk::Stack>,
#[template_child]
pub(super) toolbar_view: TemplateChild<adw::ToolbarView>,
#[template_child]
pub(super) header_stack: TemplateChild<gtk::Stack>,
#[template_child]
pub(super) window_title: TemplateChild<adw::WindowTitle>,
Expand All @@ -60,6 +64,8 @@ mod imp {
pub(super) filter_stack: TemplateChild<gtk::Stack>,
#[template_child]
pub(super) list_box: TemplateChild<gtk::ListBox>,
#[template_child]
pub(super) overhang_action_bar: TemplateChild<gtk::ActionBar>,
}

#[glib::object_subclass]
Expand Down Expand Up @@ -147,6 +153,7 @@ mod imp {
let not_selection_mode_expr = selection_mode_expr.chain_closure::<bool>(closure!(
|_: Self::Type, selection_mode: bool| { !selection_mode }
));
let collapsed_expr = Self::Type::this_expression("collapsed");

gtk::ClosureExpression::new::<Option<String>>(
[
Expand Down Expand Up @@ -221,6 +228,28 @@ mod imp {

not_selection_mode_expr.bind(&self.search_bar.get(), "visible", Some(obj));

gtk::ClosureExpression::new::<bool>(
[
collapsed_expr.upcast_ref(),
not_selection_mode_expr.upcast_ref(),
],
closure!(|_: Self::Type, collapsed: bool, not_selection_mode: bool| {
collapsed && not_selection_mode
}),
)
.bind(&self.overhang_action_bar.get(), "revealed", Some(obj));

gtk::ClosureExpression::new::<bool>(
[
collapsed_expr.upcast_ref(),
selection_mode_expr.upcast_ref(),
],
closure!(|_: Self::Type, collapsed: bool, selection_mode: bool| {
collapsed || selection_mode
}),
)
.bind(&self.toolbar_view.get(), "reveal-bottom-bars", Some(obj));

let search_filter = gtk::CustomFilter::new(clone!(
#[weak]
obj,
Expand Down Expand Up @@ -287,8 +316,6 @@ mod imp {
fn on_notify_search_mode_enabled(&self) {
if self.search_bar.is_search_mode() {
self.search_entry.grab_focus();
} else {
self.search_entry.set_text("");
}
}

Expand Down
Loading

0 comments on commit 5a0391b

Please sign in to comment.