From cd9be0f5af3432c36077d1f2cb9d565dbb3e0842 Mon Sep 17 00:00:00 2001 From: ClementTsang <34804052+ClementTsang@users.noreply.github.com> Date: Fri, 3 Oct 2025 03:35:15 -0400 Subject: [PATCH] fix sorttable --- src/app.rs | 9 +++++---- src/canvas/widgets/process_table.rs | 2 +- src/widgets/process_table.rs | 21 +++++++++++---------- src/widgets/process_table/sort_table.rs | 2 +- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/app.rs b/src/app.rs index 8caceb77..d4bf53d6 100644 --- a/src/app.rs +++ b/src/app.rs @@ -325,7 +325,7 @@ impl App { // If the sort is now open, move left. Otherwise, if the proc sort was selected, // force move right. if pws.is_sort_open { - pws.sort_table.set_position(pws.table.sort_index()); + pws.sort_table.0.set_position(pws.table.sort_index()); self.move_widget_selection(&WidgetDirection::Left); } else if let BottomWidgetType::ProcSort = self.current_widget.widget_type { self.move_widget_selection(&WidgetDirection::Right); @@ -1760,7 +1760,7 @@ impl App { .proc_state .get_mut_widget_state(self.current_widget.widget_id - 2) { - proc_widget_state.sort_table.scroll_to_first(); + proc_widget_state.sort_table.0.scroll_to_first(); } } BottomWidgetType::Temp => { @@ -1819,7 +1819,7 @@ impl App { .proc_state .get_mut_widget_state(self.current_widget.widget_id - 2) { - proc_widget_state.sort_table.scroll_to_last(); + proc_widget_state.sort_table.0.scroll_to_last(); } } BottomWidgetType::Temp => { @@ -1893,6 +1893,7 @@ impl App { { proc_widget_state .sort_table + .0 .increment_position(num_to_change_by); } } @@ -2414,7 +2415,7 @@ impl App { .get_widget_state(self.current_widget.widget_id - 2) { if let Some(visual_index) = - proc_widget_state.sort_table.ratatui_selected() + proc_widget_state.sort_table.0.ratatui_selected() { self.change_process_sort_position( offset_clicked_entry as i64 - visual_index as i64, diff --git a/src/canvas/widgets/process_table.rs b/src/canvas/widgets/process_table.rs index 961df4a7..451cf6d9 100644 --- a/src/canvas/widgets/process_table.rs +++ b/src/canvas/widgets/process_table.rs @@ -317,7 +317,7 @@ impl Painter { selection_state: SelectionState::new(app_state.is_expanded, is_on_widget), }; - pws.sort_table.draw( + pws.sort_table.0.draw( f, &draw_info, app_state.widget_map.get_mut(&widget_id), diff --git a/src/widgets/process_table.rs b/src/widgets/process_table.rs index ebbed720..0e127bdf 100644 --- a/src/widgets/process_table.rs +++ b/src/widgets/process_table.rs @@ -19,11 +19,13 @@ use crate::{ data::{ProcessData, StoredData}, }, canvas::components::data_table::{ - Column, ColumnHeader, ColumnWidthBounds, DataTableComponent, DataTableColumn, DataTableProps, - DataTableStyling, SortColumn, SortDataTable, SortDataTableProps, SortOrder, SortsRow, + Column, ColumnHeader, ColumnWidthBounds, DataTableColumn, DataTableComponent, + DataTableProps, DataTableStyling, SortColumn, SortDataTable, SortDataTableProps, SortOrder, + SortsRow, }, collection::processes::{Pid, ProcessHarvest}, options::config::style::Styles, + widgets::process_table::sort_table::SortTable, }; /// ProcessSearchState only deals with process' search's current settings and @@ -142,7 +144,6 @@ pub(crate) enum ProcWidgetMode { } type ProcessTable = SortDataTable; -type SortTable = DataTableComponent, SortTableColumn>; type StringPidMap = HashMap>; fn make_column(column: ProcColumn) -> SortColumn { @@ -251,7 +252,7 @@ impl ProcWidgetState { }; let styling = DataTableStyling::from_palette(palette); - DataTableComponent::new(COLUMNS, props, styling) + SortTable(DataTableComponent::new(COLUMNS, props, styling)) } fn new_process_table( @@ -439,7 +440,7 @@ impl ProcWidgetState { #[cfg(target_os = "linux")] hide_k_threads: config.hide_k_threads, }; - table.sort_table.set_data(table.column_text()); + table.sort_table.0.set_data(table.column_text()); table } @@ -870,7 +871,7 @@ impl ProcWidgetState { _ => unreachable!(), } - self.sort_table.set_data(self.column_text()); + self.sort_table.0.set_data(self.column_text()); self.force_data_update(); } } @@ -887,7 +888,7 @@ impl ProcWidgetState { _ => unreachable!(), } - self.sort_table.set_data(self.column_text()); + self.sort_table.0.set_data(self.column_text()); self.force_data_update(); } } @@ -997,7 +998,7 @@ impl ProcWidgetState { } _ => unreachable!(), } - self.sort_table.set_data(self.column_text()); + self.sort_table.0.set_data(self.column_text()); self.force_rerender_and_update(); } } @@ -1042,7 +1043,7 @@ impl ProcWidgetState { _ => unreachable!(), } - self.sort_table.set_data(self.column_text()); + self.sort_table.0.set_data(self.column_text()); self.force_rerender_and_update(); } } @@ -1125,7 +1126,7 @@ impl ProcWidgetState { /// Sets the [`ProcWidgetState`]'s current sort index to whatever was in the /// sort table if possible, then closes the sort table. pub(crate) fn use_sort_table_value(&mut self) { - self.table.set_sort_index(self.sort_table.current_index()); + self.table.set_sort_index(self.sort_table.0.current_index()); self.is_sort_open = false; self.force_rerender_and_update(); diff --git a/src/widgets/process_table/sort_table.rs b/src/widgets/process_table/sort_table.rs index 2bef6932..2c93c381 100644 --- a/src/widgets/process_table/sort_table.rs +++ b/src/widgets/process_table/sort_table.rs @@ -4,7 +4,7 @@ use crate::canvas::components::data_table::{ ColumnHeader, DataTable, DataTableColumn, DataTableComponent, DataToCell, }; -pub struct SortTable(DataTableComponent, SortTableColumn>); +pub struct SortTable(pub DataTableComponent, SortTableColumn>); impl DataTable<&'static str> for SortTable { type HeaderType = SortTableColumn;