Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement a greater extent of mouse interaction within the tui #946

Closed
wants to merge 11 commits into from
Next Next commit
w.i.p. concept for more mouse interaction within the tui
run fmt
nnyyxxxx committed Nov 17, 2024
commit 55fed66f0b2d9db4b0c9c3672643be83b5294b44
33 changes: 28 additions & 5 deletions tui/src/state.rs
Original file line number Diff line number Diff line change
@@ -13,7 +13,9 @@ 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, MouseButton, MouseEvent, MouseEventKind,
},
layout::{Alignment, Constraint, Direction, Flex, Layout, Position, Rect},
style::{Style, Stylize},
text::{Line, Span, Text},
@@ -501,9 +503,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;
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::TabList
self.focus = Focus::List;
}
}
MouseEventKind::ScrollDown => {
@@ -513,7 +536,7 @@ impl AppState {
}
self.refresh_tab();
} else if mouse_in_list {
self.selection.select_next()
self.scroll_down();
}
}
MouseEventKind::ScrollUp => {
@@ -523,7 +546,7 @@ impl AppState {
}
self.refresh_tab();
} else if mouse_in_list {
self.selection.select_previous()
self.scroll_up();
}
}
_ => {}