Scroll bars: the screen's GUI size, and a test of the drag
stats_scroll and stats_drag take the GUI height from gui_size() instead of a copy of it. The Game Rules list's press, drag and release get the test from #1913 (vlesmentie's take on the same fix). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user