Decouple cursor_position from Cache
Instead, we ask explicitly for it in the different `update` and `draw` methods. This way, the runtime can derive the logical position of the cursor from the source of truth.
This commit is contained in:
parent
bbdf558bd7
commit
f30a666dc8
6 changed files with 90 additions and 36 deletions
|
|
@ -148,6 +148,7 @@ pub fn run<A, E, C>(
|
|||
.expect("Open window");
|
||||
|
||||
let clipboard = Clipboard::new(&window);
|
||||
let mut cursor_position = winit::dpi::PhysicalPosition::new(-1.0, -1.0);
|
||||
let mut mouse_interaction = mouse::Interaction::default();
|
||||
let mut modifiers = winit::event::ModifiersState::default();
|
||||
|
||||
|
|
@ -171,6 +172,7 @@ pub fn run<A, E, C>(
|
|||
let mut state = program::State::new(
|
||||
application,
|
||||
viewport.logical_size(),
|
||||
conversion::cursor_position(cursor_position, viewport.scale_factor()),
|
||||
&mut renderer,
|
||||
&mut debug,
|
||||
);
|
||||
|
|
@ -184,8 +186,12 @@ pub fn run<A, E, C>(
|
|||
|
||||
let command = runtime.enter(|| {
|
||||
state.update(
|
||||
clipboard.as_ref().map(|c| c as _),
|
||||
viewport.logical_size(),
|
||||
conversion::cursor_position(
|
||||
cursor_position,
|
||||
viewport.scale_factor(),
|
||||
),
|
||||
clipboard.as_ref().map(|c| c as _),
|
||||
&mut renderer,
|
||||
&mut debug,
|
||||
)
|
||||
|
|
@ -240,11 +246,14 @@ pub fn run<A, E, C>(
|
|||
// The queue is empty, therefore this will never produce
|
||||
// a `Command`.
|
||||
//
|
||||
// TODO: Properly queue `WindowResized` and `CursorMoved`
|
||||
// events.
|
||||
// TODO: Properly queue `WindowResized`
|
||||
let _ = state.update(
|
||||
clipboard.as_ref().map(|c| c as _),
|
||||
viewport.logical_size(),
|
||||
conversion::cursor_position(
|
||||
cursor_position,
|
||||
viewport.scale_factor(),
|
||||
),
|
||||
clipboard.as_ref().map(|c| c as _),
|
||||
&mut renderer,
|
||||
&mut debug,
|
||||
);
|
||||
|
|
@ -304,6 +313,7 @@ pub fn run<A, E, C>(
|
|||
&window,
|
||||
scale_factor,
|
||||
control_flow,
|
||||
&mut cursor_position,
|
||||
&mut modifiers,
|
||||
&mut viewport,
|
||||
&mut resized,
|
||||
|
|
@ -332,6 +342,7 @@ pub fn handle_window_event(
|
|||
window: &winit::window::Window,
|
||||
scale_factor: f64,
|
||||
control_flow: &mut winit::event_loop::ControlFlow,
|
||||
cursor_position: &mut winit::dpi::PhysicalPosition<f64>,
|
||||
modifiers: &mut winit::event::ModifiersState,
|
||||
viewport: &mut Viewport,
|
||||
resized: &mut bool,
|
||||
|
|
@ -352,6 +363,9 @@ pub fn handle_window_event(
|
|||
WindowEvent::CloseRequested => {
|
||||
*control_flow = ControlFlow::Exit;
|
||||
}
|
||||
WindowEvent::CursorMoved { position, .. } => {
|
||||
*cursor_position = *position;
|
||||
}
|
||||
WindowEvent::ModifiersChanged(new_modifiers) => {
|
||||
*modifiers = *new_modifiers;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue