From a94513ea22ff9a4919c22386cc7bc5d174c8a0a6 Mon Sep 17 00:00:00 2001 From: Alexander Keliris Date: Tue, 17 Mar 2020 16:11:40 +0000 Subject: [PATCH] Add basic view Pressing `B` will take you to a "basic view", which is just a centered playbar. Closes #320 --- src/app.rs | 2 ++ src/handlers/basic_view.rs | 7 +++++++ src/handlers/common_key_events.rs | 1 + src/handlers/mod.rs | 7 +++++++ src/main.rs | 3 +++ src/ui/mod.rs | 21 +++++++++++++++++++++ src/user_config.rs | 4 ++++ 7 files changed, 45 insertions(+) create mode 100644 src/handlers/basic_view.rs diff --git a/src/app.rs b/src/app.rs index e5034854..4818235a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -131,6 +131,7 @@ pub enum ActiveBlock { TrackTable, MadeForYou, Artists, + BasicView, } #[derive(Clone, PartialEq, Debug)] @@ -139,6 +140,7 @@ pub enum RouteId { AlbumTracks, AlbumList, Artist, + BasicView, Error, Home, RecentlyPlayed, diff --git a/src/handlers/basic_view.rs b/src/handlers/basic_view.rs new file mode 100644 index 00000000..0c659ff0 --- /dev/null +++ b/src/handlers/basic_view.rs @@ -0,0 +1,7 @@ +use crate::{app::App, event::Key}; + +pub fn handler(key: Key, _app: &mut App) { + match key { + _ => {} + }; +} diff --git a/src/handlers/common_key_events.rs b/src/handlers/common_key_events.rs index 05da4dac..b38810e1 100644 --- a/src/handlers/common_key_events.rs +++ b/src/handlers/common_key_events.rs @@ -147,6 +147,7 @@ pub fn handle_right_event(app: &mut App) { RouteId::SelectedDevice => {} RouteId::Error => {} RouteId::Analysis => {} + RouteId::BasicView => {} }, _ => {} }; diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index fc88d276..d1ccb9c8 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -3,6 +3,7 @@ mod album_tracks; mod analysis; mod artist; mod artists; +mod basic_view; mod common_key_events; mod empty; mod error_screen; @@ -84,6 +85,9 @@ pub fn handle_app(key: Key, app: &mut App) { _ if key == app.user_config.keys.audio_analysis => { app.get_audio_analysis(); } + _ if key == app.user_config.keys.basic_view => { + app.push_navigation_stack(RouteId::BasicView, ActiveBlock::BasicView); + } _ => handle_block_events(key, app), } } @@ -149,6 +153,9 @@ fn handle_block_events(key: Key, app: &mut App) { ActiveBlock::PlayBar => { playbar::handler(key, app); } + ActiveBlock::BasicView => { + basic_view::handler(key, app); + } } } diff --git a/src/main.rs b/src/main.rs index 66e5b03d..0e5118cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -261,6 +261,9 @@ async fn start_ui(user_config: UserConfig, app: &Arc>) -> Result<(), ActiveBlock::Analysis => { ui::audio_analysis::draw(&mut f, &app); } + ActiveBlock::BasicView => { + ui::draw_basic_view(&mut f, &app); + } _ => { ui::draw_main_layout(&mut f, &app); } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 8ad19fd1..b9f91150 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -230,6 +230,7 @@ where RouteId::Error => {} // This is handled as a "full screen" route in main.rs RouteId::SelectedDevice => {} // This is handled as a "full screen" route in main.rs RouteId::Analysis => {} // This is handled as a "full screen" route in main.rs + RouteId::BasicView => {} // This is handled as a "full screen" route in main.rs }; } @@ -728,6 +729,26 @@ where ) } +pub fn draw_basic_view(f: &mut Frame, app: &App) +where + B: Backend, +{ + let chunks = Layout::default() + .direction(Direction::Vertical) + .constraints( + [ + Constraint::Percentage(44), + Constraint::Min(6), + Constraint::Percentage(44), + ] + .as_ref(), + ) + .margin(4) + .split(f.size()); + + draw_playbar(f, app, chunks[1]); +} + pub fn draw_playbar(f: &mut Frame, app: &App, layout_chunk: Rect) where B: Backend, diff --git a/src/user_config.rs b/src/user_config.rs index aa9e6338..ca479496 100644 --- a/src/user_config.rs +++ b/src/user_config.rs @@ -163,6 +163,7 @@ pub struct KeyBindingsString { copy_song_url: Option, copy_album_url: Option, audio_analysis: Option, + basic_view: Option, } #[derive(Clone)] @@ -186,6 +187,7 @@ pub struct KeyBindings { pub copy_song_url: Key, pub copy_album_url: Key, pub audio_analysis: Key, + pub basic_view: Key, } #[derive(Default, Clone, Debug, PartialEq, Serialize, Deserialize)] @@ -240,6 +242,7 @@ impl UserConfig { copy_song_url: Key::Char('c'), copy_album_url: Key::Char('C'), audio_analysis: Key::Char('v'), + basic_view: Key::Char('B'), }, behavior: BehaviorConfig { seek_milliseconds: 5 * 1000, @@ -305,6 +308,7 @@ impl UserConfig { to_keys!(copy_song_url); to_keys!(copy_album_url); to_keys!(audio_analysis); + to_keys!(basic_view); Ok(()) }