From f701027dff3ee07aaf2ac21b013ec74b71f06f35 Mon Sep 17 00:00:00 2001 From: Samuel Oldham Date: Fri, 9 Aug 2024 07:06:50 +0100 Subject: [PATCH 1/3] Add buttons and functionality --- psst-gui/src/ui/mod.rs | 61 ++++++++++++++++++++++++++++++++++++ psst-gui/src/widget/icons.rs | 7 +++++ 2 files changed, 68 insertions(+) diff --git a/psst-gui/src/ui/mod.rs b/psst-gui/src/ui/mod.rs index f51189dc..371877f8 100644 --- a/psst-gui/src/ui/mod.rs +++ b/psst-gui/src/ui/mod.rs @@ -145,6 +145,8 @@ fn root_widget() -> impl Widget { .with_child(topbar_back_button_widget()) .with_child(topbar_title_widget()) .with_child(topbar_sort_widget()) + .with_flex_spacer(6.0) + .with_child(topbar_shortcut_buttons_widget()) .background(Border::Bottom.with_color(theme::BACKGROUND_DARK)); let main = Flex::column() @@ -413,6 +415,65 @@ fn topbar_back_button_widget() -> impl Widget { .lens(AppState::history) } +fn topbar_shortcut_buttons_widget() -> impl Widget { + let reload_icon = icons::RELOAD.scale(theme::ICON_SIZE_LARGE) + .padding(theme::grid(1.0)) + .link() + .rounded(theme::BUTTON_BORDER_RADIUS) + .on_left_click(|ctx, _, data: &mut AppState, _| { + match &data.nav { + Nav::SavedTracks => { + ctx.submit_command(library::LOAD_TRACKS); + } + Nav::SavedShows => { + ctx.submit_command(library::LOAD_SHOWS); + } + Nav::SavedAlbums => { + ctx.submit_command(library::LOAD_ALBUMS); + } + Nav::Home => { + ctx.submit_command(home::LOAD_MADE_FOR_YOU); + } + Nav::PlaylistDetail(_) => { + ctx.submit_command(cmd::NAVIGATE_REFRESH); + } + _ => {} + } + }); + + let search_icon = icons::SEARCH.scale(theme::ICON_SIZE_LARGE) + .padding(theme::grid(1.0)) + .link() + .rounded(theme::BUTTON_BORDER_RADIUS) + .on_left_click(|ctx, _, _, _| { + ctx.submit_command(cmd::TOGGLE_FINDER); + }); + let srch_icon = Either::new( + |nav: &AppState, _| { + // check if the current nav is PlaylistDetail + !matches!(nav.nav, Nav::SavedTracks) + && !matches!(nav.nav, Nav::SavedShows) + && !matches!(nav.nav, Nav::Home) + && !matches!(nav.nav, Nav::SavedAlbums) + }, + search_icon, + Empty.boxed(), + ); + + let icons = Flex::row() + .with_child(reload_icon) + .with_child(srch_icon); + + Either::new( + |nav: &AppState, _| { + !matches!(nav.nav, Nav::SearchResults(_)) + && !matches!(nav.nav, Nav::Recommendations(_)) + }, + icons, + Empty.boxed(), + ) +} + fn history_menu(history: &Vector