From 1ce4f0547226a8149489a38d9ddcc907473be3e9 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: 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 291ba0d0..b599f9fd 100644 --- a/crates/egui/src/response.rs +++ b/crates/egui/src/response.rs @@ -601,6 +601,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(); + } + // Temporary hack for 0.26.1 to avoid breaking change. let clip_rect = self.ctx.graphics(|g| { g.get(self.layer_id) -- cgit v1.2.3-70-g09d2