rmptuib9bbabd
add mouse scrolling
+53 −3
3 files changed
- M src/app.rs +35 −1
- M src/event/handler.rs +17 −1
- M src/main.rs +1 −1
| @@ -1,11 +1,12 @@ | |||
| 1 | 1 | use std::{path::Path, time::Duration}; | |
| 2 | 2 | ||
| 3 | 3 | use crate::browser::FileBrowser; | |
| 4 | − | use crate::utils::FileExtension; | |
| 5 | 4 | use crate::connection::Connection; | |
| 6 | 5 | use crate::list::ContentList; | |
| 7 | 6 | use crate::ui::InputMode; | |
| 7 | + | use crate::utils::FileExtension; | |
| 8 | 8 | use mpd::{Client, Song}; | |
| 9 | + | use ratatui::widgets::{ListState, TableState}; | |
| 9 | 10 | ||
| 10 | 11 | // Application result type | |
| 11 | 12 | pub type AppResult<T> = std::result::Result<T, Box<dyn std::error::Error>>; | |
| @@ -386,4 +387,37 @@ impl App { | |||
| 386 | 387 | } | |
| 387 | 388 | Ok(()) | |
| 388 | 389 | } | |
| 390 | + | ||
| 391 | + | // Mouse event handlers | |
| 392 | + | pub fn handle_scroll_up(&mut self) { | |
| 393 | + | match self.selected_tab { | |
| 394 | + | SelectedTab::Queue => { | |
| 395 | + | self.queue_list.prev(); | |
| 396 | + | } | |
| 397 | + | SelectedTab::DirectoryBrowser => { | |
| 398 | + | self.browser.prev(); | |
| 399 | + | } | |
| 400 | + | SelectedTab::Playlists => { | |
| 401 | + | self.pl_list.prev(); | |
| 402 | + | } | |
| 403 | + | } | |
| 404 | + | } | |
| 405 | + | ||
| 406 | + | pub fn handle_scroll_down(&mut self) { | |
| 407 | + | match self.selected_tab { | |
| 408 | + | SelectedTab::Queue => { | |
| 409 | + | self.queue_list.next(); | |
| 410 | + | } | |
| 411 | + | SelectedTab::DirectoryBrowser => { | |
| 412 | + | self.browser.next(); | |
| 413 | + | } | |
| 414 | + | SelectedTab::Playlists => { | |
| 415 | + | self.pl_list.next(); | |
| 416 | + | } | |
| 417 | + | } | |
| 418 | + | } | |
| 419 | + | ||
| 420 | + | pub fn handle_mouse_left_click(&mut self, x: u16, y: u16) -> AppResult<()> { | |
| 421 | + | Ok(()) | |
| 422 | + | } | |
| 389 | 423 | } | |
| @@ -2,7 +2,7 @@ use crate::{ | |||
| 2 | 2 | app::{App, AppResult, SelectedTab}, | |
| 3 | 3 | ui::InputMode, | |
| 4 | 4 | }; | |
| 5 | − | use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; | |
| 5 | + | use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind}; | |
| 6 | 6 | use std::time::Duration; | |
| 7 | 7 | ||
| 8 | 8 | use super::{pl_append_keys, pl_rename_keys, search_keys}; | |
| @@ -297,3 +297,19 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> { | |||
| 297 | 297 | } | |
| 298 | 298 | Ok(()) | |
| 299 | 299 | } | |
| 300 | + | ||
| 301 | + | pub fn handle_mouse_events(mouse_event: MouseEvent, app: &mut App) -> AppResult<()> { | |
| 302 | + | match mouse_event.kind { | |
| 303 | + | MouseEventKind::ScrollUp => app.handle_scroll_up(), | |
| 304 | + | MouseEventKind::ScrollDown => app.handle_scroll_down(), | |
| 305 | + | MouseEventKind::Down(button) => { | |
| 306 | + | let (x, y) = (mouse_event.column, mouse_event.row); | |
| 307 | + | match button { | |
| 308 | + | crossterm::event::MouseButton::Left => app.handle_mouse_left_click(x, y)?, | |
| 309 | + | _ => {} | |
| 310 | + | } | |
| 311 | + | } | |
| 312 | + | _ => {} | |
| 313 | + | } | |
| 314 | + | Ok(()) | |
| 315 | + | } | |
| @@ -35,7 +35,7 @@ fn main() -> AppResult<()> { | |||
| 35 | 35 | match tui.events.next()? { | |
| 36 | 36 | Event::Tick => app.tick()?, | |
| 37 | 37 | Event::Key(key_event) => handler::handle_key_events(key_event, &mut app)?, | |
| 38 | − | Event::Mouse(_) => {} | |
| 38 | + | Event::Mouse(mouse_event) => handler::handle_mouse_events(mouse_event, &mut app)?, | |
| 39 | 39 | Event::Resize(_, _) => {} | |
| 40 | 40 | } | |
| 41 | 41 | } | |