mirror of
https://github.com/emilk/egui.git
synced 2026-06-26 22:53:14 -04:00
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.).
This commit is contained in:
committed by
Emil Ernerfeldt
parent
ed5fe01535
commit
1ce4f05472
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user