LR-BEHAV-WINDOW: a window fitted to a screen smaller than its minimum stays within it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
OneSlipsandClaude Opus 5.5 committed 2026-10-28 07:04:12 +10:00
1 parent e902fae5f0
commit fb4bd21598
2 files changed
+26 -4

No files matched your search

+12 -4
View File
@@ -382,12 +382,20 @@ impl StartPlace {
let shown = *self.shown.get_or_insert(now);
if !self.maximize {
self.done = true;
// remembered larger than this screen: fitted to it
// remembered larger than this screen: fitted to it, and never larger than it (a screen smaller than
// the window's minimum lowers the minimum to the screen)
if !seen.zoomed && (size[0] > screen[0] + SAME_WITHIN || size[1] > screen[1] + SAME_WITHIN) {
let fit = [(screen[0] * FIT_TO_SCREEN).max(MIN_SIZE[0]), (screen[1] * FIT_TO_SCREEN).max(MIN_SIZE[1])];
// (`seen` is in the system's points, the command in the interface's)
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 = if zoom.is_finite() && zoom > 0.0 { zoom } else { 1.0 };
return vec![egui::ViewportCommand::InnerSize(egui::vec2(fit[0] / zoom, fit[1] / zoom))];
let mut told = Vec::new();
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])];
told.push(egui::ViewportCommand::MinInnerSize(egui::vec2(min[0] / zoom, min[1] / zoom)));
}
told.push(egui::ViewportCommand::InnerSize(egui::vec2(fit[0] / zoom, fit[1] / zoom)));
return told;
}
return Vec::new();
}
+14
View File
@@ -643,3 +643,17 @@ fn the_window_is_maximized_once_it_shows_and_again_if_it_only_says_so() {
let mut s = StartPlace::new(false);
assert_eq!(s.step(&big, 0.0, 2.0), vec![C::InnerSize(egui::vec2(864.0, 486.0))]);
}
/// A screen smaller than the window's minimum (800 × 600 beside a 900 pt minimum): the window is fitted within it
/// and the minimum is lowered to it, so it never asks for more than the screen (CodeRabbit on #2974).
#[test]
fn a_window_on_a_screen_smaller_than_its_minimum_fits_within_the_screen() {
use egui::ViewportCommand as C;
let mut s = StartPlace::new(false);
let small = Seen { size: Some([900.0, 560.0]), screen: Some([800.0, 600.0]), ..Default::default() };
assert_eq!(s.step(&small, 0.0, 1.0), vec![C::MinInnerSize(egui::vec2(800.0, 560.0)), C::InnerSize(egui::vec2(800.0, 560.0))]);
// a screen the minimum fits on keeps the minimum
let mut s = StartPlace::new(false);
let big = Seen { size: Some([3000.0, 2000.0]), screen: Some([1920.0, 1080.0]), ..Default::default() };
assert_eq!(s.step(&big, 0.0, 1.0), vec![C::InnerSize(egui::vec2(1728.0, 972.0))]);
}