Skip to content

Commit

Permalink
Implement scroll up/down
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoRiether committed Feb 8, 2024
1 parent e012b38 commit 1946dbd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions tori/src/component/visualizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl Default for ThreadHandle {
}
}

// TODO: use tokio::process
pub struct Visualizer {
pub state: Option<VisualizerState>,
pub width: usize,
Expand Down
2 changes: 2 additions & 0 deletions tori/src/events/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub enum Action {
Rerender,
Tick,
Input(KeyEvent),
ScrollDown,
ScrollUp,
Command(Command),
SongAdded { playlist: String, song: String },
RefreshSongs,
Expand Down
27 changes: 26 additions & 1 deletion tori/src/update/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
state::{browse_screen::Focus, Screen, State},
util::copy_to_clipboard,
};
use crossterm::event::{Event as TermEvent, KeyCode, KeyEvent, KeyEventKind};
use crossterm::event::{Event as TermEvent, KeyCode, KeyEvent, KeyEventKind, MouseEventKind};

pub fn handle_event(state: &mut State<'_>, ev: TermEvent) -> Result<Option<Action>> {
Ok(match ev {
Expand All @@ -19,6 +19,16 @@ pub fn handle_event(state: &mut State<'_>, ev: TermEvent) -> Result<Option<Actio
Focus::PlaylistsFilter(_) | Focus::SongsFilter(_) => Some(Action::Input(key)),
},
},
TermEvent::Mouse(mouse) => match mouse.kind {
MouseEventKind::Down(_) => todo!("Clicks are yet to be implemented!"),
MouseEventKind::Up(_) => todo!("Clickups are yet to be implemented!"),
MouseEventKind::Drag(_) => todo!("Dragging is yet to be implemented!"),
MouseEventKind::ScrollDown => Some(Action::ScrollDown),
MouseEventKind::ScrollUp => Some(Action::ScrollUp),
MouseEventKind::Moved | MouseEventKind::ScrollLeft | MouseEventKind::ScrollRight => {
None
}
},
_ => None,
})
}
Expand Down Expand Up @@ -59,6 +69,21 @@ pub fn update(state: &mut State<'_>, tx: Tx, act: Action) -> Result<Option<Actio
},
},

ScrollDown => match &mut state.screen {
Screen::BrowseScreen(screen) => match &screen.focus {
Focus::Playlists => screen.shown_playlists.select_next(),
Focus::Songs => screen.shown_songs.select_next(),
Focus::PlaylistsFilter(_) | Focus::SongsFilter(_) => {}
},
},
ScrollUp => match &mut state.screen {
Screen::BrowseScreen(screen) => match &screen.focus {
Focus::Playlists => screen.shown_playlists.select_prev(),
Focus::Songs => screen.shown_songs.select_prev(),
Focus::PlaylistsFilter(_) | Focus::SongsFilter(_) => {}
},
},

Tick => {
state.now_playing.update(&state.player);
state.visualizer.update()?;
Expand Down

0 comments on commit 1946dbd

Please sign in to comment.