From def09c245513f3f1c9b848dca6244ba206ac291a Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 27 Mar 2021 16:50:35 +0100 Subject: [PATCH] Don't close colopicker and other popups when clicking inside of them --- CHANGELOG.md | 11 ++++++----- egui/src/response.rs | 10 +++++++++- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2235cbed..27ff1445 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,13 +21,14 @@ NOTE: `eframe`, `egui_web` and `egui_glium` has their own changelogs! * Add `Slider::new` and `DragValue::new` to replace old type-specific constructors. ### Changed 🔧 -* `kb_focus` is now just called `focus` +* `kb_focus` is now just called `focus`. ### Fixed 🐛 -* Fix some bugs related to centered layouts -* Fixed secondary-click to open a menu -* [Fix panic for zero-range sliders and zero-speed drag values](https://github.com/emilk/egui/pull/216) -* Fix false id clash error for wrapping text +* Fix some bugs related to centered layouts. +* Fixed secondary-click to open a menu. +* [Fix panic for zero-range sliders and zero-speed drag values](https://github.com/emilk/egui/pull/216). +* Fix false id clash error for wrapping text. +* Fix bug that would close a popup (e.g. the color picker) when clicking inside of it. ### Deprecated ☢️ * Deprectated `combo_box_with_label` in favor of new `ComboBox`. diff --git a/egui/src/response.rs b/egui/src/response.rs index 29ddc74d..73b65c4d 100644 --- a/egui/src/response.rs +++ b/egui/src/response.rs @@ -135,7 +135,15 @@ impl Response { /// `true` if there was a click *outside* this widget this frame. pub fn clicked_elsewhere(&self) -> bool { - !self.clicked() && self.ctx.input().pointer.any_click() + // We do not use self.clicked(), because we want to catch all click within our frame, + // even if we aren't clickable. This is important for windows and such that should close + // then the user clicks elsewhere. + let pointer = &self.ctx.input().pointer; + if let Some(pos) = pointer.latest_pos() { + pointer.any_click() && !self.rect.contains(pos) + } else { + false + } } /// Was the widget enabled?