-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Window contents can sometimes be affected by mouse interaction outside the window #4349
Comments
It would be good for emilk to fix this. This is a problem that has existed for a long time. The area of It will be easier to check the problem using the example below. struct TestApp;
impl eframe::App for TestApp {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::Window::new("test")
.scroll(true)
.resizable(true)
.show(ctx, |ui| {
ui.label("looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong");
ui.collapsing(
"looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
|_ui| {},
);
});
egui::CentralPanel::default().show(ctx, |ui| {
ctx.options_mut(|options| {
options.tessellation_options.debug_paint_clip_rects = true;
});
ctx.settings_ui(ui);
});
}
}
fn main() {
let _result = eframe::run_native(
"Test",
Default::default(),
Box::new(|_cc| Box::new(TestApp)),
);
} |
I have updated the code to reproduce the issue, turns out that all that is needed is something that allocates space within a window. |
@emilk It seems that the |
Yup, somewhere the |
I looked a bit more into it and couldn't find any reference to a egui/crates/egui/src/containers/scroll_area.rs Lines 591 to 594 in a287921
It does this based on the rectangle returned by One fix that I could think of is to store the last content size and use it for the drag input detection on the next frame. Let me know if that would be an okay solution or if you have a different suggestion. |
I think you're right in your conclusion @s-nie. Storing the content size or Another way to do it is to leverage // (NOTE: `inner_rect` here is a bad estimate, which is what is causing the bug)
let content_response = ui.interact(inner_rect, id.with("area"), Sense::drag()); With let drag_area_id = id.with("area");
let content_response = ui.ctx().read_response(drag_area_id); And then at the end of // (NOTE: `inner_rect` here is the _actual_, correct final rect of the scroll area)
// Result ignored, but read at the start of next frame with `read_response`.
let _ = ui.interact(inner_rect, drag_area_id, Sense::drag()); Maybe this could be easier, maybe not. |
That worked great! I'll open a PR. |
This fixes a bug which sometimes would make it possible to interact with widgets that were outside the parent clip_rect. Interaction with a widget is done with the `interact_rect`, which is the intersection of the widget rect and the parent clip rect. If these rectangles are disjoint (the widget is outside the parent clip rect), this results in a _negative rectangle_ (a rectangle with a negative width and/or height). The distance tests for negative rectangles were broken, causing the bug. * This is part of solving #4475 * It is also likely this would have solved #4349 (which now has another fix for it) ### Breaking changes `Rect::distance_to_pos`, `distance_sq_to_pos`, `signed_distance_to_pos` now all return `f32::INFINITY` if the rectangle is negative.
This fixes a bug which sometimes would make it possible to interact with widgets that were outside the parent clip_rect. Interaction with a widget is done with the `interact_rect`, which is the intersection of the widget rect and the parent clip rect. If these rectangles are disjoint (the widget is outside the parent clip rect), this results in a _negative rectangle_ (a rectangle with a negative width and/or height). The distance tests for negative rectangles were broken, causing the bug. * This is part of solving emilk#4475 * It is also likely this would have solved emilk#4349 (which now has another fix for it) ### Breaking changes `Rect::distance_to_pos`, `distance_sq_to_pos`, `signed_distance_to_pos` now all return `f32::INFINITY` if the rectangle is negative.
egui version 0.27.2, also present on master
Describe the bug
Interactions outside a window can sometimes interact with elements inside the window if they allocate enough space.
To Reproduce
Expected behavior
The drag affects whatever is inside the window.
Screenshots
demo.mp4
The text was updated successfully, but these errors were encountered: