summaryrefslogtreecommitdiffstats
path: root/src/app
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2021-02-18 17:10:51 -0500
committerGitHub <noreply@github.com>2021-02-18 17:10:51 -0500
commit4db39da75e00e45cc50c8143ff5eba3d92525dbd (patch)
treedbaab3c59fec5001e48621a13c2301936ae7b056 /src/app
parentce9818d93560fbe8d439d20f8c7a3ec6e082c8b3 (diff)
feature: Add mouse support to sorting columns (#413)
Adds mouse support for sorting columns within the process widget. You can now click on the column header to sort (or invert the sort).
Diffstat (limited to 'src/app')
-rw-r--r--src/app/states.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/app/states.rs b/src/app/states.rs
index d30adcc4..37fbd8d1 100644
--- a/src/app/states.rs
+++ b/src/app/states.rs
@@ -178,6 +178,10 @@ pub struct ColumnInfo {
pub struct ProcColumn {
pub ordered_columns: Vec<ProcessSorting>,
+ /// The y location of headers. Since they're all aligned, it's just one value.
+ pub column_header_y_loc: Option<u16>,
+ /// The x start and end bounds for each header.
+ pub column_header_x_locs: Option<Vec<(u16, u16)>>,
pub column_mapping: HashMap<ProcessSorting, ColumnInfo>,
pub longest_header_len: u16,
pub column_state: TableState,
@@ -294,6 +298,8 @@ impl Default for ProcColumn {
current_scroll_position: 0,
previous_scroll_position: 0,
backup_prev_scroll_position: 0,
+ column_header_y_loc: None,
+ column_header_x_locs: None,
}
}
}
@@ -335,8 +341,8 @@ impl ProcColumn {
.sum()
}
- /// ALWAYS call this when opening the sorted window.
- pub fn set_to_sorted_index(&mut self, proc_sorting_type: &ProcessSorting) {
+ /// NOTE: ALWAYS call this when opening the sorted window.
+ pub fn set_to_sorted_index_from_type(&mut self, proc_sorting_type: &ProcessSorting) {
// TODO [Custom Columns]: If we add custom columns, this may be needed! Since column indices will change, this runs the risk of OOB. So, when you change columns, CALL THIS AND ADAPT!
let mut true_index = 0;
for column in &self.ordered_columns {
@@ -352,6 +358,12 @@ impl ProcColumn {
self.backup_prev_scroll_position = self.previous_scroll_position;
}
+ /// This function sets the scroll position based on the index.
+ pub fn set_to_sorted_index_from_visual_index(&mut self, visual_index: usize) {
+ self.current_scroll_position = visual_index;
+ self.backup_prev_scroll_position = self.previous_scroll_position;
+ }
+
pub fn get_column_headers(
&self, proc_sorting_type: &ProcessSorting, sort_reverse: bool,
) -> Vec<String> {
@@ -432,7 +444,7 @@ impl ProcWidgetState {
// TODO: If we add customizable columns, this should pull from config
let mut columns = ProcColumn::default();
- columns.set_to_sorted_index(&process_sorting_type);
+ columns.set_to_sorted_index_from_type(&process_sorting_type);
if is_grouped {
// Normally defaults to showing by PID, toggle count on instead.
columns.toggle(&ProcessSorting::Count);