Skip to content

Commit

Permalink
Avoid interacting twice when not required (#4041)
Browse files Browse the repository at this point in the history
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.).
  • Loading branch information
abey79 authored and emilk committed Feb 14, 2024
1 parent ed5fe01 commit 1ce4f05
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions crates/egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1ce4f05

Please sign in to comment.