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.
This commit is contained in:
Clement Tsang 2022-08-14 18:21:48 -04:00 committed by GitHub
parent 79a0f20825
commit 3016a3d6a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 33 deletions

View File

@ -1017,15 +1017,10 @@ impl App {
pub fn scroll_half_page_down(&mut self) { pub fn scroll_half_page_down(&mut self) {
if self.help_dialog_state.is_showing_help { 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; let amount = self.help_dialog_state.height / 2;
*current = (*current + amount).min( self.help_scroll_to_or_max(current + amount);
self.help_dialog_state
.scroll_state
.max_scroll_index
.saturating_sub(1),
);
} else if self.current_widget.widget_type.is_widget_table() { } else if self.current_widget.widget_type.is_widget_table() {
if let (Some((_tlc_x, tlc_y)), Some((_brc_x, brc_y))) = ( if let (Some((_tlc_x, tlc_y)), Some((_brc_x, brc_y))) = (
&self.current_widget.top_left_corner, &self.current_widget.top_left_corner,
@ -2098,11 +2093,8 @@ impl App {
} }
self.reset_multi_tap_keys(); self.reset_multi_tap_keys();
} else if self.help_dialog_state.is_showing_help { } else if self.help_dialog_state.is_showing_help {
self.help_dialog_state.scroll_state.current_scroll_index = self self.help_dialog_state.scroll_state.current_scroll_index =
.help_dialog_state self.help_dialog_state.scroll_state.max_scroll_index;
.scroll_state
.max_scroll_index
.saturating_sub(1);
} else if self.delete_dialog_state.is_showing_dd { } else if self.delete_dialog_state.is_showing_dd {
self.delete_dialog_state.selected_signal = KillSignal::Kill(MAX_SIGNAL); self.delete_dialog_state.selected_signal = KillSignal::Kill(MAX_SIGNAL);
} }
@ -2201,7 +2193,7 @@ impl App {
} }
fn help_scroll_down(&mut self) { 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.max_scroll_index
{ {
self.help_dialog_state.scroll_state.current_scroll_index += 1; 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) { 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; self.help_dialog_state.scroll_state.current_scroll_index = new_position;
} else { } else {
self.help_dialog_state.scroll_state.current_scroll_index = 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;
} }
} }

View File

@ -76,28 +76,19 @@ impl Painter {
overflow_buffer += buffer; overflow_buffer += buffer;
}); });
app_state.help_dialog_state.scroll_state.max_scroll_index = let max_scroll_index = &mut app_state.help_dialog_state.scroll_state.max_scroll_index;
(self.styled_help_text.len() as u16 *max_scroll_index = (self.styled_help_text.len() as u16
+ (constants::HELP_TEXT.len() as u16 - 5) + (constants::HELP_TEXT.len() as u16 - 5)
+ overflow_buffer) + overflow_buffer)
.saturating_sub(draw_loc.height); .saturating_sub(draw_loc.height + 1);
// Fix if over-scrolled // Fix if over-scrolled
if app_state let index = &mut app_state
.help_dialog_state .help_dialog_state
.scroll_state .scroll_state
.current_scroll_index .current_scroll_index;
>= app_state.help_dialog_state.scroll_state.max_scroll_index
{ *index = max(*index, *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);
}
} }
f.render_widget( f.render_widget(