I'm implementing a Rust alternative to .NET's DragMove method however the result causes the application to flicker between two relative positions.
See screencast and sample project.
Code I'm using to perform the drag move:
let mut mouse_down = false;
let mut last_pos: Option<PhysicalPosition<f64>> = None;
event_loop.run(move |event, _, control_flow| match event {
Event::WindowEvent {
event: WindowEvent::CursorMoved {
position,
..
},
..
} => {
let gl_window = display.gl_window();
let window = gl_window.window();
if mouse_down {
if last_pos.is_some() {
let previous_pos = last_pos.unwrap();
let delta_x = previous_pos.x - position.x;
let delta_y = previous_pos.y - position.y;
window.set_outer_position(PhysicalPosition::new(position.x + delta_x, position.y + delta_y));
}
last_pos = Some(position);
}
}
Event::WindowEvent {
event: WindowEvent::MouseInput{
state,
button,
..
},
..
} => {
mouse_down = button == MouseButton::Left && state == ElementState::Pressed;
if !mouse_down {
last_pos = None;
}
}
_ => {}
});