diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2020-08-15 17:35:49 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-15 20:35:49 -0400 |
commit | f3897f0538f90c682b96bc340c3c05e80be10b2d (patch) | |
tree | f24673d4d5702e48b9d3d1889f7498c97ac238a1 /src/canvas/widgets/basic_table_arrows.rs | |
parent | 84f63f2f8306382dbf5cab819589161bf0b7c093 (diff) |
feature: Allow sorting by any column
This feature allows any column to be sortable.
This also adds:
- Inverting sort for current column with `I`
- Invoking a sort widget with `s` or `F6`. Close with same key or esc.
And:
- A bugfix in regards the basic menu and battery widget
- A lot of refactoring
Diffstat (limited to 'src/canvas/widgets/basic_table_arrows.rs')
-rw-r--r-- | src/canvas/widgets/basic_table_arrows.rs | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/canvas/widgets/basic_table_arrows.rs b/src/canvas/widgets/basic_table_arrows.rs index 5e5c306c..18beab83 100644 --- a/src/canvas/widgets/basic_table_arrows.rs +++ b/src/canvas/widgets/basic_table_arrows.rs @@ -24,6 +24,15 @@ impl BasicTableArrows for Painter { fn draw_basic_table_arrows<B: Backend>( &self, f: &mut Frame<'_, B>, app_state: &App, draw_loc: Rect, current_table: &BottomWidget, ) { + let current_table = if let BottomWidgetType::ProcSort = current_table.widget_type { + current_table + .right_neighbour + .map(|id| app_state.widget_map.get(&id).unwrap()) + .unwrap() + } else { + current_table + }; + // Effectively a paragraph with a ton of spacing let (left_table, right_table) = ( { @@ -33,7 +42,21 @@ impl BasicTableArrows for Painter { app_state .widget_map .get(&left_widget_id) - .map(|left_widget| &left_widget.widget_type) + .map(|left_widget| { + if left_widget.widget_type == BottomWidgetType::ProcSort { + left_widget + .left_neighbour + .map(|left_left_widget_id| { + app_state.widget_map.get(&left_left_widget_id).map( + |left_left_widget| &left_left_widget.widget_type, + ) + }) + .unwrap_or_else(|| Some(&BottomWidgetType::Temp)) + .unwrap_or_else(|| &BottomWidgetType::Temp) + } else { + &left_widget.widget_type + } + }) .unwrap_or_else(|| &BottomWidgetType::Temp) }) .unwrap_or_else(|| &BottomWidgetType::Temp) @@ -45,7 +68,23 @@ impl BasicTableArrows for Painter { app_state .widget_map .get(&right_widget_id) - .map(|right_widget| &right_widget.widget_type) + .map(|right_widget| { + if right_widget.widget_type == BottomWidgetType::ProcSort { + right_widget + .right_neighbour + .map(|right_right_widget_id| { + app_state.widget_map.get(&right_right_widget_id).map( + |right_right_widget| { + &right_right_widget.widget_type + }, + ) + }) + .unwrap_or_else(|| Some(&BottomWidgetType::Disk)) + .unwrap_or_else(|| &BottomWidgetType::Disk) + } else { + &right_widget.widget_type + } + }) .unwrap_or_else(|| &BottomWidgetType::Disk) }) .unwrap_or_else(|| &BottomWidgetType::Disk) |