Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sorting by any column #183

Merged
merged 8 commits into from
Aug 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add widget size adaptation to sort widget
  • Loading branch information
ClementTsang committed Aug 15, 2020
commit b2b2c2bb3ae1981374bf8ac0456e7a184d8c78f6
2 changes: 2 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ impl App {
.get_mut_widget_state(self.current_widget.widget_id - 2)
{
if current_proc_state.is_sort_open {
current_proc_state.columns.current_scroll_position =
current_proc_state.columns.backup_prev_scroll_position;
current_proc_state.is_sort_open = false;
self.move_widget_selection(&WidgetDirection::Right);
return;
Expand Down
14 changes: 12 additions & 2 deletions src/app/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ pub struct ProcColumn {
pub column_state: TableState,
pub scroll_direction: ScrollDirection,
pub current_scroll_position: usize,
pub previous_scroll_position: usize,
pub backup_prev_scroll_position: usize,
}

impl Default for ProcColumn {
Expand Down Expand Up @@ -241,6 +243,8 @@ impl Default for ProcColumn {
column_state: TableState::default(),
scroll_direction: ScrollDirection::default(),
current_scroll_position: 0,
previous_scroll_position: 0,
backup_prev_scroll_position: 0,
}
}
}
Expand All @@ -261,12 +265,18 @@ impl ProcColumn {

pub fn set_to_sorted_index(&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!
for (itx, column) in self.ordered_columns.iter().enumerate() {
let mut true_index = 0;
for column in &self.ordered_columns {
if *column == *proc_sorting_type {
self.current_scroll_position = itx;
break;
}
if self.column_mapping.get(column).unwrap().enabled {
true_index += 1;
}
}

self.current_scroll_position = true_index;
self.backup_prev_scroll_position = self.previous_scroll_position;
}

pub fn get_column_headers(
Expand Down
32 changes: 24 additions & 8 deletions src/canvas/widgets/process_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ impl ProcessTableWidget for Painter {
proc_widget_state.process_sorting_reverse,
);

// debug!("PH: {:?}", process_headers);

let process_headers_lens: Vec<usize> = process_headers
.iter()
.map(|entry| entry.len())
Expand Down Expand Up @@ -514,13 +512,12 @@ impl ProcessTableWidget for Painter {
.ordered_columns
.iter()
.filter(|column_type| {
let mapping = proc_widget_state
proc_widget_state
.columns
.column_mapping
.get(&column_type)
.unwrap();

mapping.enabled
.unwrap()
.enabled
})
.enumerate()
.map(|(itx, column_type)| {
Expand All @@ -534,9 +531,28 @@ impl ProcessTableWidget for Painter {
}
})
.collect::<Vec<_>>();
let sort_options = sort_string

let position = get_start_position(
usize::from(draw_loc.height.saturating_sub(self.table_height_offset)),
&proc_widget_state.columns.scroll_direction,
&mut proc_widget_state.columns.previous_scroll_position,
current_scroll_position,
app_state.is_force_redraw,
);

// Sanity check
let start_position = if position >= sort_string.len() {
sort_string.len().saturating_sub(1)
} else {
position
};

let sliced_vec = &sort_string[start_position..];

let sort_options = sliced_vec
.into_iter()
.map(|(column, style)| Row::StyledData(vec![column].into_iter(), style));
.map(|(column, style)| Row::StyledData(vec![column].into_iter(), *style));

let column_state = &mut proc_widget_state.columns.column_state;
let current_border_style = if proc_widget_state
.process_search_state
Expand Down