diff options
author | ClementTsang <cjhtsang@uwaterloo.ca> | 2021-09-22 01:16:33 -0400 |
---|---|---|
committer | ClementTsang <cjhtsang@uwaterloo.ca> | 2021-09-22 01:16:33 -0400 |
commit | 7ee85a82f794c44b3a0bb6a50e8075eff96bb4c8 (patch) | |
tree | 35f2817649638873113b8b51c220adfee2454de1 /src/app/widgets | |
parent | e7b9c729123eda386f12ce90faaa413bf516fed3 (diff) |
refactor: finish help menu
Diffstat (limited to 'src/app/widgets')
-rw-r--r-- | src/app/widgets/base/scrollable.rs | 47 | ||||
-rw-r--r-- | src/app/widgets/base/sort_menu.rs | 6 | ||||
-rw-r--r-- | src/app/widgets/base/sort_text_table.rs | 12 | ||||
-rw-r--r-- | src/app/widgets/base/text_input.rs | 76 | ||||
-rw-r--r-- | src/app/widgets/base/text_table.rs | 12 | ||||
-rw-r--r-- | src/app/widgets/base/time_graph.rs | 42 | ||||
-rw-r--r-- | src/app/widgets/bottom_widgets/basic_mem.rs | 11 | ||||
-rw-r--r-- | src/app/widgets/bottom_widgets/battery.rs | 24 | ||||
-rw-r--r-- | src/app/widgets/bottom_widgets/carousel.rs | 12 | ||||
-rw-r--r-- | src/app/widgets/bottom_widgets/cpu.rs | 16 | ||||
-rw-r--r-- | src/app/widgets/bottom_widgets/disk.rs | 8 | ||||
-rw-r--r-- | src/app/widgets/bottom_widgets/mem.rs | 8 | ||||
-rw-r--r-- | src/app/widgets/bottom_widgets/net.rs | 25 | ||||
-rw-r--r-- | src/app/widgets/bottom_widgets/process.rs | 65 | ||||
-rw-r--r-- | src/app/widgets/bottom_widgets/temp.rs | 11 | ||||
-rw-r--r-- | src/app/widgets/dialogs.rs | 2 | ||||
-rw-r--r-- | src/app/widgets/dialogs/help.rs | 304 | ||||
-rw-r--r-- | src/app/widgets/tui_stuff/block_builder.rs | 38 |
18 files changed, 507 insertions, 212 deletions
diff --git a/src/app/widgets/base/scrollable.rs b/src/app/widgets/base/scrollable.rs index ba4faa5f..b8652a9f 100644 --- a/src/app/widgets/base/scrollable.rs +++ b/src/app/widgets/base/scrollable.rs @@ -4,7 +4,7 @@ use crossterm::event::{KeyEvent, KeyModifiers, MouseButton, MouseEvent, MouseEve use tui::{layout::Rect, widgets::TableState}; use crate::app::{ - event::{MultiKey, MultiKeyResult, WidgetEventResult}, + event::{ComponentEventResult, MultiKey, MultiKeyResult}, Component, }; @@ -138,54 +138,54 @@ impl Scrollable { } } - fn skip_to_first(&mut self) -> WidgetEventResult { + fn skip_to_first(&mut self) -> ComponentEventResult { if self.current_index != 0 { self.set_index(0); - WidgetEventResult::Redraw + ComponentEventResult::Redraw } else { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } } - fn skip_to_last(&mut self) -> WidgetEventResult { + fn skip_to_last(&mut self) -> ComponentEventResult { let last_index = self.num_items - 1; if self.current_index != last_index { self.set_index(last_index); - WidgetEventResult::Redraw + ComponentEventResult::Redraw } else { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } } /// Moves *downward* by *incrementing* the current index. - fn move_down(&mut self, change_by: usize) -> WidgetEventResult { + fn move_down(&mut self, change_by: usize) -> ComponentEventResult { if self.num_items == 0 { - return WidgetEventResult::NoRedraw; + return ComponentEventResult::NoRedraw; } let new_index = self.current_index + change_by; if new_index >= self.num_items || self.current_index == new_index { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } else { self.set_index(new_index); - WidgetEventResult::Redraw + ComponentEventResult::Redraw } } /// Moves *upward* by *decrementing* the current index. - fn move_up(&mut self, change_by: usize) -> WidgetEventResult { + fn move_up(&mut self, change_by: usize) -> ComponentEventResult { if self.num_items == 0 { - return WidgetEventResult::NoRedraw; + return ComponentEventResult::NoRedraw; } let new_index = self.current_index.saturating_sub(change_by); if self.current_index == new_index { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } else { self.set_index(new_index); - WidgetEventResult::Redraw + ComponentEventResult::Redraw } } @@ -207,7 +207,7 @@ impl Scrollable { } impl Component for Scrollable { - fn handle_key_event(&mut self, event: KeyEvent) -> WidgetEventResult { + fn handle_key_event(&mut self, event: KeyEvent) -> ComponentEventResult { use crossterm::event::KeyCode::{Char, Down, Up}; if event.modifiers == KeyModifiers::NONE || event.modifiers == KeyModifiers::SHIFT { @@ -218,18 +218,19 @@ impl Component for Scrollable { Char('k') => self.move_up(1), Char('g') => match self.gg_manager.input('g') { MultiKeyResult::Completed => self.skip_to_first(), - MultiKeyResult::Accepted => WidgetEventResult::NoRedraw, - MultiKeyResult::Rejected => WidgetEventResult::NoRedraw, + MultiKeyResult::Accepted | MultiKeyResult::Rejected => { + ComponentEventResult::NoRedraw + } }, Char('G') => self.skip_to_last(), - _ => WidgetEventResult::NoRedraw, + _ => ComponentEventResult::Unhandled, } } else { - WidgetEventResult::NoRedraw + ComponentEventResult::Unhandled } } - fn handle_mouse_event(&mut self, event: MouseEvent) -> WidgetEventResult { + fn handle_mouse_event(&mut self, event: MouseEvent) -> ComponentEventResult { match event.kind { MouseEventKind::Down(MouseButton::Left) => { if self.does_bounds_intersect_mouse(&event) { @@ -256,11 +257,11 @@ impl Component for Scrollable { } } - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } MouseEventKind::ScrollDown => self.move_down(1), MouseEventKind::ScrollUp => self.move_up(1), - _ => WidgetEventResult::NoRedraw, + _ => ComponentEventResult::Unhandled, } } diff --git a/src/app/widgets/base/sort_menu.rs b/src/app/widgets/base/sort_menu.rs index b893a418..548bbf77 100644 --- a/src/app/widgets/base/sort_menu.rs +++ b/src/app/widgets/base/sort_menu.rs @@ -3,7 +3,7 @@ use tui::{backend::Backend, layout::Rect, Frame}; use crate::{ app::{ - event::WidgetEventResult, text_table::SimpleColumn, widgets::tui_stuff::BlockBuilder, + event::ComponentEventResult, text_table::SimpleColumn, widgets::tui_stuff::BlockBuilder, Component, TextTable, }, canvas::Painter, @@ -69,11 +69,11 @@ impl Component for SortMenu { self.bounds = new_bounds; } - fn handle_key_event(&mut self, event: KeyEvent) -> WidgetEventResult { + fn handle_key_event(&mut self, event: KeyEvent) -> ComponentEventResult { self.table.handle_key_event(event) } - fn handle_mouse_event(&mut self, event: MouseEvent) -> WidgetEventResult { + fn handle_mouse_event(&mut self, event: MouseEvent) -> ComponentEventResult { self.table.handle_mouse_event(event) } } diff --git a/src/app/widgets/base/sort_text_table.rs b/src/app/widgets/base/sort_text_table.rs index 64766041..f1f3b0e4 100644 --- a/src/app/widgets/base/sort_text_table.rs +++ b/src/app/widgets/base/sort_text_table.rs @@ -5,7 +5,7 @@ use tui::{backend::Backend, layout::Rect, Frame}; use crate::{ app::{ - event::{ReturnSignal, WidgetEventResult}, + event::{ReturnSignal, ComponentEventResult}, widgets::tui_stuff::BlockBuilder, Component, TextTable, }, @@ -391,12 +391,12 @@ impl<S> Component for SortableTextTable<S> where S: SortableColumn, { - fn handle_key_event(&mut self, event: KeyEvent) -> WidgetEventResult { + fn handle_key_event(&mut self, event: KeyEvent) -> ComponentEventResult { for (index, column) in self.table.columns.iter().enumerate() { if let Some((shortcut, _)) = *column.shortcut() { if shortcut == event { self.set_sort_index(index); - return WidgetEventResult::Signal(ReturnSignal::Update); + return ComponentEventResult::Signal(ReturnSignal::Update); } } } @@ -404,10 +404,10 @@ where self.table.scrollable.handle_key_event(event) } - fn handle_mouse_event(&mut self, event: MouseEvent) -> WidgetEventResult { + fn handle_mouse_event(&mut self, event: MouseEvent) -> ComponentEventResult { if let MouseEventKind::Down(MouseButton::Left) = event.kind { if !self.does_bounds_intersect_mouse(&event) { - return WidgetEventResult::NoRedraw; + return ComponentEventResult::NoRedraw; } // Note these are representing RELATIVE coordinates! They *need* the above intersection check for validity! @@ -419,7 +419,7 @@ where if let Some((start, end)) = column.get_x_bounds() { if x >= start && x <= end { self.set_sort_index(index); - return WidgetEventResult::Signal(ReturnSignal::Update); + return ComponentEventResult::Signal(ReturnSignal::Update); } } } diff --git a/src/app/widgets/base/text_input.rs b/src/app/widgets/base/text_input.rs index f3480c0e..47a5cb7b 100644 --- a/src/app/widgets/base/text_input.rs +++ b/src/app/widgets/base/text_input.rs @@ -13,8 +13,8 @@ use unicode_width::UnicodeWidthStr; use crate::{ app::{ event::{ + ComponentEventResult::{self}, ReturnSignal, - WidgetEventResult::{self}, }, Component, }, @@ -85,19 +85,19 @@ impl TextInput { } } - fn clear_text(&mut self) -> WidgetEventResult { + fn clear_text(&mut self) -> ComponentEventResult { if self.text.is_empty() { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } else { self.text = String::default(); self.cursor = GraphemeCursor::new(0, 0, true); self.window_index = Default::default(); self.cursor_direction = CursorDirection::Left; - WidgetEventResult::Signal(ReturnSignal::Update) + ComponentEventResult::Signal(ReturnSignal::Update) } } - fn move_word_forward(&mut self) -> WidgetEventResult { + fn move_word_forward(&mut self) -> ComponentEventResult { let current_index = self.cursor.cur_cursor(); if current_index < self.text.len() { @@ -105,30 +105,30 @@ impl TextInput { if index > 0 { self.cursor.set_cursor(index + current_index); self.cursor_direction = CursorDirection::Right; - return WidgetEventResult::Redraw; + return ComponentEventResult::Redraw; } } self.cursor.set_cursor(self.text.len()); } - WidgetEventResult::Redraw + ComponentEventResult::Redraw } - fn move_word_back(&mut self) -> WidgetEventResult { + fn move_word_back(&mut self) -> ComponentEventResult { let current_index = self.cursor.cur_cursor(); for (index, _word) in self.text[..current_index].unicode_word_indices().rev() { if index < current_index { self.cursor.set_cursor(index); self.cursor_direction = CursorDirection::Left; - return WidgetEventResult::Redraw; + return ComponentEventResult::Redraw; } } - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } - fn clear_word_from_cursor(&mut self) -> WidgetEventResult { + fn clear_word_from_cursor(&mut self) -> ComponentEventResult { // Fairly simple logic - create the word index iterator, skip the word that intersects with the current // cursor location, draw the rest, update the string. let current_index = self.cursor.cur_cursor(); @@ -147,16 +147,16 @@ impl TextInput { } if start_delete_index == current_index { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } else { self.text.drain(start_delete_index..current_index); self.cursor = GraphemeCursor::new(start_delete_index, self.text.len(), true); self.cursor_direction = CursorDirection::Left; - WidgetEventResult::Signal(ReturnSignal::Update) + ComponentEventResult::Signal(ReturnSignal::Update) } } - fn clear_previous_grapheme(&mut self) -> WidgetEventResult { + fn clear_previous_grapheme(&mut self) -> ComponentEventResult { let current_index = self.cursor.cur_cursor(); if current_index > 0 { @@ -166,13 +166,13 @@ impl TextInput { self.cursor = GraphemeCursor::new(new_index, self.text.len(), true); self.cursor_direction = CursorDirection::Left; - WidgetEventResult::Signal(ReturnSignal::Update) + ComponentEventResult::Signal(ReturnSignal::Update) } else { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } } - fn clear_current_grapheme(&mut self) -> WidgetEventResult { + fn clear_current_grapheme(&mut self) -> ComponentEventResult { let current_index = self.cursor.cur_cursor(); if current_index < self.text.len() { @@ -182,19 +182,19 @@ impl TextInput { self.cursor = GraphemeCursor::new(current_index, self.text.len(), true); self.cursor_direction = CursorDirection::Left; - WidgetEventResult::Signal(ReturnSignal::Update) + ComponentEventResult::Signal(ReturnSignal::Update) } else { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } } - fn insert_character(&mut self, c: char) -> WidgetEventResult { + fn insert_character(&mut self, c: char) -> ComponentEventResult { let current_index = self.cursor.cur_cursor(); self.text.insert(current_index, c); self.cursor = GraphemeCursor::new(current_index, self.text.len(), true); self.move_forward(); - WidgetEventResult::Signal(ReturnSignal::Update) + ComponentEventResult::Signal(ReturnSignal::Update) } /// Updates the window indexes and returns the start index. @@ -296,29 +296,29 @@ impl Component for TextInput { self.bounds = new_bounds; } - fn handle_key_event(&mut self, event: KeyEvent) -> WidgetEventResult { + fn handle_key_event(&mut self, event: KeyEvent) -> ComponentEventResult { if event.modifiers.is_empty() { match event.code { KeyCode::Left => { let original_cursor = self.cursor.cur_cursor(); if self.move_back() == original_cursor { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } else { - WidgetEventResult::Redraw + ComponentEventResult::Redraw } } KeyCode::Right => { let original_cursor = self.cursor.cur_cursor(); if self.move_forward() == original_cursor { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } else { - WidgetEventResult::Redraw + ComponentEventResult::Redraw } } KeyCode::Backspace => self.clear_previous_grapheme(), KeyCode::Delete => self.clear_current_grapheme(), KeyCode::Char(c) => self.insert_character(c), - _ => WidgetEventResult::NoRedraw, + _ => ComponentEventResult::Unhandled, } } else if let KeyModifiers::CONTROL = event.modifiers { match event.code { @@ -326,46 +326,46 @@ impl Component for TextInput { let prev_index = self.cursor.cur_cursor(); self.cursor.set_cursor(0); if self.cursor.cur_cursor() == prev_index { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } else { - WidgetEventResult::Redraw + ComponentEventResult::Redraw } } KeyCode::Char('e') => { let prev_index = self.cursor.cur_cursor(); self.cursor.set_cursor(self.text.len()); if self.cursor.cur_cursor() == prev_index { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } else { - WidgetEventResult::Redraw + ComponentEventResult::Redraw } } KeyCode::Char('u') => self.clear_text(), KeyCode::Char('w') => self.clear_word_from_cursor(), KeyCode::Char('h') => self.clear_previous_grapheme(), - _ => WidgetEventResult::NoRedraw, + _ => ComponentEventResult::Unhandled, } } else if let KeyModifiers::ALT = event.modifiers { match event.code { KeyCode::Char('b') => self.move_word_back(), KeyCode::Char('f') => self.move_word_forward(), - _ => WidgetEventResult::NoRedraw, + _ => ComponentEventResult::Unhandled, } } else { - WidgetEventResult::NoRedraw + ComponentEventResult::Unhandled } } - fn handle_mouse_event(&mut self, event: MouseEvent) -> WidgetEventResult { + fn handle_mouse_event(&mut self, event: MouseEvent) -> ComponentEventResult { // We are assuming this is within bounds... let x = event.column; let widget_x = self.bounds.x + 2; if x >= widget_x { - // TODO: do this - WidgetEventResult::Redraw + // TODO: Do this at some point after refactor + ComponentEventResult::Redraw } else { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } } } diff --git a/src/app/widgets/base/text_table.rs b/src/app/widgets/base/text_table.rs index 0814555c..e6d42001 100644 --- a/src/app/widgets/base/text_table.rs +++ b/src/app/widgets/base/text_table.rs @@ -15,7 +15,7 @@ use tui::{ use unicode_segmentation::UnicodeSegmentation; use crate::{ - app::{event::WidgetEventResult, widgets::tui_stuff::BlockBuilder, Component, Scrollable}, + app::{event::ComponentEventResult, widgets::tui_stuff::BlockBuilder, Component, Scrollable}, canvas::Painter, constants::TABLE_GAP_HEIGHT_LIMIT, }; @@ -130,7 +130,7 @@ where pub show_gap: bool, /// The bounding box of the [`TextTable`]. - pub bounds: Rect, // TODO: Consider moving bounds to something else??? + pub bounds: Rect, // TODO: Consider moving bounds to something else? /// The bounds including the border, if there is one. pub border_bounds: Rect, @@ -492,19 +492,19 @@ impl<C> Component for TextTable<C> where C: TableColumn, { - fn handle_key_event(&mut self, event: KeyEvent) -> WidgetEventResult { + fn handle_key_event(&mut self, event: KeyEvent) -> ComponentEventResult { if self.selectable { self.scrollable.handle_key_event(event) } else { - WidgetEventResult::NoRedraw + ComponentEventResult::Unhandled } } - fn handle_mouse_event(&mut self, event: MouseEvent) -> WidgetEventResult { + fn handle_mouse_event(&mut self, event: MouseEvent) -> ComponentEventResult { if self.selectable { self.scrollable.handle_mouse_event(event) } else { - WidgetEventResult::NoRedraw + ComponentEventResult::Unhandled } } diff --git a/src/app/widgets/base/time_graph.rs b/src/app/widgets/base/time_graph.rs index 94e5f847..81ca9e15 100644 --- a/src/app/widgets/base/time_graph.rs +++ b/src/app/widgets/base/time_graph.rs @@ -15,7 +15,7 @@ use tui::{ use crate::{ app::{ - event::WidgetEventResult, + event::ComponentEventResult, widgets::tui_stuff::{ custom_legend_chart::{Axis, Dataset}, TimeChart, @@ -160,62 +160,62 @@ impl TimeGraph { } /// Handles a char `c`. - fn handle_char(&mut self, c: char) -> WidgetEventResult { + fn handle_char(&mut self, c: char) -> ComponentEventResult { match c { '-' => self.zoom_out(), '+' => self.zoom_in(), '=' => self.reset_zoom(), - _ => WidgetEventResult::NoRedraw, + _ => ComponentEventResult::NoRedraw, } } - fn zoom_in(&mut self) -> WidgetEventResult { + fn zoom_in(&mut self) -> ComponentEventResult { let new_time = self.current_display_time.saturating_sub(self.time_interval); if self.current_display_time == new_time { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } else if new_time >= self.min_duration { self.current_display_time = new_time; self.autohide_timer.start_display_timer(); - WidgetEventResult::Redraw + ComponentEventResult::Redraw } else if new_time != self.min_duration { self.current_display_time = self.min_duration; self.autohide_timer.start_display_timer(); - WidgetEventResult::Redraw + ComponentEventResult::Redraw } else { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } } - fn zoom_out(&mut self) -> WidgetEventResult { + fn zoom_out(&mut self) -> ComponentEventResult { let new_time = self.current_display_time + self.time_interval; if self.current_display_time == new_time { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } else if new_time <= self.max_duration { self.current_display_time = new_time; self.autohide_timer.start_display_timer(); - WidgetEventResult::Redraw + ComponentEventResult::Redraw } else if new_time != self.max_duration { self.current_display_time = self.max_duration; self.autohide_timer.start_display_timer(); - WidgetEventResult::Redraw + ComponentEventResult::Redraw } else { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } } - fn reset_zoom(&mut self) -> WidgetEventResult { + fn reset_zoom(&mut self) -> ComponentEventResult { if self.current_display_time == self.default_time_value { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } else { self.current_display_time = self.default_time_value; self.autohide_timer.start_display_timer(); - WidgetEventResult::Redraw + ComponentEventResult::Redraw } } @@ -307,24 +307,24 @@ impl TimeGraph { } impl Component for TimeGraph { - fn handle_key_event(&mut self, event: KeyEvent) -> WidgetEventResult { + fn handle_key_event(&mut self, event: KeyEvent) -> ComponentEventResult { use crossterm::event::KeyCode::Char; if event.modifiers == KeyModifiers::NONE || event.modifiers == KeyModifiers::SHIFT { match event.code { Char(c) => self.handle_char(c), - _ => WidgetEventResult::NoRedraw, + _ => ComponentEventResult::Unhandled, } } else { - WidgetEventResult::NoRedraw + ComponentEventResult::Unhandled } } - fn handle_mouse_event(&mut self, event: MouseEvent) -> WidgetEventResult { + fn handle_mouse_event(&mut self, event: MouseEvent) -> ComponentEventResult { match event.kind { MouseEventKind::ScrollDown => self.zoom_out(), MouseEventKind::ScrollUp => self.zoom_in(), - _ => WidgetEventResult::NoRedraw, + _ => ComponentEventResult::Unhandled, } } diff --git a/src/app/widgets/bottom_widgets/basic_mem.rs b/src/app/widgets/bottom_widgets/basic_mem.rs index d70d0e04..3658ee7c 100644 --- a/src/app/widgets/bottom_widgets/basic_mem.rs +++ b/src/app/widgets/bottom_widgets/basic_mem.rs @@ -8,7 +8,8 @@ use tui::{ use crate::{ app::{ - event::WidgetEventResult, widgets::tui_stuff::PipeGauge, Component, DataCollection, Widget, + event::ComponentEventResult, widgets::tui_stuff::PipeGauge, Component, DataCollection, + Widget, }, canvas::Painter, constants::SIDE_BORDERS, @@ -54,13 +55,13 @@ impl Component for BasicMem { self.bounds = new_bounds; } - fn handle_key_event(&mut self, event: KeyEvent) -> WidgetEventResult { + fn handle_key_event(&mut self, event: KeyEvent) -> ComponentEventResult { match event.code { - KeyCode::Char('%') if event.modifiers.is_empty() => { + KeyCode::Char('%') => { self.use_percent = !self.use_percent; - WidgetEventResult::Redraw + ComponentEventResult::Redraw } - _ => WidgetEventResult::NoRedraw, + _ => ComponentEventResult::Unhandled, } } } diff --git a/src/app/widgets/bottom_widgets/battery.rs b/src/app/widgets/bottom_widgets/battery.rs index 1d0c9c8b..8c1d0721 100644 --- a/src/app/widgets/bottom_widgets/battery.rs +++ b/src/app/widgets/bottom_widgets/battery.rs @@ -14,7 +14,7 @@ use tui::{ use crate::{ app::{ - data_farmer::DataCollection, does_bound_intersect_coordinate, event::WidgetEventResult, + data_farmer::DataCollection, does_bound_intersect_coordinate, event::ComponentEventResult, widgets::tui_stuff::PipeGauge, Component, Widget, }, canvas::Painter, @@ -114,44 +114,44 @@ impl Component for BatteryTable { self.bounds = new_bounds; } - fn handle_key_event(&mut self, event: KeyEvent) -> WidgetEventResult { + fn handle_key_event(&mut self, event: KeyEvent) -> ComponentEventResult { if event.modifiers.is_empty() { match event.code { KeyCode::Left => { let current_index = self.selected_index; self.decrement_index(); if current_index == self.selected_index { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } else { - WidgetEventResult::Redraw + ComponentEventResult::Redraw } } KeyCode::Right => { let current_index = self.selected_index; self.increment_index(); if current_index == self.selected_index { - WidgetEventResult::NoRedraw + ComponentEventResult::NoRedraw } else { - WidgetEventResult::Redraw + ComponentEventResult::Redraw } } - _ => WidgetEventResult::NoRedraw, + _ => ComponentEventResult::Unhandled, } } else { - WidgetEventResult::NoRedraw + ComponentEventResult::Unhandled } } - fn handle_mouse_event(&mut self, event: MouseEvent) -> WidgetEventResult { + fn handle_mouse_event(&mut self, event: MouseEvent) -> ComponentEventResult { for (itx, bound) in self.tab_bounds.iter().enumerate() { if does_bound_intersect_coordinate(event.column, event.row, *bound) && itx < self.battery_data.len() { self.selected_index = itx; - return WidgetEventResult::Redraw; + return ComponentEventResult::Redraw; } } - WidgetEventResult::NoRedraw + ComponentEventResult::Unhandled } } @@ -183,7 +183,7 @@ impl Widget for BatteryTable { .block() .selected(selected) .borders(self.block_border) - .expanded(expanded) + .show_esc(expanded) .build(painter, area); let inner_area = block.inner(area); diff --git a/src/app/widgets/bottom_widgets/carousel.rs b/src/app/widgets/bottom_widgets/carousel.rs index 9c8356fb..92d3614c 100644 --- a/src/app/widgets/bottom_widgets/carousel.rs +++ b/src/app/widgets/bottom_widgets/carousel.rs @@ -12,7 +12,7 @@ use tui::{ use crate::{ app::{ - does_bound_intersect_coordinate, event::WidgetEventResult, Component, SelectableType, + does_bound_intersect_coordinate, event::ComponentEventResult, Component, SelectableType, Widget, }, canvas::Painter, @@ -164,7 +164,7 @@ impl Component for Carousel { self.bounds = new_bounds; } - fn handle_mouse_event(&mut self, event: MouseEvent) -> WidgetEventResult { + fn handle_mouse_event(&mut self, event: MouseEvent) -> ComponentEventResult { match event.kind { crossterm::event::MouseEventKind::Down(crossterm::event::MouseButton::Left) => { let x = event.column; @@ -172,15 +172,15 @@ impl Component for Carousel { if does_bound_intersect_coordinate(x, y, self.left_button_bounds) { self.decrement_index(); - WidgetEventResult::Redraw + ComponentEventResult::Redraw } else if does_bound_intersect_coordinate(x, y, self.right_button_bounds) { self.increment_index(); - WidgetEventResult::Redraw + ComponentEventResult::Redraw } else { - WidgetEventResult::NoRedraw + ComponentEventResult::Unhandled } } - _ => WidgetEventResult::NoRedraw, + _ => ComponentEventResult::Unhandled, } } } diff --git a/src/app/widgets/bottom_widgets/cpu.rs b/src/app/widgets/bottom_widgets/cpu.rs index 9397a7e1..6e5e18a5 100644 --- a/src/app/widgets/bottom_widgets/cpu.rs +++ b/src/app/widgets/bottom_widgets/cpu.rs @@ -9,7 +9,7 @@ use tui::{ use crate::{ app::{ - event::{SelectionAction, WidgetEventResult}, + event::{ComponentEventResult, SelectionAction}, text_table::SimpleColumn, time_graph::TimeGraphData, AppConfigFields, AppScrollWidgetState, CanvasTableWidthState, Component, DataCollection, @@ -118,21 +118,21 @@ impl CpuGraph { } impl Co |