diff --git a/crates/horizon-client/src/game/game_rules_screen.rs b/crates/horizon-client/src/game/game_rules_screen.rs index 126bc8804..0992f7689 100644 --- a/crates/horizon-client/src/game/game_rules_screen.rs +++ b/crates/horizon-client/src/game/game_rules_screen.rs @@ -564,6 +564,29 @@ mod tests { ); } + /// AbstractScrollArea: a press on the bar holds it, a drag moves the + /// list (to the ends past them), a release lets go. + #[test] + fn the_scroll_bar_can_be_held_dragged_and_let_go() { + let mut s = RulesScreen::new(&GameRules::default()); + let (w, h) = (427.0, 240.0); + let (top, bottom, content) = (HEADER, h - FOOTER, s.content()); + assert!( + content > bottom - top, + "the rules overflow a 240-high screen" + ); + let bar = RulesScreen::bar(w); + assert!(!s.press_scrollbar((bar - 4.0, top + 5.0), (w, h))); + assert!(s.press_scrollbar((bar + 3.0, top + 5.0), (w, h))); + s.drag(top + 40.0, h); + assert!(s.scroll.amount > 0.0); + s.drag(bottom + 10.0, h); + assert_eq!(s.scroll.amount, content - (bottom - top)); + s.release(); + s.drag(top, h); + assert_eq!(s.scroll.amount, content - (bottom - top)); + } + #[test] fn edits_change_rules_and_bad_numbers_hold_done() { let mut s = RulesScreen::new(&GameRules::default()); diff --git a/crates/horizon-client/src/game/stats_screen.rs b/crates/horizon-client/src/game/stats_screen.rs index e86b29aeb..bd7663e49 100644 --- a/crates/horizon-client/src/game/stats_screen.rs +++ b/crates/horizon-client/src/game/stats_screen.rs @@ -492,11 +492,7 @@ impl Game<'_> { } pub(super) fn stats_scroll(&mut self, amount: f32) { let (row_h, _) = self.stats_rows(); - let size = self - .renderer - .as_ref() - .map_or([1280, 720], |r| [r.config.width, r.config.height]); - let h = HudBatch::new(size).height; + let h = self.gui_size().1; let content = self.stats_content(); self.stats_ui .scroll @@ -517,11 +513,7 @@ impl Game<'_> { if !self.stats_ui.scroll.held() { return; } - let size = self - .renderer - .as_ref() - .map_or([1280, 720], |r| [r.config.width, r.config.height]); - let h = HudBatch::new(size).height; + let h = self.gui_size().1; let content = self.stats_content(); self.stats_ui .scroll