Skip to content

Commit

Permalink
Only pass events to input handler if egui doesn't want exclusive ac…
Browse files Browse the repository at this point in the history
…cess.

This now seems to work correctly, whereas the last time I tried to
implement this functionality it didn't, IIRC.

Not sure why but might be because I'm restricting it to affecting the
"input handler"-related events only? And/or the `egui` monitored area
might be restricted to a narrower part of the window?

Anyway, this means that interacting with the UI now doesn't also
affect the model view, e.g. mouse drag can change values without
*also* rotating model. :)
  • Loading branch information
follower committed Jul 5, 2022
1 parent be03aea commit 61db1dc
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions crates/fj-window/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pub fn run(

//

let mut egui_wants_exclusive = false;

if let Event::WindowEvent {
event: window_event,
..
Expand All @@ -103,11 +105,12 @@ pub fn run(
// a title bar that overlaps the model then both the model & window
// get moved.
//
// TODO: Revisit this.
// DONE: Revisit this. (Added `egui_wants_exclusive` which actually seems
// to work as expected now.)
//
// TODO: Encapsulate the egui state/context access better.
//
renderer
egui_wants_exclusive = renderer
.egui
.winit_state
.on_event(&renderer.egui.context, &window_event);
Expand Down Expand Up @@ -240,17 +243,20 @@ pub fn run(
_ => None,
};

if let (Some(event), Some(shape), Some(camera)) =
(event, &shape, &mut camera)
{
input_handler.handle_event(
event,
window.size(),
now,
&shape.mesh,
camera,
&mut actions,
);
if !egui_wants_exclusive {
if let (Some(event), Some(shape), Some(camera)) =
(event, &shape, &mut camera)
{
input_handler.handle_event(
event,
window.size(),
now,
&shape.mesh,
camera,
&mut actions,
);
}
}
}

if actions.exit {
Expand Down

0 comments on commit 61db1dc

Please sign in to comment.