mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-28 09:19:25 +01:00
LR-BEHAV-WINDOW: a window remembered maximized on a screen smaller than its minimum lowers the minimum before it is maximized (CodeRabbit, #2974)
The fit branch already lowered MinInnerSize to a small screen; the deferred maximize did not, so the 900 x 560 minimum could leave the maximized window wider than the screen. Both now share min_within. Test: a_window_on_a_screen_smaller_than_its_minimum_fits_within_the_screen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fa172a15cd
commit
d69d76d331
2 files changed
+28
-7
No files matched your search
@@ -327,6 +327,21 @@ const MAXIMIZE_CHECK_SECONDS: f64 = 0.6;
|
||||
/// borders Windows keeps off screen, take the rest).
|
||||
const MAXIMIZED_ACROSS: f32 = 0.9;
|
||||
const MAXIMIZED_DOWN: f32 = 0.75;
|
||||
/// `zoom` when it is a usable interface zoom, else 1.
|
||||
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))];
|
||||
}
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
/// A window opened larger than its screen is fitted to this much of it.
|
||||
const FIT_TO_SCREEN: f32 = 0.9;
|
||||
/// How long after its first frame the window is placed at most: one that stays unseen, full
|
||||
@@ -399,12 +414,8 @@ impl StartPlace {
|
||||
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 };
|
||||
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)));
|
||||
}
|
||||
let zoom = interface_zoom(zoom);
|
||||
let mut told = min_within(screen, zoom);
|
||||
told.push(egui::ViewportCommand::InnerSize(egui::vec2(fit[0] / zoom, fit[1] / zoom)));
|
||||
return told;
|
||||
}
|
||||
@@ -414,7 +425,10 @@ impl StartPlace {
|
||||
match self.asked {
|
||||
None if now - shown >= MAXIMIZE_AFTER_SECONDS => {
|
||||
self.asked = Some(now);
|
||||
vec![egui::ViewportCommand::Maximized(true)]
|
||||
// a screen smaller than the window's minimum lowers it first, or the maximized window would stay wider
|
||||
let mut told = min_within(screen, interface_zoom(zoom));
|
||||
told.push(egui::ViewportCommand::Maximized(true));
|
||||
told
|
||||
}
|
||||
None => Vec::new(),
|
||||
Some(at) if now - at < MAXIMIZE_CHECK_SECONDS => Vec::new(),
|
||||
|
||||
@@ -652,7 +652,14 @@ fn a_window_on_a_screen_smaller_than_its_minimum_fits_within_the_screen() {
|
||||
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))]);
|
||||
// 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)]);
|
||||
// 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);
|
||||
assert_eq!(s.step(&window([1300.0, 800.0]), 0.2, 1.0), vec![C::Maximized(true)]);
|
||||
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))]);
|
||||
|
||||
Reference in new issue
Block a user