add mouse scrolling
This commit is contained in:
parent
53522c936d
commit
faaddc2bd7
36
src/app.rs
36
src/app.rs
|
|
@ -1,11 +1,12 @@
|
||||||
use std::{path::Path, time::Duration};
|
use std::{path::Path, time::Duration};
|
||||||
|
|
||||||
use crate::browser::FileBrowser;
|
use crate::browser::FileBrowser;
|
||||||
use crate::utils::FileExtension;
|
|
||||||
use crate::connection::Connection;
|
use crate::connection::Connection;
|
||||||
use crate::list::ContentList;
|
use crate::list::ContentList;
|
||||||
use crate::ui::InputMode;
|
use crate::ui::InputMode;
|
||||||
|
use crate::utils::FileExtension;
|
||||||
use mpd::{Client, Song};
|
use mpd::{Client, Song};
|
||||||
|
use ratatui::widgets::{ListState, TableState};
|
||||||
|
|
||||||
// Application result type
|
// Application result type
|
||||||
pub type AppResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
pub type AppResult<T> = std::result::Result<T, Box<dyn std::error::Error>>;
|
||||||
|
|
@ -386,4 +387,37 @@ impl App {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mouse event handlers
|
||||||
|
pub fn handle_scroll_up(&mut self) {
|
||||||
|
match self.selected_tab {
|
||||||
|
SelectedTab::Queue => {
|
||||||
|
self.queue_list.prev();
|
||||||
|
}
|
||||||
|
SelectedTab::DirectoryBrowser => {
|
||||||
|
self.browser.prev();
|
||||||
|
}
|
||||||
|
SelectedTab::Playlists => {
|
||||||
|
self.pl_list.prev();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handle_scroll_down(&mut self) {
|
||||||
|
match self.selected_tab {
|
||||||
|
SelectedTab::Queue => {
|
||||||
|
self.queue_list.next();
|
||||||
|
}
|
||||||
|
SelectedTab::DirectoryBrowser => {
|
||||||
|
self.browser.next();
|
||||||
|
}
|
||||||
|
SelectedTab::Playlists => {
|
||||||
|
self.pl_list.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handle_mouse_left_click(&mut self, x: u16, y: u16) -> AppResult<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use crate::{
|
||||||
app::{App, AppResult, SelectedTab},
|
app::{App, AppResult, SelectedTab},
|
||||||
ui::InputMode,
|
ui::InputMode,
|
||||||
};
|
};
|
||||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use super::{pl_append_keys, pl_rename_keys, search_keys};
|
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<()> {
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn handle_mouse_events(mouse_event: MouseEvent, app: &mut App) -> AppResult<()> {
|
||||||
|
match mouse_event.kind {
|
||||||
|
MouseEventKind::ScrollUp => app.handle_scroll_up(),
|
||||||
|
MouseEventKind::ScrollDown => app.handle_scroll_down(),
|
||||||
|
MouseEventKind::Down(button) => {
|
||||||
|
let (x, y) = (mouse_event.column, mouse_event.row);
|
||||||
|
match button {
|
||||||
|
crossterm::event::MouseButton::Left => app.handle_mouse_left_click(x, y)?,
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,7 @@ fn main() -> AppResult<()> {
|
||||||
match tui.events.next()? {
|
match tui.events.next()? {
|
||||||
Event::Tick => app.tick()?,
|
Event::Tick => app.tick()?,
|
||||||
Event::Key(key_event) => handler::handle_key_events(key_event, &mut app)?,
|
Event::Key(key_event) => handler::handle_key_events(key_event, &mut app)?,
|
||||||
Event::Mouse(_) => {}
|
Event::Mouse(mouse_event) => handler::handle_mouse_events(mouse_event, &mut app)?,
|
||||||
Event::Resize(_, _) => {}
|
Event::Resize(_, _) => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in New Issue