From 0e1bcc2c1c58295ce45184d3440378b4a7431c44 Mon Sep 17 00:00:00 2001 From: Antoine Beyeler <49431240+abey79@users.noreply.github.com> Date: Wed, 14 Feb 2024 09:07:33 +0100 Subject: [PATCH] Avoid interacting twice when not required (#4041) This PR short-circuits `Response::interact()` when the `Response` has already been sufficiently "sensed" already. In some circumstance, this can avoid unnecessarily registering another widget rect that may mask some other widget. One such instance is Rerun's `ListItem`. Calling `context_menu()` on its response would call `interact` and, in turn, mask its sub-widget (collapsing triangle, show/hide buttons, etc.). --- crates/egui/src/response.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/egui/src/response.rs b/crates/egui/src/response.rs index 073ab5615b2..2cef13e93f6 100644 --- a/crates/egui/src/response.rs +++ b/crates/egui/src/response.rs @@ -610,6 +610,13 @@ impl Response { /// ``` #[must_use] pub fn interact(&self, sense: Sense) -> Self { + // Test if we must sense something new compared to what we have already sensed. If not, then + // we can return early. This may avoid unnecessarily "masking" some widgets with unneeded + // interactions. + if (self.sense | sense) == self.sense { + return self.clone(); + } + self.ctx.interact_with_hovered( self.layer_id, self.id,