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 Feb 14, 2024
1 parent d99faba commit 0e1bcc2
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 @@ -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,
Expand Down

0 comments on commit 0e1bcc2

Please sign in to comment.