Add button to toggle view

This commit is contained in:
Jeremy Soller 2024-01-05 15:17:38 -07:00
parent 40ee305eb2
commit 6acac60526
No known key found for this signature in database
GPG key ID: DCFCA852D3906975
2 changed files with 18 additions and 0 deletions

View file

@ -482,6 +482,16 @@ impl Application for App {
let cosmic_theme::Spacing { space_xxs, .. } = self.core().system_theme().cosmic().spacing;
let active = self.tab_model.active();
let current_view = if let Some(tab) = self.tab_model.data::<Tab>(active) {
tab.view
} else {
tab::View::Grid
};
let (view, view_icon) = match current_view {
tab::View::Grid => (tab::View::List, "view-list-symbolic"),
tab::View::List => (tab::View::Grid, "view-grid-symbolic"),
};
vec![row![
widget::button(widget::icon::from_name("list-add-symbolic").size(16).icon())
.on_press(Message::TabNew)
@ -494,6 +504,10 @@ impl Application for App {
widget::button(widget::icon::from_name("go-up-symbolic").size(16).icon())
.on_press(Message::TabMessage(active, tab::Message::Parent))
.padding(space_xxs)
.style(style::Button::Icon),
widget::button(widget::icon::from_name(view_icon).size(16).icon())
.on_press(Message::TabMessage(active, tab::Message::View(view)))
.padding(space_xxs)
.style(style::Button::Icon)
]
.align_items(Alignment::Center)

View file

@ -217,6 +217,7 @@ pub enum Message {
Click(Option<usize>),
Home,
Parent,
View(View),
}
#[derive(Clone)]
@ -397,6 +398,9 @@ impl Tab {
cd = Some(parent.to_owned());
}
}
Message::View(view) => {
self.view = view;
}
}
if let Some(path) = cd {
self.path = path;