mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-28 09:19:25 +01:00
window placement: the time limit runs while the window is hidden, so a hidden start ends placement and its repaints (CodeRabbit on #2974)
This commit is contained in:
1 parent
ba6e5423d5
commit
e7d729535f
3 files changed
+34
-3
No files matched your search
@@ -243,6 +243,9 @@ impl PrefsWriter {
|
||||
for command in start.step(&seen, at, zoom) {
|
||||
ctx.send_viewport_cmd(command);
|
||||
}
|
||||
} else {
|
||||
// (hidden: nothing to place by, but the time limit still runs)
|
||||
start.idle(at);
|
||||
}
|
||||
match start.waits() {
|
||||
Some(wait) => ctx.request_repaint_after(wait),
|
||||
|
||||
@@ -402,9 +402,7 @@ impl StartPlace {
|
||||
return Vec::new();
|
||||
}
|
||||
// (not shown yet, its screen unknown, full screen or minimized: wait, but not for ever)
|
||||
let first = *self.first_step.get_or_insert(now);
|
||||
if now - first > PLACE_WITHIN_SECONDS {
|
||||
self.done = true;
|
||||
if self.out_of_time(now) {
|
||||
return Vec::new();
|
||||
}
|
||||
if seen.full_screen || seen.minimized {
|
||||
@@ -458,6 +456,23 @@ impl StartPlace {
|
||||
}
|
||||
}
|
||||
|
||||
/// A pass with nothing to place by (the window is hidden: its size is stale) at time `now`: the time limit
|
||||
/// still runs, so a window kept hidden ends the placement and stops asking to be looked at.
|
||||
pub fn idle(&mut self, now: f64) {
|
||||
if !self.done {
|
||||
self.out_of_time(now);
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether placing has gone on for longer than it may (it is then done); its clock starts at the first pass.
|
||||
fn out_of_time(&mut self, now: f64) -> bool {
|
||||
let first = *self.first_step.get_or_insert(now);
|
||||
if now - first > PLACE_WITHIN_SECONDS {
|
||||
self.done = true;
|
||||
}
|
||||
self.done
|
||||
}
|
||||
|
||||
/// When to look again while it waits (the app may have nothing else to draw).
|
||||
pub fn waits(&self) -> Option<std::time::Duration> {
|
||||
(!self.done).then(|| std::time::Duration::from_millis(100))
|
||||
|
||||
@@ -689,3 +689,16 @@ fn a_window_clamped_to_its_screen_before_it_shows_is_still_fitted() {
|
||||
let mut s = StartPlace::new(false);
|
||||
assert!(s.step(&clamped, 0.0, 1.0).is_empty());
|
||||
}
|
||||
|
||||
/// A window kept hidden while it is being placed still ends the placement in time, and then stops asking to be
|
||||
/// looked at (CodeRabbit on #2974).
|
||||
#[test]
|
||||
fn placement_ends_in_time_while_the_window_is_hidden() {
|
||||
let mut s = StartPlace::new(true);
|
||||
s.idle(0.0);
|
||||
assert!(!s.done() && s.waits().is_some(), "still within its time");
|
||||
s.idle(PLACE_WITHIN_SECONDS + 0.1);
|
||||
assert!(s.done());
|
||||
assert_eq!(s.waits(), None);
|
||||
assert!(s.step(&window([1300.0, 800.0]), PLACE_WITHIN_SECONDS + 0.2, 1.0).is_empty());
|
||||
}
|
||||
Reference in new issue
Block a user