diff options
author | ClementTsang <cjhtsang@uwaterloo.ca> | 2020-04-29 23:43:49 -0400 |
---|---|---|
committer | ClementTsang <cjhtsang@uwaterloo.ca> | 2020-04-29 23:43:49 -0400 |
commit | edd5cff12daaa1834f391bd189e692e4e9a7ecdd (patch) | |
tree | c43464e65299b073327967a1b43742b8f32fcb97 /src/canvas/widgets | |
parent | dacf8b1abb4f723bce3fb235c08ea1d767c6d048 (diff) |
change: merge search and process widgets together
Diffstat (limited to 'src/canvas/widgets')
-rw-r--r-- | src/canvas/widgets/process_table.rs | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/canvas/widgets/process_table.rs b/src/canvas/widgets/process_table.rs index 40803f9b..651c5d2f 100644 --- a/src/canvas/widgets/process_table.rs +++ b/src/canvas/widgets/process_table.rs @@ -44,11 +44,11 @@ impl ProcessTableWidget for Painter { widget_id: u64, ) { if let Some(process_widget_state) = app_state.proc_state.widget_states.get(&widget_id) { - let search_width = if draw_border { 5 } else { 3 }; + let search_height = if draw_border { 4 } else { 3 }; if process_widget_state.is_search_enabled() { let processes_chunk = Layout::default() .direction(Direction::Vertical) - .constraints([Constraint::Min(0), Constraint::Length(search_width)].as_ref()) + .constraints([Constraint::Min(0), Constraint::Length(search_height)].as_ref()) .split(draw_loc); self.draw_processes_table(f, app_state, processes_chunk[0], draw_border, widget_id); @@ -85,6 +85,9 @@ impl ProcessTableWidget for Painter { // do so by hiding some elements! let num_rows = max(0, i64::from(draw_loc.height) - self.table_height_offset) as u64; let is_on_widget = widget_id == app_state.current_widget.widget_id; + let is_on_processes = + is_on_widget || (widget_id + 1 == app_state.current_widget.widget_id); + let is_search_enabled = proc_widget_state.is_search_enabled(); let position = get_start_position( num_rows, @@ -212,7 +215,7 @@ impl ProcessTableWidget for Painter { String::default() }; - let (border_and_title_style, highlight_style) = if is_on_widget { + let (border_and_title_style, highlight_style) = if is_on_processes { ( self.colours.highlighted_border_style, self.colours.currently_selected_text_style, @@ -229,7 +232,11 @@ impl ProcessTableWidget for Painter { } else { self.colours.widget_title_style }) - .borders(Borders::ALL) + .borders(if is_search_enabled { + *TOP_LEFT_RIGHT + } else { + Borders::ALL + }) .border_style(border_and_title_style) } else if is_on_widget { Block::default() @@ -338,6 +345,8 @@ impl ProcessTableWidget for Painter { let chosen_text = get_prompt_text(&proc_widget_state); let is_on_widget = widget_id == app_state.current_widget.widget_id; + let is_on_processes = + is_on_widget || (widget_id - 1 == app_state.current_widget.widget_id); let num_columns = draw_loc.width as usize; let small_mode = num_columns < 70; let search_title: &str = if !small_mode { @@ -358,6 +367,7 @@ impl ProcessTableWidget for Painter { let cursor_position = proc_widget_state.get_cursor_position(); let current_cursor_position = proc_widget_state.get_char_cursor_position(); + let is_search_enabled = proc_widget_state.is_search_enabled(); let start_position: usize = get_search_start_position( num_columns - num_chars_for_text - 5, @@ -452,29 +462,19 @@ impl ProcessTableWidget for Painter { .is_invalid_search { *INVALID_REGEX_STYLE - } else if is_on_widget { + } else if is_on_processes { self.colours.highlighted_border_style } else { self.colours.border_style }; - let title = if draw_border { - const TITLE_BASE: &str = " Esc to close "; - - let repeat_num = max( - 0, - draw_loc.width as i32 - TITLE_BASE.chars().count() as i32 - 2, - ); - format!("{} Esc to close ", "─".repeat(repeat_num as usize)) - } else { - String::new() - }; - let process_search_block = if draw_border { Block::default() - .title(&title) - .title_style(current_border_style) - .borders(Borders::ALL) + .borders(if is_search_enabled { + *BOTTOM_LEFT_RIGHT + } else { + Borders::ALL + }) .border_style(current_border_style) } else if is_on_widget { Block::default() |