Fix `Response::clicked_elsewhere` not returning true sometimes (#5798)

* Closes #5794
This commit is contained in:
Lucas Meurer 2025-03-18 11:40:33 +01:00 committed by GitHub
parent d3c1ac3798
commit 626cd9e227
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 11 deletions

View File

@ -222,25 +222,32 @@ impl Response {
/// ///
/// Clicks on widgets contained in this one counts as clicks inside this widget, /// Clicks on widgets contained in this one counts as clicks inside this widget,
/// so that clicking a button in an area will not be considered as clicking "elsewhere" from the area. /// so that clicking a button in an area will not be considered as clicking "elsewhere" from the area.
///
/// Clicks on other layers above this widget *will* be considered as clicking elsewhere.
pub fn clicked_elsewhere(&self) -> bool { pub fn clicked_elsewhere(&self) -> bool {
let (pointer_interact_pos, any_click) = self
.ctx
.input(|i| (i.pointer.interact_pos(), i.pointer.any_click()));
// We do not use self.clicked(), because we want to catch all clicks within our frame, // We do not use self.clicked(), because we want to catch all clicks within our frame,
// even if we aren't clickable (or even enabled). // even if we aren't clickable (or even enabled).
// This is important for windows and such that should close then the user clicks elsewhere. // This is important for windows and such that should close then the user clicks elsewhere.
self.ctx.input(|i| { if any_click {
let pointer = &i.pointer; if self.contains_pointer() || self.hovered() {
false
if pointer.any_click() { } else if let Some(pos) = pointer_interact_pos {
if self.contains_pointer() || self.hovered() { let layer_under_pointer = self.ctx.layer_id_at(pos);
false if layer_under_pointer != Some(self.layer_id) {
} else if let Some(pos) = pointer.interact_pos() { true
!self.interact_rect.contains(pos)
} else { } else {
false // clicked without a pointer, weird !self.interact_rect.contains(pos)
} }
} else { } else {
false false // clicked without a pointer, weird
} }
}) } else {
false
}
} }
/// Was the widget enabled? /// Was the widget enabled?