From 61c5f29ab772d04d4cf55c06f59870c27205c16b Mon Sep 17 00:00:00 2001 From: levzzz <86072227+levzzz5154@users.noreply.github.com> Date: Mon, 26 Oct 2026 01:04:47 +0500 Subject: [PATCH 1/2] Game Rules and Statistics: the scroll bars can be dragged Both lists drew a scroll bar but only listened to the mouse wheel: a press inside the bar column, the drag that follows and the release were dropped. `ui::Scroll` already models AbstractSelectionList's press/drag/release (the server list uses it); the two screens now keep their scrolling in it and the window passes the press, the pointer's moves while it is held and the release along. Fixes #1782 --- crates/horizon-client/src/game.rs | 10 +++ .../src/game/game_rules_screen.rs | 56 +++++++++++---- crates/horizon-client/src/game/lan_screen.rs | 21 ++++++ .../horizon-client/src/game/stats_screen.rs | 68 ++++++++++++++++--- 4 files changed, 132 insertions(+), 23 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index f05ee41e4..f4b2fc192 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -10962,6 +10962,12 @@ impl ApplicationHandler for Game<'_> { if self.screen == Screen::Advancements { self.advancements_drag(); } + if self.screen == Screen::Stats { + self.stats_drag(); + } + if self.screen == Screen::WorldOptions { + self.world_options_drag(); + } if self.screen == Screen::Creative { let (_, oy) = Self::creative_origin(&b); self.creative_screen.drag_scrollbar(self.cursor.1 - oy); @@ -11238,6 +11244,9 @@ impl ApplicationHandler for Game<'_> { Screen::WorldOptions if pressed && button == MouseButton::Left => { self.world_options_click() } + Screen::WorldOptions if button == MouseButton::Left => { + self.world_options_release() + } Screen::Friends if pressed && button == MouseButton::Left => { self.friends_screen_click() } @@ -11261,6 +11270,7 @@ impl ApplicationHandler for Game<'_> { .map_or([1, 1], |r| [r.config.width, r.config.height]); self.stats_click(size); } + Screen::Stats if button == MouseButton::Left => self.stats_release(), _ => {} } } diff --git a/crates/horizon-client/src/game/game_rules_screen.rs b/crates/horizon-client/src/game/game_rules_screen.rs index d925c5081..126bc8804 100644 --- a/crates/horizon-client/src/game/game_rules_screen.rs +++ b/crates/horizon-client/src/game/game_rules_screen.rs @@ -45,7 +45,8 @@ pub(super) struct RulesScreen { initial: GameRules, /// IntegerRuleEntry's boxes, by rule. numbers: Vec<(&'static str, EditBox)>, - scroll: f32, + /// RuleList's scrolling: the wheel and the held scrollbar. + scroll: ui::Scroll, /// ConfirmScreen "Game Rule Changes" in its place. confirm: bool, } @@ -120,7 +121,7 @@ impl RulesScreen { values: rules.clone(), initial: rules.clone(), numbers, - scroll: 0.0, + scroll: ui::Scroll::default(), confirm: false, } } @@ -156,12 +157,17 @@ impl RulesScreen { }) .collect() } - fn max_scroll(rows: usize, h: f32) -> f32 { - (ROW * rows as f32 + 4.0 - (h - HEADER - FOOTER)).max(0.0) - } /// Entry `i`'s top: 2 under the list's top, less the scroll. fn row_top(&self, i: usize) -> f32 { - HEADER + 2.0 - self.scroll.trunc() + ROW * i as f32 + HEADER + 2.0 - self.scroll.amount.trunc() + ROW * i as f32 + } + /// The list's scrollbar column (AbstractSelectionList: 6 pixels right of + /// the entries) and the pixels it scrolls. + fn bar(w: f32) -> f32 { + row_left(w) + ROW_WIDTH + 6.0 + 2.0 + } + fn content(&self) -> f32 { + ROW * self.rows().len() as f32 + 4.0 } /// getEntryAtPosition: the row under the pointer, inside the list. fn hovered(&self, rows: usize, (x, y): (f32, f32), (w, h): (f32, f32)) -> Option { @@ -212,10 +218,28 @@ impl RulesScreen { /// The mouse wheel (AbstractSelectionList: half an entry a step). pub(super) fn wheel(&mut self, delta: f32, h: f32) { if !self.confirm { - let max = Self::max_scroll(self.rows().len(), h); - self.scroll = (self.scroll - delta * ROW / 2.0).clamp(0.0, max); + let content = self.content(); + self.scroll + .wheel(delta, ROW / 2.0, HEADER, h - FOOTER, content); } } + /// A press on the scrollbar holds it (AbstractSelectionList.updateScrolling). + pub(super) fn press_scrollbar(&mut self, cursor: (f32, f32), (w, h): (f32, f32)) -> bool { + let content = self.content(); + self.scroll + .press(cursor, Self::bar(w), HEADER, h - FOOTER, content) + } + /// The pointer moved while the scrollbar is held. + pub(super) fn drag(&mut self, y: f32, h: f32) { + if self.scroll.held() { + let content = self.content(); + self.scroll.drag(y, HEADER, h - FOOTER, content); + } + } + /// The button came up: the scrollbar lets go. + pub(super) fn release(&mut self) { + self.scroll.release(); + } fn focused(&mut self) -> Option<(Option<&'static str>, &mut EditBox)> { if self.search.focused { return Some((None, &mut self.search)); @@ -229,7 +253,7 @@ impl RulesScreen { /// number sets its rule when valid (IntegerRuleEntry's responder). fn edited(&mut self, rule: Option<&'static str>) { let Some(name) = rule else { - self.scroll = 0.0; + self.scroll.amount = 0.0; return; }; let Some(r) = gamerules::rule(name) else { @@ -286,6 +310,11 @@ impl RulesScreen { if on(cx, cy, 150.0, 20.0) { return self.close(); } + // A press on the scrollbar holds it and clicks nothing else. + if self.press_scrollbar(cursor, size) { + self.unfocus(); + return None; + } // A click moves the focus to the widget under it. let (sx, sy) = search_at(w); if on(sx, sy, SEARCH_WIDTH, 15.0) { @@ -360,7 +389,8 @@ impl RulesScreen { return; } let rows = self.rows(); - self.scroll = self.scroll.clamp(0.0, Self::max_scroll(rows.len(), h)); + let content = ROW * rows.len() as f32 + 4.0; + self.scroll.clamp(HEADER, h - FOOTER, content); // RuleList: the in-world list background, its entries clipped to it, // then the separators and scrollbar. ui::list_background(batch, atlas, HEADER, h - FOOTER, true); @@ -421,16 +451,14 @@ impl RulesScreen { } batch.clip_since(first, 0.0, HEADER, w, h - FOOTER); ui::separators(batch, atlas, HEADER, h - FOOTER, true); - let content = ROW * rows.len() as f32 + 4.0; - let bar_x = left + ROW_WIDTH + 6.0 + 2.0; ui::scrollbar( batch, atlas, - bar_x, + Self::bar(w), HEADER, h - FOOTER, content, - self.scroll.trunc(), + self.scroll.amount.trunc(), ); // The header: the title centred over the search box. let title = Text::translate("editGamerule.title", &[]); diff --git a/crates/horizon-client/src/game/lan_screen.rs b/crates/horizon-client/src/game/lan_screen.rs index 335b5fbae..2d0416d72 100644 --- a/crates/horizon-client/src/game/lan_screen.rs +++ b/crates/horizon-client/src/game/lan_screen.rs @@ -802,6 +802,27 @@ impl Game<'_> { } } + /// The pointer moved while a list's scrollbar is held: the game rules' + /// list follows it (AbstractSelectionList.mouseDragged). + pub(super) fn world_options_drag(&mut self) { + let h = self.gui_size().1; + if let Some(o) = self.world_options.as_mut() + && o.view == View::GameRules + && let Some(rules) = o.rules.as_mut() + { + rules.drag(self.cursor.1, h); + } + } + + /// The button came up: a held scrollbar lets go (onRelease). + pub(super) fn world_options_release(&mut self) { + if let Some(o) = self.world_options.as_mut() + && let Some(rules) = o.rules.as_mut() + { + rules.release(); + } + } + pub(super) fn world_options_click(&mut self) { let Some(mut o) = self.world_options.take() else { return; diff --git a/crates/horizon-client/src/game/stats_screen.rs b/crates/horizon-client/src/game/stats_screen.rs index 5505d423d..e86b29aeb 100644 --- a/crates/horizon-client/src/game/stats_screen.rs +++ b/crates/horizon-client/src/game/stats_screen.rs @@ -158,7 +158,8 @@ const COLUMNS: [(&str, &str); 6] = [ #[derive(Default)] pub(super) struct StatsUi { tab: usize, - scroll: f32, + /// The list's scrolling: the wheel and the held scrollbar. + scroll: horizon_client::ui::Scroll, sort: Option<(usize, i32)>, } /// `MenuTabBar` geometry: three tabs over at most 400 pixels. @@ -182,6 +183,15 @@ impl Game<'_> { self.stats_ui = StatsUi::default(); self.screen = Screen::Stats; } + /// The list's scrollbar column (right of the 280 pixel list) and the + /// pixels it scrolls. + fn stats_bar(w: f32) -> f32 { + ((w - 280.0) / 2.0).floor() + 280.0 + 6.0 + } + fn stats_content(&self) -> f32 { + let (row_h, rows) = self.stats_rows(); + row_h * rows as f32 + 4.0 + } fn stats_rows(&self) -> (f32, usize) { match self.stats_ui.tab { 0 => (14.0, CUSTOM.len()), @@ -260,10 +270,9 @@ impl Game<'_> { // The list. let (row_h, rows) = self.stats_rows(); let content = row_h * rows as f32 + 4.0; - let max_scroll = (content - (bottom - top)).max(0.0); - self.stats_ui.scroll = self.stats_ui.scroll.clamp(0.0, max_scroll); + self.stats_ui.scroll.clamp(top, bottom, content); let left = ((w - 280.0) / 2.0).floor(); - let scroll = self.stats_ui.scroll; + let scroll = self.stats_ui.scroll.amount; let row_y = |i: usize| top + 4.0 + i as f32 * row_h - scroll; let visible = |y: f32| y >= top && y + row_h <= bottom; match self.stats_ui.tab { @@ -408,11 +417,11 @@ impl Game<'_> { ui::scrollbar( batch, atlas, - left + 280.0 + 6.0, + Self::stats_bar(w), top, bottom, content, - self.stats_ui.scroll, + self.stats_ui.scroll.amount, ); self.draw_stats_footer(batch, w, h); } @@ -433,6 +442,10 @@ impl Game<'_> { ); } pub(super) fn stats_click(&mut self, size: [u32; 2]) { + // A press on the scrollbar holds it and clicks nothing else. + if self.stats_press_scrollbar(size) { + return; + } let b = HudBatch::new(size); let (w, h) = (b.width, b.height); let (x0, tw) = tabs(w); @@ -441,7 +454,7 @@ impl Game<'_> { && self.stats_ui.tab != i { self.stats_ui.tab = i; - self.stats_ui.scroll = 0.0; + self.stats_ui.scroll.amount = 0.0; self.audio .play("minecraft:ui.button.click", None, 0.25, 1.0); return; @@ -461,7 +474,7 @@ impl Game<'_> { } if self.stats_ui.tab == 1 { let left = ((w - 280.0) / 2.0).floor(); - let y = TAB_H + 4.0 - self.stats_ui.scroll; + let y = TAB_H + 4.0 - self.stats_ui.scroll.amount; for c in 0..COLUMNS.len() { let x = left + 75.0 + 40.0 * c as f32 - 18.0; if ui::hovered(self.cursor, x, y + 1.0, 18.0, 18.0) { @@ -479,6 +492,43 @@ impl Game<'_> { } pub(super) fn stats_scroll(&mut self, amount: f32) { let (row_h, _) = self.stats_rows(); - self.stats_ui.scroll -= amount * row_h / 2.0; + let size = self + .renderer + .as_ref() + .map_or([1280, 720], |r| [r.config.width, r.config.height]); + let h = HudBatch::new(size).height; + let content = self.stats_content(); + self.stats_ui + .scroll + .wheel(amount, row_h / 2.0, TAB_H, h - FOOTER, content); + } + /// A press on the statistics list's scrollbar holds it + /// (`AbstractSelectionList.updateScrolling`). + pub(super) fn stats_press_scrollbar(&mut self, size: [u32; 2]) -> bool { + let b = HudBatch::new(size); + let (w, h) = (b.width, b.height); + let content = self.stats_content(); + self.stats_ui + .scroll + .press(self.cursor, Self::stats_bar(w), TAB_H, h - FOOTER, content) + } + /// The pointer moved while the scrollbar is held. + pub(super) fn stats_drag(&mut self) { + 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 content = self.stats_content(); + self.stats_ui + .scroll + .drag(self.cursor.1, TAB_H, h - FOOTER, content); + } + /// The button came up: the scrollbar lets go. + pub(super) fn stats_release(&mut self) { + self.stats_ui.scroll.release(); } } From a41381236362cca38a951ed652adeaef876e0b4a Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 23:46:15 +0100 Subject: [PATCH 2/2] 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 --- .../src/game/game_rules_screen.rs | 23 +++++++++++++++++++ .../horizon-client/src/game/stats_screen.rs | 12 ++-------- 2 files changed, 25 insertions(+), 10 deletions(-) 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