From cf2c96a4ad13b7f9c7114094d79e9ff606589902 Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Tue, 12 Nov 2024 23:36:46 -0500 Subject: [PATCH] w.i.p. concept for more mouse interaction within the tui --- tui/src/state.rs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/tui/src/state.rs b/tui/src/state.rs index 7f96aee9..ec86bdc7 100644 --- a/tui/src/state.rs +++ b/tui/src/state.rs @@ -13,7 +13,7 @@ use linutil_core::{ego_tree::NodeId, Config, ListNode, TabList}; #[cfg(feature = "tips")] use rand::Rng; use ratatui::{ - crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers, MouseEvent, MouseEventKind}, + crossterm::event::{KeyCode, KeyEvent, KeyEventKind, KeyModifiers, MouseEvent, MouseEventKind, MouseButton}, layout::{Alignment, Constraint, Direction, Flex, Layout, Position, Rect}, style::{Style, Stylize}, text::{Line, Span, Text}, @@ -501,9 +501,30 @@ impl AppState { match event.kind { MouseEventKind::Moved => { if mouse_in_list { - self.focus = Focus::List + self.focus = Focus::List; + if let Some(areas) = &self.areas { + let relative_y = position.y.saturating_sub(areas.list.y + 1); + let list_len = self.filter.item_list().len(); + if relative_y < list_len as u16 { + self.selection.select(Some(relative_y as usize)); + } + } } else if mouse_in_tab_list { - self.focus = Focus::TabList + self.focus = Focus::TabList; + if let Some(areas) = &self.areas { + let relative_y = position.y.saturating_sub(areas.tab_list.y + 1); + if relative_y < self.tabs.len() as u16 { + self.current_tab.select(Some(relative_y as usize)); + self.refresh_tab(); + } + } + } + } + MouseEventKind::Down(MouseButton::Left) => { + if mouse_in_list { + self.handle_enter(); + } else if mouse_in_tab_list { + self.focus = Focus::List; } } MouseEventKind::ScrollDown => { @@ -513,7 +534,7 @@ impl AppState { } self.refresh_tab(); } else if mouse_in_list { - self.selection.select_next() + self.scroll_down(); } } MouseEventKind::ScrollUp => { @@ -523,7 +544,7 @@ impl AppState { } self.refresh_tab(); } else if mouse_in_list { - self.selection.select_previous() + self.scroll_up(); } } _ => {}