1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-29 04:40:03 -04:00

Fix ui.response().interact(Sense::click()) being flakey (#7713)

This fixes calls to `ui.response().interact(Sense::click())` being
flakey. Since egui checks widget interactions at the beginning of the
frame, based on the responses from last frame, we need to ensure that we
always call `create_widget` on `interact` calls, otherwise there can be
a feedback loop where the `Sense` egui acts on flips back and forth
between frames.

Without the fix in `interact`, both the asserts in the new test fail.

Here is a video where I experienced the bug, showing the sense switching
every frame. Every other click would fail to be detected.


https://github.com/user-attachments/assets/6be7ca0e-b50f-4d30-bf87-bbb80c319f3b

Also note, usually it's better to use `UiBuilder::sense()` to give a Ui
some sense, but sometimes you don't have the flexibility, e.g. in a `Ui`
callback from some code external to your project.
This commit is contained in:
Lucas Meurer
2025-11-13 13:52:13 +01:00
committed by GitHub
parent 9ef610e16b
commit ecee85fc6b
2 changed files with 47 additions and 5 deletions

View File

@@ -724,10 +724,9 @@ impl Response {
/// ```
#[must_use]
pub fn interact(&self, sense: Sense) -> Self {
if (self.sense | sense) == self.sense {
// Early-out: we already sense everything we need to sense.
return self.clone();
}
// We could check here if the new Sense equals the old one to avoid the extra create_widget
// call. But that would break calling `interact` on a response from `Context::read_response`
// or `Ui::response`. (See https://github.com/emilk/egui/pull/7713 for more details.)
self.ctx.create_widget(
WidgetRect {