mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-26 07:04:51 +02:00
Pretty sure I fixed scroll resizing...
This commit is contained in:
parent
8cf5b42f29
commit
67c6984406
43
src/app.rs
43
src/app.rs
@ -233,6 +233,7 @@ pub struct App {
|
|||||||
pub help_dialog_state: AppHelpDialogState,
|
pub help_dialog_state: AppHelpDialogState,
|
||||||
pub app_config_fields: AppConfigFields,
|
pub app_config_fields: AppConfigFields,
|
||||||
pub is_expanded: bool,
|
pub is_expanded: bool,
|
||||||
|
pub is_resized: bool,
|
||||||
pub cpu_state: CpuState,
|
pub cpu_state: CpuState,
|
||||||
pub mem_state: MemState,
|
pub mem_state: MemState,
|
||||||
pub net_state: NetworkState,
|
pub net_state: NetworkState,
|
||||||
@ -275,6 +276,7 @@ impl App {
|
|||||||
show_disabled_data,
|
show_disabled_data,
|
||||||
},
|
},
|
||||||
is_expanded: false,
|
is_expanded: false,
|
||||||
|
is_resized: false,
|
||||||
cpu_state: CpuState::default(),
|
cpu_state: CpuState::default(),
|
||||||
mem_state: MemState::default(),
|
mem_state: MemState::default(),
|
||||||
net_state: NetworkState::default(),
|
net_state: NetworkState::default(),
|
||||||
@ -325,6 +327,7 @@ impl App {
|
|||||||
}
|
}
|
||||||
} else if self.is_expanded {
|
} else if self.is_expanded {
|
||||||
self.is_expanded = false;
|
self.is_expanded = false;
|
||||||
|
self.is_resized = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,43 +543,13 @@ impl App {
|
|||||||
} else if !self.is_in_dialog() {
|
} else if !self.is_in_dialog() {
|
||||||
// Pop-out mode. We ignore if in process search.
|
// 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 {
|
match self.current_widget_selected {
|
||||||
WidgetPosition::Process => {
|
WidgetPosition::ProcessSearch => {}
|
||||||
self.app_scroll_positions
|
_ => {
|
||||||
.process_scroll_state
|
|
||||||
.current_scroll_position = 0;
|
|
||||||
self.app_scroll_positions
|
|
||||||
.process_scroll_state
|
|
||||||
.previous_scroll_position = 0;
|
|
||||||
}
|
|
||||||
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;
|
self.is_expanded = true;
|
||||||
|
self.is_resized = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,8 +83,8 @@ pub struct DisplayableData {
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
/// Handles the canvas' state. TODO: [OPT] implement this.
|
/// Handles the canvas' state. TODO: [OPT] implement this.
|
||||||
pub struct Painter {
|
pub struct Painter {
|
||||||
height: f64,
|
height: u16,
|
||||||
width: f64,
|
width: u16,
|
||||||
vertical_dialog_chunk: Vec<Rect>,
|
vertical_dialog_chunk: Vec<Rect>,
|
||||||
middle_dialog_chunk: Vec<Rect>,
|
middle_dialog_chunk: Vec<Rect>,
|
||||||
vertical_chunks: Vec<Rect>,
|
vertical_chunks: Vec<Rect>,
|
||||||
@ -146,6 +146,17 @@ impl Painter {
|
|||||||
pub fn draw_data<B: backend::Backend>(
|
pub fn draw_data<B: backend::Backend>(
|
||||||
&mut self, terminal: &mut Terminal<B>, app_state: &mut app::App,
|
&mut self, terminal: &mut Terminal<B>, app_state: &mut app::App,
|
||||||
) -> error::Result<()> {
|
) -> 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.autoresize()?;
|
||||||
terminal.draw(|mut f| {
|
terminal.draw(|mut f| {
|
||||||
if app_state.help_dialog_state.is_showing_help {
|
if app_state.help_dialog_state.is_showing_help {
|
||||||
@ -519,6 +530,8 @@ impl Painter {
|
|||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
app_state.is_resized = false;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -612,6 +625,7 @@ impl Painter {
|
|||||||
.app_scroll_positions
|
.app_scroll_positions
|
||||||
.cpu_scroll_state
|
.cpu_scroll_state
|
||||||
.current_scroll_position,
|
.current_scroll_position,
|
||||||
|
app_state.is_resized,
|
||||||
);
|
);
|
||||||
|
|
||||||
let sliced_cpu_data = &cpu_data[start_position as usize..];
|
let sliced_cpu_data = &cpu_data[start_position as usize..];
|
||||||
@ -950,6 +964,7 @@ impl Painter {
|
|||||||
.app_scroll_positions
|
.app_scroll_positions
|
||||||
.temp_scroll_state
|
.temp_scroll_state
|
||||||
.current_scroll_position,
|
.current_scroll_position,
|
||||||
|
app_state.is_resized,
|
||||||
);
|
);
|
||||||
|
|
||||||
let sliced_vec = &(temp_sensor_data[start_position as usize..]);
|
let sliced_vec = &(temp_sensor_data[start_position as usize..]);
|
||||||
@ -1045,6 +1060,7 @@ impl Painter {
|
|||||||
.app_scroll_positions
|
.app_scroll_positions
|
||||||
.disk_scroll_state
|
.disk_scroll_state
|
||||||
.current_scroll_position,
|
.current_scroll_position,
|
||||||
|
app_state.is_resized,
|
||||||
);
|
);
|
||||||
|
|
||||||
let sliced_vec = &disk_data[start_position as usize..];
|
let sliced_vec = &disk_data[start_position as usize..];
|
||||||
@ -1285,6 +1301,7 @@ impl Painter {
|
|||||||
.app_scroll_positions
|
.app_scroll_positions
|
||||||
.process_scroll_state
|
.process_scroll_state
|
||||||
.current_scroll_position,
|
.current_scroll_position,
|
||||||
|
app_state.is_resized,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Sanity check
|
// Sanity check
|
||||||
|
@ -72,16 +72,12 @@ pub fn get_variable_intrinsic_widths(
|
|||||||
|
|
||||||
pub fn get_start_position(
|
pub fn get_start_position(
|
||||||
num_rows: u64, scroll_direction: &app::ScrollDirection, scroll_position_bar: &mut u64,
|
num_rows: u64, scroll_direction: &app::ScrollDirection, scroll_position_bar: &mut u64,
|
||||||
currently_selected_position: u64,
|
currently_selected_position: u64, is_resized: bool,
|
||||||
) -> u64 {
|
) -> u64 {
|
||||||
// TODO: [FIX] Scroll does NOT work with expanded (and resizing overall).
|
if is_resized {
|
||||||
// if currently_selected_position >= *scroll_position_bar
|
*scroll_position_bar = 0;
|
||||||
// && 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);
|
|
||||||
// }
|
|
||||||
match scroll_direction {
|
match scroll_direction {
|
||||||
app::ScrollDirection::DOWN => {
|
app::ScrollDirection::DOWN => {
|
||||||
if currently_selected_position < *scroll_position_bar + num_rows {
|
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
|
// If it's past the first element, then show from that element downwards
|
||||||
*scroll_position_bar = currently_selected_position;
|
*scroll_position_bar = currently_selected_position;
|
||||||
*scroll_position_bar
|
*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 {
|
||||||
// Else, don't change what our start position is from whatever it is set to!
|
// Else, don't change what our start position is from whatever it is set to!
|
||||||
*scroll_position_bar
|
*scroll_position_bar
|
||||||
|
Loading…
x
Reference in New Issue
Block a user