From b48539197a0b2b87e0bf62c308b69defcedfbcb5 Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Wed, 14 Oct 2026 22:59:27 +0100 Subject: [PATCH] Use the current framebuffer for GUI Scale cycle limits --- crates/horizon-client/src/game.rs | 5 + crates/horizon-client/src/game/options.rs | 8 ++ crates/horizon-client/src/graphics_ui.rs | 30 +++-- crates/horizon-client/src/options_horizon.rs | 5 +- crates/horizon-client/src/options_ui.rs | 115 ++++++++++++++----- crates/horizon-client/src/settings.rs | 6 + 6 files changed, 129 insertions(+), 40 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index ed70ddc65..96023db60 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -6956,6 +6956,10 @@ impl Game<'_> { )) } fn apply_settings(&mut self) { + if let Some(r) = &self.renderer { + self.settings + .clamp_gui_scale([r.config.width as i32, r.config.height as i32]); + } self.streaming.radius = self.settings.render_distance; self.streaming.biome_blend = self.settings.biome_blend; self.streaming.smooth_lighting = self.settings.smooth_lighting; @@ -8207,6 +8211,7 @@ impl ApplicationHandler for Game<'_> { } } self.window = Some(window); + self.apply_settings(); self.previous = Instant::now(); } fn window_event(&mut self, event_loop: &ActiveEventLoop, id: WindowId, event: WindowEvent) { diff --git a/crates/horizon-client/src/game/options.rs b/crates/horizon-client/src/game/options.rs index a375a38f0..fa631e114 100644 --- a/crates/horizon-client/src/game/options.rs +++ b/crates/horizon-client/src/game/options.rs @@ -55,6 +55,9 @@ impl Game<'_> { self.dragging = true; } let size = self.gui_size(); + let framebuffer = self.renderer.as_ref().map_or([1280, 720], |r| { + [r.config.width as i32, r.config.height as i32] + }); let mut ui = std::mem::take(&mut self.ui.options); let events = ui.click( &mut self.settings, @@ -62,6 +65,7 @@ impl Game<'_> { self.cursor.0, self.cursor.1, size, + framebuffer, false, right, ); @@ -70,6 +74,9 @@ impl Game<'_> { } pub(super) fn options_drag(&mut self) -> Result<()> { let size = self.gui_size(); + let framebuffer = self.renderer.as_ref().map_or([1280, 720], |r| { + [r.config.width as i32, r.config.height as i32] + }); let mut ui = std::mem::take(&mut self.ui.options); let events = ui.click( &mut self.settings, @@ -77,6 +84,7 @@ impl Game<'_> { self.cursor.0, self.cursor.1, size, + framebuffer, true, false, ); diff --git a/crates/horizon-client/src/graphics_ui.rs b/crates/horizon-client/src/graphics_ui.rs index 22e72a00b..d72f8de86 100644 --- a/crates/horizon-client/src/graphics_ui.rs +++ b/crates/horizon-client/src/graphics_ui.rs @@ -412,9 +412,9 @@ impl Item { } self.touched(s); } - pub fn cycle(self, s: &mut Settings, back: bool) { + pub fn cycle(self, s: &mut Settings, back: bool, framebuffer: [i32; 2]) { match self { - Item::Vanilla(o) => o.cycle(s, back), + Item::Vanilla(o) => o.cycle(s, back, framebuffer), Item::Horizon(h) => h.cycle(s, back), } self.touched(s); @@ -648,6 +648,7 @@ impl GraphicsUi { s: &mut Settings, (x, y): (f32, f32), (w, h): (f32, f32), + framebuffer: [i32; 2], drag: bool, right: bool, ) -> Vec { @@ -681,7 +682,7 @@ impl GraphicsUi { self.dragging = Some(item); item.set_slider(s, ui::slider_value(wd.x, wd.w, x)); } else { - item.cycle(s, right); + item.cycle(s, right, framebuffer); return vec![Action::ButtonClick, Action::Changed]; } vec![Action::Changed] @@ -717,11 +718,11 @@ mod tests { .unwrap(); let point = (button.x + 1.0, button.y + 1.0); assert!( - ui.click(Level::Simple, &mut s, point, size, false, true) + ui.click(Level::Simple, &mut s, point, size, [854, 480], false, true) .is_empty() ); assert_eq!( - ui.click(Level::Simple, &mut s, point, size, false, false)[0], + ui.click(Level::Simple, &mut s, point, size, [854, 480], false, false)[0], Action::ButtonClick ); assert!(!ui.release()); @@ -735,13 +736,22 @@ mod tests { &mut s, (slider.x + 1.0, slider.y + 1.0), size, + [854, 480], false, false ), vec![Action::Changed] ); assert_eq!( - ui.click(Level::Simple, &mut s, (-100.0, -100.0), size, true, false), + ui.click( + Level::Simple, + &mut s, + (-100.0, -100.0), + size, + [854, 480], + true, + false + ), vec![Action::Changed] ); assert!(ui.release()); @@ -808,16 +818,16 @@ mod tests { #[test] fn presets_set_vanilla_and_horizon_options() { let mut s = Settings::default(); - Item::Horizon(H::Preset).cycle(&mut s, false); + Item::Horizon(H::Preset).cycle(&mut s, false, [854, 480]); assert_eq!(s.horizon.preset, Preset::Performance); assert_eq!(s.render_distance, 8); assert_eq!(s.clouds, "false"); // Any quality change leaves the preset. - Item::Vanilla(Opt::Clouds).cycle(&mut s, false); + Item::Vanilla(Opt::Clouds).cycle(&mut s, false, [854, 480]); assert_eq!(s.horizon.preset, Preset::Custom); // Display preferences keep it. - Item::Horizon(H::Preset).cycle(&mut s, true); - Item::Vanilla(Opt::Vsync).cycle(&mut s, false); + Item::Horizon(H::Preset).cycle(&mut s, true, [854, 480]); + Item::Vanilla(Opt::Vsync).cycle(&mut s, false, [854, 480]); assert_eq!(s.horizon.preset, Preset::Ultra); } diff --git a/crates/horizon-client/src/options_horizon.rs b/crates/horizon-client/src/options_horizon.rs index 095547ed2..b61c63d35 100644 --- a/crates/horizon-client/src/options_horizon.rs +++ b/crates/horizon-client/src/options_horizon.rs @@ -547,6 +547,7 @@ impl OptionsUi { atlas: &HudAtlas, x: f32, y: f32, + framebuffer: [i32; 2], drag: bool, right: bool, ) -> Vec { @@ -597,14 +598,14 @@ impl OptionsUi { let section = self.section.min(SECTIONS.len() - 1); match (SECTIONS[section].rows)(s).get(i) { Some(HRow::Opt(opt)) => { - opt.cycle(s, right); + opt.cycle(s, right, framebuffer); if *opt == Opt::Preset { apply_preset(s); } events.push(Event::Changed); } Some(HRow::Graphics(item, ..)) => { - item.cycle(s, right); + item.cycle(s, right, framebuffer); events.push(Event::Changed); } Some(HRow::Page(_, _, page)) => self.open_page(*page), diff --git a/crates/horizon-client/src/options_ui.rs b/crates/horizon-client/src/options_ui.rs index 0bafb85d8..19443d7f4 100644 --- a/crates/horizon-client/src/options_ui.rs +++ b/crates/horizon-client/src/options_ui.rs @@ -493,7 +493,7 @@ impl Opt { ) } /// Advance a cycle button (CycleButton.cycleValue). - pub fn cycle(self, s: &mut Settings, back: bool) { + pub fn cycle(self, s: &mut Settings, back: bool, framebuffer: [i32; 2]) { let next = |n: u8, count: u8| { if back { (n + count - 1) % count @@ -502,7 +502,17 @@ impl Opt { } }; match self { - Opt::GuiScale => s.gui_scale = u32::from(next(s.gui_scale.min(6) as u8, 7)), + Opt::GuiScale => { + let max = crate::window::calculate_scale(framebuffer, 0, s.force_unicode) as u32; + let value = s.gui_scale.min(max); + s.gui_scale = if back { + if value == 0 { max } else { value - 1 } + } else if value == max { + 0 + } else { + value + 1 + }; + } Opt::InvertY => s.invert_y = !s.invert_y, Opt::DiscreteScroll => s.discrete_scroll = !s.discrete_scroll, Opt::ViewBobbing => s.view_bobbing = !s.view_bobbing, @@ -1609,16 +1619,20 @@ impl OptionsUi { x: f32, y: f32, size: (f32, f32), + framebuffer: [i32; 2], drag: bool, right: bool, ) -> Vec { if crate::ui_theme::horizon() && self.page() == Page::Main { - return self.click_horizon(s, atlas, x, y, drag, right); + return self.click_horizon(s, atlas, x, y, framebuffer, drag, right); } if let Some(level) = Self::graphics_level(self.page()) { use crate::graphics_ui::Action; let mut events = Vec::new(); - for action in self.graphics.click(level, s, (x, y), size, drag, right) { + for action in self + .graphics + .click(level, s, (x, y), size, framebuffer, drag, right) + { match action { Action::ButtonClick => events.push(Event::ButtonClick), Action::Changed => events.push(Event::Changed), @@ -1709,7 +1723,7 @@ impl OptionsUi { Act::Push(p) => self.push(p), Act::Done => events.extend(self.back(s)), Act::Cycle(opt) => { - opt.cycle(s, right); + opt.cycle(s, right, framebuffer); if opt == Opt::Preset { apply_preset(s); } @@ -2008,16 +2022,19 @@ mod tests { .expect("GUI Scale must be a cycle button in classic Video Settings"); let (x, y) = (button.x + 1.0, button.y + 1.0); assert!(Opt::GuiScale.slider_position(&s).is_none()); - assert!(ui.click(&mut s, &atlas, x, y, size, false, true).is_empty()); + assert!( + ui.click(&mut s, &atlas, x, y, size, [854, 480], false, true) + .is_empty() + ); assert_eq!(s.gui_scale, 0); - for expected in [1, 2, 3, 4, 5, 6, 0] { + for expected in [1, 2, 0] { assert_eq!( - ui.click(&mut s, &atlas, x, y, size, false, false), + ui.click(&mut s, &atlas, x, y, size, [854, 480], false, false), vec![Event::ButtonClick, Event::Changed] ); assert_eq!(s.gui_scale, expected); assert!( - ui.click(&mut s, &atlas, x + 100.0, y, size, true, false) + ui.click(&mut s, &atlas, x + 100.0, y, size, [854, 480], true, false) .is_empty() ); assert_eq!(s.gui_scale, expected); @@ -2027,17 +2044,42 @@ mod tests { #[test] fn gui_scale_cycle_handles_reverse_and_out_of_range_saved_values() { - let mut s = Settings::default(); - for expected in [6, 5, 4, 3, 2, 1, 0] { - Opt::GuiScale.cycle(&mut s, true); - assert_eq!(s.gui_scale, expected); + for (framebuffer, force_unicode, max) in [ + ([854, 480], false, 2), + ([1920, 1080], false, 4), + ([1280, 720], true, 4), + ([3840, 2160], false, 9), + ([320, 240], false, 1), + ] { + let mut s = Settings { + force_unicode, + ..Settings::default() + }; + for expected in (0..=max).rev() { + Opt::GuiScale.cycle(&mut s, true, framebuffer); + assert_eq!(s.gui_scale, expected); + } + for expected in (1..=max).chain([0]) { + Opt::GuiScale.cycle(&mut s, false, framebuffer); + assert_eq!(s.gui_scale, expected); + } + s.gui_scale = u32::MAX; + s.clamp_gui_scale(framebuffer); + assert_eq!(s.gui_scale, max); + s.gui_scale = u32::MAX; + Opt::GuiScale.cycle(&mut s, false, framebuffer); + assert_eq!(s.gui_scale, 0); + s.gui_scale = u32::MAX; + Opt::GuiScale.cycle(&mut s, true, framebuffer); + assert_eq!(s.gui_scale, max - 1); } - s.gui_scale = u32::MAX; - Opt::GuiScale.cycle(&mut s, false); - assert_eq!(s.gui_scale, 0); - s.gui_scale = u32::MAX; - Opt::GuiScale.cycle(&mut s, true); - assert_eq!(s.gui_scale, 5); + let mut s = Settings { + gui_scale: 4, + ..Settings::default() + }; + // A resized window supplies a new maximum on the next interaction. + Opt::GuiScale.cycle(&mut s, true, [854, 480]); + assert_eq!(s.gui_scale, 1); } #[test] @@ -2062,14 +2104,17 @@ mod tests { }) .unwrap(); let (x, y) = (button.x + 1.0, button.y + 1.0); - assert!(ui.click(&mut s, &atlas, x, y, size, false, true).is_empty()); + assert!( + ui.click(&mut s, &atlas, x, y, size, [854, 480], false, true) + .is_empty() + ); assert_eq!( - ui.click(&mut s, &atlas, x, y, size, false, false), + ui.click(&mut s, &atlas, x, y, size, [854, 480], false, false), vec![Event::ButtonClick, Event::Changed] ); assert!(ui.release().is_empty()); assert!( - ui.click(&mut s, &atlas, 0.0, 0.0, size, false, false) + ui.click(&mut s, &atlas, 0.0, 0.0, size, [854, 480], false, false) .is_empty() ); ui.show(Page::KeyBinds); @@ -2085,6 +2130,7 @@ mod tests { disabled.x + 1.0, disabled.y + 1.0, size, + [854, 480], false, false ) @@ -2114,24 +2160,27 @@ mod tests { .unwrap(); let (x, y) = (slider.x + slider.w - 1.0, slider.y + 1.0); assert_eq!( - ui.click(&mut s, &atlas, x, y, size, false, false), + ui.click(&mut s, &atlas, x, y, size, [854, 480], false, false), vec![Event::Changed] ); assert_eq!(s.master_volume, 1.0); assert_eq!(ui.release(), vec![Event::ButtonClick]); assert!(ui.release().is_empty()); assert_eq!( - ui.click(&mut s, &atlas, x, y, size, false, false), + ui.click(&mut s, &atlas, x, y, size, [854, 480], false, false), vec![Event::Changed] ); for cx in [-100.0, 250.0, 1000.0] { assert_eq!( - ui.click(&mut s, &atlas, cx, -100.0, size, true, false), + ui.click(&mut s, &atlas, cx, -100.0, size, [854, 480], true, false), vec![Event::Changed] ); } assert_eq!(ui.release(), vec![Event::ButtonClick]); - assert!(ui.click(&mut s, &atlas, x, y, size, true, false).is_empty()); + assert!( + ui.click(&mut s, &atlas, x, y, size, [854, 480], true, false) + .is_empty() + ); } #[test] @@ -2152,8 +2201,17 @@ mod tests { }) .unwrap(); assert!( - ui.click(&mut s, &atlas, row.x + 1.0, row.y + 1.0, size, false, false) - .is_empty() + ui.click( + &mut s, + &atlas, + row.x + 1.0, + row.y + 1.0, + size, + [854, 480], + false, + false + ) + .is_empty() ); assert!(ui.release().is_empty()); let search = ui.language_search.clone(); @@ -2164,6 +2222,7 @@ mod tests { search.x + 1.0, search.y + 1.0, size, + [854, 480], false, false ) diff --git a/crates/horizon-client/src/settings.rs b/crates/horizon-client/src/settings.rs index 1cc58b472..d232b8dd2 100644 --- a/crates/horizon-client/src/settings.rs +++ b/crates/horizon-client/src/settings.rs @@ -281,6 +281,12 @@ fn put_s(f: &mut OptionsFile, key: &str, v: &str) { } } impl Settings { + /// `ClampingLazyMaxIntRange.validateValue`: clamp once the framebuffer is known. + pub fn clamp_gui_scale(&mut self, framebuffer: [i32; 2]) { + let max = crate::window::calculate_scale(framebuffer, 0, self.force_unicode) as u32; + self.gui_scale = self.gui_scale.min(max); + } + pub fn load(path: &Path) -> Self { let horizon = path .parent()