Merge pull request #1941 from rdbtCVS/t3/preserve-gui-scale-setting

🤖 Agent: Thanks rdbt! Matches vanilla: the saved GUI scale isn't clamped while a temporary small surface is up, the HUD caps the scale it draws with. Tested together with the other wave 1 contributor PRs on current main: fmt, clippy -D warnings and the horizon-client tests (1,120 lib tests and the rest) pass; the 114 harnesses the batch affects pass; lan_e2e anvil, grindstone, replant, instant_digging, digging, frames and leads pass with the host in-frame and on its server thread.
This commit is contained in:
Ludovic Marie
2026-10-26 02:20:26 +01:00
committed by GitHub
4 changed files with 26 additions and 22 deletions
-10
View File
@@ -9202,10 +9202,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.
@@ -13105,10 +13101,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);
}
@@ -13147,8 +13139,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";