Preserve requested GUI scale across temporary small surfaces

Keep framebuffer limits in rendering and explicit option cycling rather than overwriting the saved choice during startup or settings application.

Co-Authored-By: Codex gpt-6.1-sol <noreply@openai.com>
This commit is contained in:
rdbtCVS
2026-10-25 21:08:55 +00:00
parent 82b0051a3c
commit 40b3c1e3d6
4 changed files with 26 additions and 22 deletions
-10
View File
@@ -9194,10 +9194,6 @@ 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;
// Options.biomeBlendRadius, ambientOcclusion and cutoutLeaves:
// LevelExtractor.allChanged when they change.
@@ -13094,10 +13090,6 @@ impl Loading {
return;
}
}
if let Some(r) = &self.renderer {
self.settings
.clamp_gui_scale([r.config.width as i32, r.config.height as i32]);
}
horizon_client::hud::GUI_SCALE.store(self.settings.gui_scale, Ordering::Relaxed);
self.window = Some(window);
}
@@ -13136,8 +13128,6 @@ impl Loading {
self.settings.horizon.api,
) {
Ok(r) => {
self.settings
.clamp_gui_scale([r.config.width as i32, r.config.height as i32]);
horizon_client::hud::GUI_SCALE.store(self.settings.gui_scale, Ordering::Relaxed);
self.renderer = Some(r);
}
@@ -272,8 +272,6 @@ impl Loading {
}
pub(super) fn apply_menu_settings(&mut self) {
if let Some(renderer) = &mut self.renderer {
self.settings
.clamp_gui_scale([renderer.config.width as i32, renderer.config.height as i32]);
renderer.gamma = self.settings.gamma;
renderer.set_present_mode(self.settings.vsync, self.settings.horizon.present_mode);
}
-3
View File
@@ -3403,9 +3403,6 @@ mod tests {
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;
+26 -7
View File
@@ -104,7 +104,7 @@ pub struct Settings {
pub master_volume: f32,
/// Volumes of every other sound source, indexed like SOUND_SOURCES.
pub volumes: [f32; 11],
/// 0 = auto.
/// Requested scale (0 = auto); rendering caps it to the current framebuffer.
pub gui_scale: u32,
pub view_bobbing: bool,
/// Brightness 0..1 (gamma).
@@ -284,12 +284,6 @@ 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()
@@ -597,6 +591,31 @@ impl Settings {
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn gui_scale_survives_temporary_small_framebuffer() {
for requested in [0, 1, 2, 6] {
let settings = Settings::parse(&format!("guiScale:{requested}\n"));
// Hyprland's initial surface can be smaller than the fullscreen one.
for (framebuffer, maximum) in [([715, 860], 2), ([3400, 1913], 7)] {
let effective = crate::window::calculate_scale(
framebuffer,
settings.gui_scale as i32,
settings.force_unicode,
);
assert_eq!(
effective,
if requested == 0 {
maximum
} else {
(requested as i32).min(maximum)
}
);
let saved = Settings::parse(&settings.serialize());
assert_eq!(saved.gui_scale, requested);
}
}
}
#[test]
fn round_trips_vanilla_options_txt() {
let text = "version:4000\nfov:0.5\nrenderDistance:16\nmaxFps:260\nrenderClouds:\"fast\"\nkey_key.jump:key.keyboard.j\nsoundCategory_music:0.25\nresourcePacks:[\"vanilla\",\"file/x.zip\"]\nlang:fr_fr\nsomeFutureOption:42\n";