diff options
author | Clement Tsang <34804052+ClementTsang@users.noreply.github.com> | 2022-08-14 18:21:48 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-14 18:21:48 -0400 |
commit | 3016a3d6a2bd24af4877e23841800d71e7e149ff (patch) | |
tree | 14517526fca1a54bed62859921a73103c91e816a /src | |
parent | 79a0f20825a56661b12bce495e56a761ba796033 (diff) |
refactor: change max_scroll_index usage to better reflect name (#783)
Tweaks `max_scroll_index` usage in the help menu to better reflect its name of being a max index, not a max index bound.
For example, before, the index could not be equal to or more than `max_scroll_index`, but the name would have implied that it should be less than or equal to it.
Diffstat (limited to 'src')
-rw-r--r-- | src/app.rs | 22 | ||||
-rw-r--r-- | src/canvas/dialogs/help_dialog.rs | 27 |
2 files changed, 16 insertions, 33 deletions
@@ -1017,15 +1017,10 @@ impl App { pub fn scroll_half_page_down(&mut self) { if self.help_dialog_state.is_showing_help { - let current = &mut self.help_dialog_state.scroll_state.current_scroll_index; + let current = self.help_dialog_state.scroll_state.current_scroll_index; let amount = self.help_dialog_state.height / 2; - *current = (*current + amount).min( - self.help_dialog_state - .scroll_state - .max_scroll_index - .saturating_sub(1), - ); + self.help_scroll_to_or_max(current + amount); } else if self.current_widget.widget_type.is_widget_table() { if let (Some((_tlc_x, tlc_y)), Some((_brc_x, brc_y))) = ( &self.current_widget.top_left_corner, @@ -2098,11 +2093,8 @@ impl App { } self.reset_multi_tap_keys(); } else if self.help_dialog_state.is_showing_help { - self.help_dialog_state.scroll_state.current_scroll_index = self - .help_dialog_state - .scroll_state - .max_scroll_index - .saturating_sub(1); + self.help_dialog_state.scroll_state.current_scroll_index = + self.help_dialog_state.scroll_state.max_scroll_index; } else if self.delete_dialog_state.is_showing_dd { self.delete_dialog_state.selected_signal = KillSignal::Kill(MAX_SIGNAL); } @@ -2201,7 +2193,7 @@ impl App { } fn help_scroll_down(&mut self) { - if self.help_dialog_state.scroll_state.current_scroll_index + 1 + if self.help_dialog_state.scroll_state.current_scroll_index < self.help_dialog_state.scroll_state.max_scroll_index { self.help_dialog_state.scroll_state.current_scroll_index += 1; @@ -2209,11 +2201,11 @@ impl App { } fn help_scroll_to_or_max(&mut self, new_position: u16) { - if new_position < self.help_dialog_state.scroll_state.max_scroll_index { + if new_position <= self.help_dialog_state.scroll_state.max_scroll_index { self.help_dialog_state.scroll_state.current_scroll_index = new_position; } else { self.help_dialog_state.scroll_state.current_scroll_index = - self.help_dialog_state.scroll_state.max_scroll_index - 1; + self.help_dialog_state.scroll_state.max_scroll_index; } } diff --git a/src/canvas/dialogs/help_dialog.rs b/src/canvas/dialogs/help_dialog.rs index df76d52d..b125e73f 100644 --- a/src/canvas/dialogs/help_dialog.rs +++ b/src/canvas/dialogs/help_dialog.rs @@ -76,28 +76,19 @@ impl Painter { overflow_buffer += buffer; }); - app_state.help_dialog_state.scroll_state.max_scroll_index = - (self.styled_help_text.len() as u16 - + (constants::HELP_TEXT.len() as u16 - 5) - + overflow_buffer) - .saturating_sub(draw_loc.height); + let max_scroll_index = &mut app_state.help_dialog_state.scroll_state.max_scroll_index; + *max_scroll_index = (self.styled_help_text.len() as u16 + + (constants::HELP_TEXT.len() as u16 - 5) + + overflow_buffer) + .saturating_sub(draw_loc.height + 1); // Fix if over-scrolled - if app_state + let index = &mut 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); - } + .current_scroll_index; + + *index = max(*index, *max_scroll_index); } f.render_widget( |