From bbd475cfdb68964bed17ceae47893f41d9b4d7f5 Mon Sep 17 00:00:00 2001 From: ClementTsang Date: Tue, 18 Feb 2020 23:33:15 -0500 Subject: Scroll bar fix v2, electric boogaloo --- src/canvas/drawing_utils.rs | 24 +++++++++++++++--------- src/main.rs | 42 ++++++++++++++++++++---------------------- 2 files changed, 35 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/canvas/drawing_utils.rs b/src/canvas/drawing_utils.rs index 62db65e6..42b80333 100644 --- a/src/canvas/drawing_utils.rs +++ b/src/canvas/drawing_utils.rs @@ -71,33 +71,39 @@ pub fn get_variable_intrinsic_widths( } pub fn get_start_position( - num_rows: u64, scroll_direction: &app::ScrollDirection, previously_scrolled_position: &mut u64, + num_rows: u64, scroll_direction: &app::ScrollDirection, scroll_position_bar: &mut u64, currently_selected_position: u64, ) -> u64 { + if currently_selected_position >= *scroll_position_bar + && num_rows > (currently_selected_position - *scroll_position_bar + 1) + { + *scroll_position_bar = + std::cmp::max(0, currently_selected_position as i64 - num_rows as i64 + 1) as u64; + } match scroll_direction { app::ScrollDirection::DOWN => { - if currently_selected_position < *previously_scrolled_position + num_rows { + if currently_selected_position < *scroll_position_bar + num_rows { // If, using previous_scrolled_position, we can see the element // (so within that and + num_rows) just reuse the current previously scrolled position - *previously_scrolled_position + *scroll_position_bar } else if currently_selected_position >= num_rows { // Else if the current position past the last element visible in the list, omit // until we can see that element - *previously_scrolled_position = currently_selected_position - num_rows; - currently_selected_position - num_rows + *scroll_position_bar = currently_selected_position - num_rows; + *scroll_position_bar } else { // Else, if it is not past the last element visible, do not omit anything 0 } } app::ScrollDirection::UP => { - if currently_selected_position <= *previously_scrolled_position { + if currently_selected_position <= *scroll_position_bar { // If it's past the first element, then show from that element downwards - *previously_scrolled_position = currently_selected_position; - *previously_scrolled_position + *scroll_position_bar = currently_selected_position; + *scroll_position_bar } else { // Else, don't change what our start position is from whatever it is set to! - *previously_scrolled_position + *scroll_position_bar } } } diff --git a/src/main.rs b/src/main.rs index 4bc692d7..725fe5ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -735,32 +735,30 @@ fn generate_config_colours(config: &Config, painter: &mut canvas::Painter) -> er fn panic_hook(panic_info: &PanicInfo<'_>) { let mut stdout = stdout(); - if cfg!(debug_assertions) { - let msg = match panic_info.payload().downcast_ref::<&'static str>() { - Some(s) => *s, - None => match panic_info.payload().downcast_ref::() { - Some(s) => &s[..], - None => "Box", - }, - }; - - let stacktrace: String = format!("{:?}", backtrace::Backtrace::new()); - - execute!( - stdout, - Print(format!( - "thread '' panicked at '{}', {}\n\r{}", - msg, - panic_info.location().unwrap(), - stacktrace - )), - ) - .unwrap(); - } + let msg = match panic_info.payload().downcast_ref::<&'static str>() { + Some(s) => *s, + None => match panic_info.payload().downcast_ref::() { + Some(s) => &s[..], + None => "Box", + }, + }; + + let stacktrace: String = format!("{:?}", backtrace::Backtrace::new()); disable_raw_mode().unwrap(); execute!(stdout, LeaveAlternateScreen).unwrap(); execute!(stdout, DisableMouseCapture).unwrap(); + + execute!( + stdout, + Print(format!( + "thread '' panicked at '{}', {}\n\r{}", + msg, + panic_info.location().unwrap(), + stacktrace + )), + ) + .unwrap(); } fn update_final_process_list(app: &mut app::App) { -- cgit v1.2.3