Closed dogunbound closed 2 years ago
After some more testing, I think it's the window.position()
function that is faulty
This properly moves the window.
use sfml::{graphics::RenderWindow, system::Vector2i, window::Style};
use std::thread::sleep;
use std::time::Duration;
fn main() {
// Create a new window
let mut window = RenderWindow::new((1280, 720), "Test", Style::DEFAULT, &Default::default());
let (min, max, step) = (0, 1000, 50);
let mut current_step = step;
let mut current_position = Vector2i::new(min, min);
while window.is_open() {
current_step = if current_position.x <= min {
step
} else if current_position.x >= max {
-step
} else {
current_step
};
current_position.x += current_step;
current_position.y += current_step;
window.set_position(current_position);
sleep(Duration::from_millis(250));
}
}
It seems highly likely that the position change is simply not instantaneous. You need to wait for the window to change to the new position before you can query the new position.
window.set_position(new_window_position);
while new_window_position != window.position() {
eprintln!("Waiting");
}
assert_eq!(new_window_position, window.position());
This prints a single "Waiting" for me. It's so fast, it has happened right after printing "waiting". It's just not instantaneous.
Min reproducible code:
assert_eq! panics.