mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-26 23:24:20 +02:00
Add flex event handling
This commit is contained in:
parent
56a9856796
commit
6ad4cbf464
16
src/app.rs
16
src/app.rs
@ -132,7 +132,7 @@ pub enum AppMessages {
|
||||
KillProcess { to_kill: Vec<Pid> },
|
||||
ToggleFreeze,
|
||||
Clean,
|
||||
Stop,
|
||||
Quit,
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
@ -203,10 +203,6 @@ impl AppState {
|
||||
// TODO: Redraw
|
||||
}
|
||||
}
|
||||
|
||||
fn quit(&mut self) {
|
||||
self.terminator.store(true, SeqCst);
|
||||
}
|
||||
}
|
||||
|
||||
impl Application for AppState {
|
||||
@ -228,7 +224,7 @@ impl Application for AppState {
|
||||
self.data_collection
|
||||
.clean_data(constants::STALE_MAX_MILLISECONDS);
|
||||
}
|
||||
AppMessages::Stop => {
|
||||
AppMessages::Quit => {
|
||||
self.terminator.store(true, SeqCst);
|
||||
}
|
||||
}
|
||||
@ -265,7 +261,7 @@ impl Application for AppState {
|
||||
}
|
||||
|
||||
fn global_event_handler(
|
||||
&mut self, event: crate::tuine::Event, _messages: &mut Vec<Self::Message>,
|
||||
&mut self, event: crate::tuine::Event, messages: &mut Vec<Self::Message>,
|
||||
) {
|
||||
use crate::tuine::Event;
|
||||
use crossterm::event::{KeyCode, KeyModifiers};
|
||||
@ -275,20 +271,20 @@ impl Application for AppState {
|
||||
if event.modifiers.is_empty() {
|
||||
match event.code {
|
||||
KeyCode::Char('q') | KeyCode::Char('Q') => {
|
||||
self.quit();
|
||||
messages.push(AppMessages::Quit);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} else if let KeyModifiers::CONTROL = event.modifiers {
|
||||
match event.code {
|
||||
KeyCode::Char('c') | KeyCode::Char('C') => {
|
||||
self.quit();
|
||||
messages.push(AppMessages::Quit);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
Event::Mouse(event) => {}
|
||||
Event::Mouse(_event) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95,18 +95,25 @@ impl<'a, Message> TmpComponent<Message> for Flex<'a, Message> {
|
||||
self.children
|
||||
.iter_mut()
|
||||
.zip(draw_ctx.children())
|
||||
.for_each(|(child, child_node)| {
|
||||
if child_node.should_draw() {
|
||||
child.draw(state_ctx, child_node, frame);
|
||||
.for_each(|(child, child_draw_ctx)| {
|
||||
if child_draw_ctx.should_draw() {
|
||||
child.draw(state_ctx, child_draw_ctx, frame);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn on_event(
|
||||
&mut self, _state_ctx: &mut StateContext<'_>, _draw_ctx: DrawContext<'_>, event: Event,
|
||||
&mut self, state_ctx: &mut StateContext<'_>, draw_ctx: DrawContext<'_>, event: Event,
|
||||
messages: &mut Vec<Message>,
|
||||
) -> Status {
|
||||
// FIXME: On event for flex
|
||||
for (child, child_draw_ctx) in self.children.iter_mut().zip(draw_ctx.children()) {
|
||||
match child.on_event(state_ctx, child_draw_ctx, event, messages) {
|
||||
Status::Captured => {
|
||||
return Status::Captured;
|
||||
}
|
||||
Status::Ignored => {}
|
||||
}
|
||||
}
|
||||
|
||||
Status::Ignored
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ pub struct StyleSheet {
|
||||
/// A sortable, scrollable table for text data.
|
||||
pub struct TextTable<'a, Message> {
|
||||
key: Key,
|
||||
state: TextTableState,
|
||||
column_widths: Vec<u16>,
|
||||
columns: Vec<TextColumn>,
|
||||
show_gap: bool,
|
||||
@ -48,7 +47,6 @@ impl<'a, Message> TextTable<'a, Message> {
|
||||
pub fn new<S: Into<Cow<'static, str>>>(ctx: &mut ViewContext<'_>, columns: Vec<S>) -> Self {
|
||||
Self {
|
||||
key: ctx.register_component(Location::caller()),
|
||||
state: TextTableState::default(),
|
||||
column_widths: vec![0; columns.len()],
|
||||
columns: columns
|
||||
.into_iter()
|
||||
@ -251,22 +249,22 @@ impl<'a, Message> TmpComponent<Message> for TextTable<'a, Message> {
|
||||
todo!()
|
||||
} else if y > self.table_gap {
|
||||
let visual_index = usize::from(y - self.table_gap);
|
||||
self.state.set_visual_index(visual_index)
|
||||
state.set_visual_index(visual_index)
|
||||
} else {
|
||||
Status::Ignored
|
||||
}
|
||||
}
|
||||
MouseEventKind::ScrollDown => {
|
||||
let status = self.state.move_down(1);
|
||||
let status = state.move_down(1);
|
||||
if let Some(on_select) = &self.on_select {
|
||||
messages.push(on_select(self.state.current_index()));
|
||||
messages.push(on_select(state.current_index()));
|
||||
}
|
||||
status
|
||||
}
|
||||
MouseEventKind::ScrollUp => {
|
||||
let status = self.state.move_up(1);
|
||||
let status = state.move_up(1);
|
||||
if let Some(on_select) = &self.on_select {
|
||||
messages.push(on_select(self.state.current_index()));
|
||||
messages.push(on_select(state.current_index()));
|
||||
}
|
||||
status
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user