-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mouse Inputs Passthrough from egui
to bevy_panorbit_camera
#75
Comments
Hey, thanks for the repro. This appears to be a quirk of egui, haven't found a solution yet. So, bevy_panorbit_camera tracks a boolean value in The problem is that these values are false when they should seemingly be true. I tested your repro and logged to console whenever First I tested without your half-workaround, i.e. using This first video shows what happens when both scrolling and dragging 'pass through' the egui side panel. You can see that Screen.Recording.2024-05-11.at.09.27.56.movThe second video shows the half-workaround. You can see the difference is that on hover Screen.Recording.2024-05-11.at.09.28.52.movMy conclusion so far is that there's nothing this plugin can do - it's a matter of P.S. I tried moving all panorbit's systems into |
@Plonq after some investigation, I've found one solution that you can implement for now, the following code: let new_wants_focus = windows.iter().any(|window| {
let ctx = contexts.ctx_for_window_mut(window);
ctx.wants_pointer_input() || ctx.wants_keyboard_input()
}); Should also check if the cursor has entered an egui area: let new_wants_focus = windows.iter().any(|window| {
let ctx = contexts.ctx_for_window_mut(window);
ctx.wants_pointer_input() || ctx.wants_keyboard_input() || ctx.is_pointer_over_area()
}); Which then results in the following behavior, which I would say is most wanted/expected: jc2_tools_nd8WBclE0C.mp4Do note however, as mentioned here, this should occur in the frame as late as possible. So perhaps we should combine it with My apologies for the delay on triaging this, it's been a busy week. I've also pinged the |
That is a decent temporary workaround, but it's not ideal. If you start dragging outside egui, and drag over egui, it should continue that drag operation (e.g. rotating the camera). This is a very common UX pattern. For example if you click and drag a scrollbar you can move the mouse anywhere - it doesn't just stop working if you move your mouse outside the scrollbar track. For this reason, I have implemented it as an optional configuration, disabled by default. See #76, which has been released in v0.18.1 |
Two possible "solutions" to avoid the camera handling stopping to work if the cursor quit the Bevy viewport:
Unfortunately this is platform specific and even depends on the windowing system (X11 or Wayland) on Linux. |
I don't particularly like the sound of either of those solutions.
The best idea I have is to save some sort of state that regarding the current 'gesture', e.g. 'panning', and then if currently panning, ignore the 'egui wants focus' check. When the user lets the mouse go, the 'panning' gesture stops and thus the 'egui wants focus' check is once again in effect. |
One solution I found for
This fixes this issue and another related (invert case):
Edit: |
Thanks for commenting with this idea! I will try it out. Or if you're willing I'd be glad to accept a PR.
Interesting. I'm guessing you used a lot of the same code? I wonder whether it's a shared problem, or something unique about your plugin. I'd expect to have bug reports about it if people were experiencing that with bevy_panorbit_camera. Have you replicated with this plugin? |
Yes, I removed the smoothing. I also added a Fly camera controller, the possibility to switch between those, the possibility to set the viewpoint (top, bottom, left, right, front and rear) and the possibility to frame the camera view around entities. For the PR, I do not have time available this week, but I will try this week-end. For the egui focus issue: Yes I used a lot of the same code. I did not replicated the issue with |
I implemented my "solution" in PR #81 I tried to reproduce the other issue in |
Trying out this plugin now and hitting this. I tried the |
We will need more informations:
Edit: Sorry, I am a bit confused. I was thinking this issue was related to the @SK83RJOSH comment and video (first comment, not original post). Regarding the movement stopping when the movement is started on top of the viewport but moved on top of the GUI. Actually the original post is more related to what I call "the other issue" where the computing of "does egui wants the focus" returns wrong results (sometimes true when it is false, sometimes false when it is true). I fixed this in my code (another camera controller plugin: Second Edit: Note that this behavior is unrelated to the egui issue linked by @SK83RJOSH and which can be worked around by checking if the pointer is over an egui |
@nixpulvis Can you clarify which issue you are having? A video would be helpful. |
I tried with both the recording.webm |
@nixpulvis the recording/video is broken for me |
The video is working for me. This looks like the OP issue (which I mistakenly called "the other issue"). Where the check to see if egui wants the focus returns false even when it should be true. Note that this behavior is normal and expected without the use of the With the feature enabled, it is quite rare and difficult to replicate. And the only times I replicated it, it was not consistent sometimes being present or not varying between launch of the executable (without code change/recompilation). Also it was with another camera controller crate (but with identical check/code to see if egui wants the focus). Can you try using the code from this git repository (and not the crates.io version if it is the case) and modify the scheduling of the diff --git a/src/lib.rs b/src/lib.rs
index eba6521..a23c82f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -66,9 +66,9 @@ impl Plugin for PanOrbitCameraPlugin {
app.init_resource::<EguiWantsFocus>()
.init_resource::<EguiFocusIncludesHover>()
.add_systems(
- PostUpdate,
+ PreUpdate,
egui::check_egui_wants_focus
- .after(EguiSet::InitContexts)
+ .after(EguiSet::BeginFrame)
.before(PanOrbitCameraSystemSet),
);
} As @Plonq said, there is a big chance that this issue is not coming from to this plugin but either from |
@thmxv unfortunately that patch on top of bdf1ccb doesn't change anything for me. You mentioned not being able to reproduce. Perhaps looking at my code could shed some light? I'm still learning both Bevy and egui, so I'm not sure I'm doing everything correctly either, but still I think this should work. There's not much special going on here from my end. Anyway, here's where I'm using it in case it helps: https://github.com/nixpulvis/galos/tree/master/starmap I'm also happy to try some more debugging for you. |
This call to bevy_panorbit_camera/src/egui.rs Line 42 in bdf1ccb
|
@nixpulvis, thanks, I will try your code to replicate the issue. On a quick glance I did not spotted anything that could cause it. The call to Edit: A search for |
Oh wow, good call. I should have checked that. Let me resolve the issue and report back. |
Boom, that was it! Thanks for catching that. It looks like I was running |
Glad a solution was found, and thanks @thmxv for helping |
Turns out |
When not directly scrolling / dragging / clicking egui ui elements, all inputs get passed through to
bevy_panorbit_camera
when using the following code to add ui systems:As demonstrated here:
bevy_panorbit_camera_repo_ZH28m2hvHm.mp4
This appears to be a scheduling issue, and doing the following somewhat resolves the issue and blocks scroll events, but not mouse drag events:
As demonstrated here:
bevy_panorbit_camera_repo_0tAfLcCWZ4.mp4
Using the solution mentioned in #39 yields no further improvements.
Here is the code used for both of the above:
repro.zip
The text was updated successfully, but these errors were encountered: