LR-BEHAV-WINDOW: the window's minimum is weighed at the interface zoom when it is fitted or maximized (CodeRabbit, #2974)

MIN_SIZE is in the interface's points, so at 2x zoom it holds the window to 1800 x 1120 system
points: on a 1200 x 800 screen that minimum blocked the fit and the maximize though the screen is
larger than 900 x 560. The minimum is now compared in the system's points and lowered to the
fitted size (or the screen, before maximizing). Tests in
a_window_on_a_screen_smaller_than_its_minimum_fits_within_the_screen and the zoomed case of
the_window_is_maximized_once_it_shows_and_again_if_it_only_says_so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
OneSlipsandClaude Opus 5.5 committed 2026-11-01 07:22:40 +10:00
1 parent d69d76d331
commit 36a1cf2964
2 files changed
+29 -11

No files matched your search

+18 -9
View File
@@ -332,12 +332,19 @@ fn interface_zoom(zoom: f32) -> f32 {
if zoom.is_finite() && zoom > 0.0 { zoom } else { 1.0 }
}
/// On a `screen` (system points) smaller than [`MIN_SIZE`]: the command that lowers the window's minimum to the
/// screen, in the interface's points (`zoom`). Nothing on a screen the minimum fits on.
fn min_within(screen: [f32; 2], zoom: f32) -> Vec<egui::ViewportCommand> {
if screen[0] < MIN_SIZE[0] || screen[1] < MIN_SIZE[1] {
let min = [MIN_SIZE[0].min(screen[0]), MIN_SIZE[1].min(screen[1])];
return vec![egui::ViewportCommand::MinInnerSize(egui::vec2(min[0] / zoom, min[1] / zoom))];
/// The window's minimum in the system's points: [`MIN_SIZE`] is in the interface's, which `zoom` scales (at 2× a
/// 900 × 560 minimum holds the window to 1800 × 1120).
fn native_min(zoom: f32) -> [f32; 2] {
[MIN_SIZE[0] * zoom, MIN_SIZE[1] * zoom]
}
/// When the window's minimum (at `zoom`) is larger than `room` (system points) on either side: the command that lowers
/// it to `room`, in the interface's points. Nothing when the minimum fits.
fn min_within(room: [f32; 2], zoom: f32) -> Vec<egui::ViewportCommand> {
let min = native_min(zoom);
if min[0] > room[0] || min[1] > room[1] {
let lowered = [min[0].min(room[0]), min[1].min(room[1])];
return vec![egui::ViewportCommand::MinInnerSize(egui::vec2(lowered[0] / zoom, lowered[1] / zoom))];
}
Vec::new()
}
@@ -411,11 +418,13 @@ impl StartPlace {
// the window's minimum lowers the minimum to the screen)
let larger = |s: [f32; 2]| s[0] > screen[0] + SAME_WITHIN || s[1] > screen[1] + SAME_WITHIN;
if !seen.zoomed && (larger(size) || self.remembered.is_some_and(larger)) {
let side = |i: usize| (screen[i] * FIT_TO_SCREEN).max(MIN_SIZE[i]).min(screen[i]);
let fit = [side(0), side(1)];
// (`seen` is in the system's points, the commands in the interface's)
let zoom = interface_zoom(zoom);
let mut told = min_within(screen, zoom);
let min = native_min(zoom);
let side = |i: usize| (screen[i] * FIT_TO_SCREEN).max(min[i]).min(screen[i]);
let fit = [side(0), side(1)];
// a minimum larger than the fitted size (a small screen, a zoomed interface) is lowered to it first
let mut told = min_within(fit, zoom);
told.push(egui::ViewportCommand::InnerSize(egui::vec2(fit[0] / zoom, fit[1] / zoom)));
return told;
}
+11 -2
View File
@@ -641,7 +641,8 @@ fn the_window_is_maximized_once_it_shows_and_again_if_it_only_says_so() {
assert!(s.step(&Seen::default(), 5.5, 1.0).is_empty() && s.done());
// the interface zoomed 2×: the fitted size is asked for in its points, half the system's
let mut s = StartPlace::new(false);
assert_eq!(s.step(&big, 0.0, 2.0), vec![C::InnerSize(egui::vec2(864.0, 486.0))]);
// (its 900 × 560 minimum is 1800 × 1120 there, taller than the 1080 screen: lowered to the fitted size first)
assert_eq!(s.step(&big, 0.0, 2.0), vec![C::MinInnerSize(egui::vec2(900.0, 540.0)), C::InnerSize(egui::vec2(900.0, 540.0))]);
}
/// A screen smaller than the window's minimum (800 × 600 beside a 900 pt minimum): the window is fitted within it
@@ -655,7 +656,15 @@ fn a_window_on_a_screen_smaller_than_its_minimum_fits_within_the_screen() {
// remembered maximized on that screen: the minimum is lowered before it is maximized, or it would stay wider
let mut s = StartPlace::new(true);
s.step(&small, 0.0, 1.0);
assert_eq!(s.step(&small, 0.2, 2.0), vec![C::MinInnerSize(egui::vec2(400.0, 280.0)), C::Maximized(true)]);
assert_eq!(s.step(&small, 0.2, 2.0), vec![C::MinInnerSize(egui::vec2(400.0, 300.0)), C::Maximized(true)]);
// a screen larger than the minimum, but not than the minimum the zoomed interface makes of it (CodeRabbit on #2974)
let mut s = StartPlace::new(true);
let laptop = Seen { size: Some([1100.0, 700.0]), screen: Some([1200.0, 800.0]), ..Default::default() };
s.step(&laptop, 0.0, 2.0);
assert_eq!(s.step(&laptop, 0.2, 2.0), vec![C::MinInnerSize(egui::vec2(600.0, 400.0)), C::Maximized(true)]);
let mut s = StartPlace::new(false);
let wide = Seen { size: Some([1600.0, 1000.0]), ..laptop };
assert_eq!(s.step(&wide, 0.0, 2.0), vec![C::MinInnerSize(egui::vec2(600.0, 400.0)), C::InnerSize(egui::vec2(600.0, 400.0))]);
// a screen the minimum fits on keeps the minimum
let mut s = StartPlace::new(true);
s.step(&window([1300.0, 800.0]), 0.0, 1.0);