mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-27 07:34:27 +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> },
|
KillProcess { to_kill: Vec<Pid> },
|
||||||
ToggleFreeze,
|
ToggleFreeze,
|
||||||
Clean,
|
Clean,
|
||||||
Stop,
|
Quit,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
@ -203,10 +203,6 @@ impl AppState {
|
|||||||
// TODO: Redraw
|
// TODO: Redraw
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn quit(&mut self) {
|
|
||||||
self.terminator.store(true, SeqCst);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Application for AppState {
|
impl Application for AppState {
|
||||||
@ -228,7 +224,7 @@ impl Application for AppState {
|
|||||||
self.data_collection
|
self.data_collection
|
||||||
.clean_data(constants::STALE_MAX_MILLISECONDS);
|
.clean_data(constants::STALE_MAX_MILLISECONDS);
|
||||||
}
|
}
|
||||||
AppMessages::Stop => {
|
AppMessages::Quit => {
|
||||||
self.terminator.store(true, SeqCst);
|
self.terminator.store(true, SeqCst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -265,7 +261,7 @@ impl Application for AppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn global_event_handler(
|
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 crate::tuine::Event;
|
||||||
use crossterm::event::{KeyCode, KeyModifiers};
|
use crossterm::event::{KeyCode, KeyModifiers};
|
||||||
@ -275,20 +271,20 @@ impl Application for AppState {
|
|||||||
if event.modifiers.is_empty() {
|
if event.modifiers.is_empty() {
|
||||||
match event.code {
|
match event.code {
|
||||||
KeyCode::Char('q') | KeyCode::Char('Q') => {
|
KeyCode::Char('q') | KeyCode::Char('Q') => {
|
||||||
self.quit();
|
messages.push(AppMessages::Quit);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
} else if let KeyModifiers::CONTROL = event.modifiers {
|
} else if let KeyModifiers::CONTROL = event.modifiers {
|
||||||
match event.code {
|
match event.code {
|
||||||
KeyCode::Char('c') | KeyCode::Char('C') => {
|
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
|
self.children
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.zip(draw_ctx.children())
|
.zip(draw_ctx.children())
|
||||||
.for_each(|(child, child_node)| {
|
.for_each(|(child, child_draw_ctx)| {
|
||||||
if child_node.should_draw() {
|
if child_draw_ctx.should_draw() {
|
||||||
child.draw(state_ctx, child_node, frame);
|
child.draw(state_ctx, child_draw_ctx, frame);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_event(
|
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>,
|
messages: &mut Vec<Message>,
|
||||||
) -> Status {
|
) -> 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
|
Status::Ignored
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ pub struct StyleSheet {
|
|||||||
/// A sortable, scrollable table for text data.
|
/// A sortable, scrollable table for text data.
|
||||||
pub struct TextTable<'a, Message> {
|
pub struct TextTable<'a, Message> {
|
||||||
key: Key,
|
key: Key,
|
||||||
state: TextTableState,
|
|
||||||
column_widths: Vec<u16>,
|
column_widths: Vec<u16>,
|
||||||
columns: Vec<TextColumn>,
|
columns: Vec<TextColumn>,
|
||||||
show_gap: bool,
|
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 {
|
pub fn new<S: Into<Cow<'static, str>>>(ctx: &mut ViewContext<'_>, columns: Vec<S>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
key: ctx.register_component(Location::caller()),
|
key: ctx.register_component(Location::caller()),
|
||||||
state: TextTableState::default(),
|
|
||||||
column_widths: vec![0; columns.len()],
|
column_widths: vec![0; columns.len()],
|
||||||
columns: columns
|
columns: columns
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -251,22 +249,22 @@ impl<'a, Message> TmpComponent<Message> for TextTable<'a, Message> {
|
|||||||
todo!()
|
todo!()
|
||||||
} else if y > self.table_gap {
|
} else if y > self.table_gap {
|
||||||
let visual_index = usize::from(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 {
|
} else {
|
||||||
Status::Ignored
|
Status::Ignored
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MouseEventKind::ScrollDown => {
|
MouseEventKind::ScrollDown => {
|
||||||
let status = self.state.move_down(1);
|
let status = state.move_down(1);
|
||||||
if let Some(on_select) = &self.on_select {
|
if let Some(on_select) = &self.on_select {
|
||||||
messages.push(on_select(self.state.current_index()));
|
messages.push(on_select(state.current_index()));
|
||||||
}
|
}
|
||||||
status
|
status
|
||||||
}
|
}
|
||||||
MouseEventKind::ScrollUp => {
|
MouseEventKind::ScrollUp => {
|
||||||
let status = self.state.move_up(1);
|
let status = state.move_up(1);
|
||||||
if let Some(on_select) = &self.on_select {
|
if let Some(on_select) = &self.on_select {
|
||||||
messages.push(on_select(self.state.current_index()));
|
messages.push(on_select(state.current_index()));
|
||||||
}
|
}
|
||||||
status
|
status
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user