Pretty sure I fixed scroll resizing...

This commit is contained in:
ClementTsang 2020-02-19 19:56:04 -05:00
parent 8cf5b42f29
commit 67c6984406
3 changed files with 34 additions and 45 deletions

View file

@ -233,6 +233,7 @@ pub struct App {
pub help_dialog_state: AppHelpDialogState,
pub app_config_fields: AppConfigFields,
pub is_expanded: bool,
pub is_resized: bool,
pub cpu_state: CpuState,
pub mem_state: MemState,
pub net_state: NetworkState,
@ -275,6 +276,7 @@ impl App {
show_disabled_data,
},
is_expanded: false,
is_resized: false,
cpu_state: CpuState::default(),
mem_state: MemState::default(),
net_state: NetworkState::default(),
@ -325,6 +327,7 @@ impl App {
}
} else if self.is_expanded {
self.is_expanded = false;
self.is_resized = true;
}
}
@ -540,43 +543,13 @@ impl App {
} else if !self.is_in_dialog() {
// Pop-out mode. We ignore if in process search.
// TODO: [FIX] This is a temporary workaround for scroll not being proper with expanded (and resizing overall).
match self.current_widget_selected {
WidgetPosition::Process => {
self.app_scroll_positions
.process_scroll_state
.current_scroll_position = 0;
self.app_scroll_positions
.process_scroll_state
.previous_scroll_position = 0;
WidgetPosition::ProcessSearch => {}
_ => {
self.is_expanded = true;
self.is_resized = true;
}
WidgetPosition::Cpu => {
self.app_scroll_positions
.cpu_scroll_state
.current_scroll_position = 0;
self.app_scroll_positions
.cpu_scroll_state
.previous_scroll_position = 0;
}
WidgetPosition::Temp => {
self.app_scroll_positions
.temp_scroll_state
.current_scroll_position = 0;
self.app_scroll_positions
.temp_scroll_state
.previous_scroll_position = 0;
}
WidgetPosition::Disk => {
self.app_scroll_positions
.disk_scroll_state
.current_scroll_position = 0;
self.app_scroll_positions
.disk_scroll_state
.previous_scroll_position = 0;
}
_ => {}
}
self.is_expanded = true;
}
}

View file

@ -83,8 +83,8 @@ pub struct DisplayableData {
#[derive(Default)]
/// Handles the canvas' state. TODO: [OPT] implement this.
pub struct Painter {
height: f64,
width: f64,
height: u16,
width: u16,
vertical_dialog_chunk: Vec<Rect>,
middle_dialog_chunk: Vec<Rect>,
vertical_chunks: Vec<Rect>,
@ -146,6 +146,17 @@ impl Painter {
pub fn draw_data<B: backend::Backend>(
&mut self, terminal: &mut Terminal<B>, app_state: &mut app::App,
) -> error::Result<()> {
let terminal_size = terminal.size()?;
let current_height = terminal_size.height;
let current_width = terminal_size.width;
if self.height == 0 && self.width == 0 {
self.height = current_height;
self.width = current_width;
} else if self.height != current_height || self.width != current_width {
app_state.is_resized = true;
}
terminal.autoresize()?;
terminal.draw(|mut f| {
if app_state.help_dialog_state.is_showing_help {
@ -519,6 +530,8 @@ impl Painter {
}
})?;
app_state.is_resized = false;
Ok(())
}
@ -612,6 +625,7 @@ impl Painter {
.app_scroll_positions
.cpu_scroll_state
.current_scroll_position,
app_state.is_resized,
);
let sliced_cpu_data = &cpu_data[start_position as usize..];
@ -950,6 +964,7 @@ impl Painter {
.app_scroll_positions
.temp_scroll_state
.current_scroll_position,
app_state.is_resized,
);
let sliced_vec = &(temp_sensor_data[start_position as usize..]);
@ -1045,6 +1060,7 @@ impl Painter {
.app_scroll_positions
.disk_scroll_state
.current_scroll_position,
app_state.is_resized,
);
let sliced_vec = &disk_data[start_position as usize..];
@ -1285,6 +1301,7 @@ impl Painter {
.app_scroll_positions
.process_scroll_state
.current_scroll_position,
app_state.is_resized,
);
// Sanity check

View file

@ -72,16 +72,12 @@ pub fn get_variable_intrinsic_widths(
pub fn get_start_position(
num_rows: u64, scroll_direction: &app::ScrollDirection, scroll_position_bar: &mut u64,
currently_selected_position: u64,
currently_selected_position: u64, is_resized: bool,
) -> u64 {
// TODO: [FIX] Scroll does NOT work with expanded (and resizing overall).
// if currently_selected_position >= *scroll_position_bar
// && num_rows > (currently_selected_position - *scroll_position_bar + num_rows)
// {
// *scroll_position_bar =
// std::cmp::max(0, currently_selected_position as i64 - num_rows as i64) as u64;
// debug!("Scroll bar: {}", *scroll_position_bar);
// }
if is_resized {
*scroll_position_bar = 0;
}
match scroll_direction {
app::ScrollDirection::DOWN => {
if currently_selected_position < *scroll_position_bar + num_rows {
@ -103,6 +99,9 @@ pub fn get_start_position(
// If it's past the first element, then show from that element downwards
*scroll_position_bar = currently_selected_position;
*scroll_position_bar
} else if currently_selected_position >= *scroll_position_bar + num_rows {
*scroll_position_bar = currently_selected_position - num_rows;
*scroll_position_bar
} else {
// Else, don't change what our start position is from whatever it is set to!
*scroll_position_bar