summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Beyeler <49431240+abey79@users.noreply.github.com>2024-02-14 09:07:33 +0100
committerEmil Ernerfeldt <emil.ernerfeldt@gmail.com>2024-02-14 10:40:24 +0100
commit1ce4f0547226a8149489a38d9ddcc907473be3e9 (patch)
tree926d5ca271e770e4f6a7c12b57197b9a970e77c3
parented5fe015359d59fe4c09310fb9a3771c06ec7eb4 (diff)
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.).
-rw-r--r--crates/egui/src/response.rs7
1 files changed, 7 insertions, 0 deletions
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)