summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClementTsang <cjhtsang@uwaterloo.ca>2020-02-18 23:33:15 -0500
committerClementTsang <cjhtsang@uwaterloo.ca>2020-02-18 23:33:15 -0500
commitbbd475cfdb68964bed17ceae47893f41d9b4d7f5 (patch)
tree648b41d523e7be8294224f037a98983bd786672a /src
parente4597730bd88c64cf8ece485a01e6cc6bbfb6b61 (diff)
Scroll bar fix v2, electric boogaloo
Diffstat (limited to 'src')
-rw-r--r--src/canvas/drawing_utils.rs24
-rw-r--r--src/main.rs42
2 files changed, 35 insertions, 31 deletions
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::<String>() {
- Some(s) => &s[..],
- None => "Box<Any>",
- },
- };
-
- let stacktrace: String = format!("{:?}", backtrace::Backtrace::new());
-
- execute!(
- stdout,
- Print(format!(
- "thread '<unnamed>' 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::<String>() {
+ Some(s) => &s[..],
+ None => "Box<Any>",
+ },
+ };
+
+ let stacktrace: String = format!("{:?}", backtrace::Backtrace::new());
disable_raw_mode().unwrap();
execute!(stdout, LeaveAlternateScreen).unwrap();
execute!(stdout, DisableMouseCapture).unwrap();
+
+ execute!(
+ stdout,
+ Print(format!(
+ "thread '<unnamed>' panicked at '{}', {}\n\r{}",
+ msg,
+ panic_info.location().unwrap(),
+ stacktrace
+ )),
+ )
+ .unwrap();
}
fn update_final_process_list(app: &mut app::App) {