summaryrefslogtreecommitdiffstats
path: root/src/canvas
diff options
context:
space:
mode:
Diffstat (limited to 'src/canvas')
-rw-r--r--src/canvas/dialogs/filter_dialog.rs0
-rw-r--r--src/canvas/dialogs/help_dialog.rs144
-rw-r--r--src/canvas/drawing_utils.rs9
-rw-r--r--src/canvas/widgets/cpu_graph.rs2
-rw-r--r--src/canvas/widgets/disk_table.rs2
-rw-r--r--src/canvas/widgets/process_table.rs4
-rw-r--r--src/canvas/widgets/temp_table.rs2
7 files changed, 126 insertions, 37 deletions
diff --git a/src/canvas/dialogs/filter_dialog.rs b/src/canvas/dialogs/filter_dialog.rs
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/canvas/dialogs/filter_dialog.rs
diff --git a/src/canvas/dialogs/help_dialog.rs b/src/canvas/dialogs/help_dialog.rs
index 8dbca876..70492ae9 100644
--- a/src/canvas/dialogs/help_dialog.rs
+++ b/src/canvas/dialogs/help_dialog.rs
@@ -1,4 +1,5 @@
use std::cmp::max;
+use unicode_width::UnicodeWidthStr;
use tui::{
backend::Backend,
@@ -7,12 +8,9 @@ use tui::{
widgets::{Block, Borders, Paragraph},
};
-use crate::{
- app::{App, AppHelpCategory},
- canvas::Painter,
-};
+use crate::{app::App, canvas::Painter, constants};
-const HELP_BASE: &str = " Help ── 1: General ─── 2: Processes ─── 3: Search ─── Esc to close ";
+const HELP_BASE: &str = " Help ── Esc to close ";
pub trait HelpDialog {
fn draw_help_dialog<B: Backend>(
@@ -28,31 +26,121 @@ impl HelpDialog for Painter {
0,
draw_loc.width as i32 - HELP_BASE.chars().count() as i32 - 2,
);
- let help_title = format!(
- " Help ─{}─ 1: General ─── 2: Processes ─── 3: Search ─── Esc to close ",
- "─".repeat(repeat_num as usize)
- );
+ let help_title = format!(" Help ─{}─ Esc to close ", "─".repeat(repeat_num as usize));
+
+ if app_state.is_force_redraw {
+ // We must also recalculate how many lines are wrapping to properly get scrolling to work on
+ // small terminal sizes... oh joy.
+
+ // TODO: Make this more automated and easier to add.
+
+ let mut overflow_buffer = 0;
+ let paragraph_width = draw_loc.width - 2;
+ constants::HELP_CONTENTS_TEXT.iter().for_each(|text_line| {
+ overflow_buffer +=
+ UnicodeWidthStr::width(*text_line).saturating_sub(1) as u16 / paragraph_width;
+ });
+
+ // General
+ app_state.help_dialog_state.general_index =
+ constants::HELP_CONTENTS_TEXT.len() as u16 + 1 + overflow_buffer;
+ constants::GENERAL_HELP_TEXT.iter().for_each(|text_line| {
+ overflow_buffer +=
+ UnicodeWidthStr::width(*text_line).saturating_sub(1) as u16 / paragraph_width;
+ });
+
+ // CPU
+ app_state.help_dialog_state.cpu_index =
+ (constants::HELP_CONTENTS_TEXT.len() + constants::GENERAL_HELP_TEXT.len()) as u16
+ + 2
+ + overflow_buffer;
+ constants::CPU_HELP_TEXT.iter().for_each(|text_line| {
+ overflow_buffer +=
+ UnicodeWidthStr::width(*text_line).saturating_sub(1) as u16 / paragraph_width;
+ });
+
+ // Processes
+ app_state.help_dialog_state.process_index = (constants::HELP_CONTENTS_TEXT.len()
+ + constants::GENERAL_HELP_TEXT.len()
+ + constants::CPU_HELP_TEXT.len())
+ as u16
+ + 3
+ + overflow_buffer;
+ constants::PROCESS_HELP_TEXT.iter().for_each(|text_line| {
+ overflow_buffer +=
+ UnicodeWidthStr::width(*text_line).saturating_sub(1) as u16 / paragraph_width;
+ });
+
+ // Search
+ app_state.help_dialog_state.search_index = (constants::HELP_CONTENTS_TEXT.len()
+ + constants::GENERAL_HELP_TEXT.len()
+ + constants::CPU_HELP_TEXT.len()
+ + constants::PROCESS_HELP_TEXT.len())
+ as u16
+ + 4
+ + overflow_buffer;
+ constants::SEARCH_HELP_TEXT.iter().for_each(|text_line| {
+ overflow_buffer +=
+ UnicodeWidthStr::width(*text_line).saturating_sub(1) as u16 / paragraph_width;
+ });
+
+ // Battery
+ app_state.help_dialog_state.battery_index = (constants::HELP_CONTENTS_TEXT.len()
+ + constants::GENERAL_HELP_TEXT.len()
+ + constants::CPU_HELP_TEXT.len()
+ + constants::PROCESS_HELP_TEXT.len()
+ + constants::SEARCH_HELP_TEXT.len())
+ as u16
+ + 5
+ + overflow_buffer;
+ constants::BATTERY_HELP_TEXT.iter().for_each(|text_line| {
+ overflow_buffer +=
+ UnicodeWidthStr::width(*text_line).saturating_sub(1) as u16 / paragraph_width;
+ });
+
+ app_state.help_dialog_state.scroll_state.max_scroll_index =
+ (self.styled_help_text.len() as u16
+ + (constants::NUM_CATEGORIES - 3)
+ + overflow_buffer)
+ .saturating_sub(draw_loc.height);
+
+ // Fix if over-scrolled
+ if app_state
+ .help_dialog_state
+ .scroll_state
+ .current_scroll_index
+ >= app_state.help_dialog_state.scroll_state.max_scroll_index
+ {
+ app_state
+ .help_dialog_state
+ .scroll_state
+ .current_scroll_index = app_state
+ .help_dialog_state
+ .scroll_state
+ .max_scroll_index
+ .saturating_sub(1);
+ }
+ }
f.render_widget(
- Paragraph::new(
- match app_state.help_dialog_state.current_category {
- AppHelpCategory::General => &self.styled_general_help_text,
- AppHelpCategory::Process => &self.styled_process_help_text,
- AppHelpCategory::Search => &self.styled_search_help_text,
- }
- .iter(),
- )
- .block(
- Block::default()
- .title(&help_title)
- .title_style(self.colours.border_style)
- .style(self.colours.border_style)
- .borders(Borders::ALL)
- .border_style(self.colours.border_style),
- )
- .style(self.colours.text_style)
- .alignment(Alignment::Left)
- .wrap(true),
+ Paragraph::new(self.styled_help_text.iter())
+ .block(
+ Block::default()
+ .title(&help_title)
+ .title_style(self.colours.border_style)
+ .style(self.colours.border_style)
+ .borders(Borders::ALL)
+ .border_style(self.colours.border_style),
+ )
+ .style(self.colours.text_style)
+ .alignment(Alignment::Left)
+ .wrap(true)
+ .scroll(
+ app_state
+ .help_dialog_state
+ .scroll_state
+ .current_scroll_index,
+ ),
draw_loc,
);
}
diff --git a/src/canvas/drawing_utils.rs b/src/canvas/drawing_utils.rs
index 6c008724..2281e503 100644
--- a/src/canvas/drawing_utils.rs
+++ b/src/canvas/drawing_utils.rs
@@ -1,6 +1,7 @@
use crate::app;
use itertools::izip;
+// TODO: Reverse intrinsic?
/// A somewhat jury-rigged solution to simulate a variable intrinsic layout for
/// table widths. Note that this will do one main pass to try to properly
/// allocate widths. This will thus potentially cut off latter elements
@@ -77,9 +78,9 @@ pub fn get_variable_intrinsic_widths(
pub fn get_search_start_position(
num_columns: usize, cursor_direction: &app::CursorDirection, cursor_bar: &mut usize,
- current_cursor_position: usize, is_resized: bool,
+ current_cursor_position: usize, is_force_redraw: bool,
) -> usize {
- if is_resized {
+ if is_force_redraw {
*cursor_bar = 0;
}
@@ -117,9 +118,9 @@ pub fn get_search_start_position(
pub fn get_start_position(
num_rows: u64, scroll_direction: &app::ScrollDirection, scroll_position_bar: &mut u64,
- currently_selected_position: u64, is_resized: bool,
+ currently_selected_position: u64, is_force_redraw: bool,
) -> u64 {
- if is_resized {
+ if is_force_redraw {
*scroll_position_bar = 0;
}
diff --git a/src/canvas/widgets/cpu_graph.rs b/src/canvas/widgets/cpu_graph.rs
index cefed8a2..a49bd6ad 100644
--- a/src/canvas/widgets/cpu_graph.rs
+++ b/src/canvas/widgets/cpu_graph.rs
@@ -224,7 +224,7 @@ impl CpuGraphWidget for Painter {
&cpu_widget_state.scroll_state.scroll_direction,
&mut cpu_widget_state.scroll_state.previous_scroll_position,
cpu_widget_state.scroll_state.current_scroll_position,
- app_state.is_resized,
+ app_state.is_force_redraw,
);
let is_on_widget = widget_id == app_state.current_widget.widget_id;
diff --git a/src/canvas/widgets/disk_table.rs b/src/canvas/widgets/disk_table.rs
index 13d24358..fda54d97 100644
--- a/src/canvas/widgets/disk_table.rs
+++ b/src/canvas/widgets/disk_table.rs
@@ -45,7 +45,7 @@ impl DiskTableWidget for Painter {
&disk_widget_state.scroll_state.scroll_direction,
&mut disk_widget_state.scroll_state.previous_scroll_position,
disk_widget_state.scroll_state.current_scroll_position,
- app_state.is_resized,
+ app_state.is_force_redraw,
);
let is_on_widget = app_state.current_widget.widget_id == widget_id;
let disk_table_state = &mut disk_widget_state.scroll_state.table_state;
diff --git a/src/canvas/widgets/process_table.rs b/src/canvas/widgets/process_table.rs
index 0733b500..40803f9b 100644
--- a/src/canvas/widgets/process_table.rs
+++ b/src/canvas/widgets/process_table.rs
@@ -91,7 +91,7 @@ impl ProcessTableWidget for Painter {
&proc_widget_state.scroll_state.scroll_direction,
&mut proc_widget_state.scroll_state.previous_scroll_position,
proc_widget_state.scroll_state.current_scroll_position,
- app_state.is_resized,
+ app_state.is_force_redraw,
);
// Sanity check
@@ -370,7 +370,7 @@ impl ProcessTableWidget for Painter {
.search_state
.cursor_bar,
current_cursor_position,
- app_state.is_resized,
+ app_state.is_force_redraw,
);
let query = proc_widget_state.get_current_search_query().as_str();
diff --git a/src/canvas/widgets/temp_table.rs b/src/canvas/widgets/temp_table.rs
index 007d93b0..1e679904 100644
--- a/src/canvas/widgets/temp_table.rs
+++ b/src/canvas/widgets/temp_table.rs
@@ -46,7 +46,7 @@ impl TempTableWidget for Painter {
&temp_widget_state.scroll_state.scroll_direction,
&mut temp_widget_state.scroll_state.previous_scroll_position,
temp_widget_state.scroll_state.current_scroll_position,
- app_state.is_resized,
+ app_state.is_force_redraw,
);
let is_on_widget = widget_id == app_state.current_widget.widget_id;
let temp_table_state = &mut temp_widget_state.scroll_state.table_state;