Conversation
|
Preview available at https://egui-pr-preview.github.io/pr/7383-lucasfix-manual-popup-close |
|
|
||
| let closed_by_click = match close_behavior { | ||
| PopupCloseBehavior::CloseOnClick => widget_clicked_elsewhere, | ||
| PopupCloseBehavior::CloseOnClick => close_click, |
There was a problem hiding this comment.
Shouldn't this close on any click?
| PopupCloseBehavior::CloseOnClick => close_click, | |
| PopupCloseBehavior::CloseOnClick => ctx.input(|i| i.pointer.any_click()), |
There was a problem hiding this comment.
We need to check if the click was the click that was used to open the popup, so we don't immediately close it again.
Previously we did this via the widget_clicked_elsewhere, which is also what we did in the old popup api. But I just realized this also won't work when using Popup::new so I came up with a better check. Now, on click, the popup will only close when it was already open last frame (by checking if a reasponse exists via ctx.read_response).
|
|
||
| let closed_by_click = match close_behavior { | ||
| PopupCloseBehavior::CloseOnClick => widget_clicked_elsewhere, | ||
| PopupCloseBehavior::CloseOnClick => close_click, |
Fixes manually created popups (via `Popup::new`) not closing, since
widget_clicked_elsewhere was always false.
This example would never close:
```rs
let mut open = true;
eframe::run_simple_native("My egui App", options, move |ctx, _frame| {
egui::CentralPanel::default().show(ctx, |ui| {
let response = egui::Popup::new(
Id::new("popup"),
ctx.clone(),
PopupAnchor::Position(Pos2::new(10.0, 10.0)),
LayerId::new(Order::Foreground, Id::new("popup")),
)
.open(open)
.show(|ui| {
ui.label("This is a popup!");
ui.label("You can put anything in here.");
});
if let Some(response) = response {
if response.response.should_close() {
open = false;
}
}
});
})
```
I also noticed that the Color submenu in the popups example had a double
arrow (must have been broken in the atoms PR):
<img width="248" height="110" alt="Screenshot 2025-08-07 at 13 42 28"
src="https://github.com/user-attachments/assets/a4e0c267-ae71-4b2c-a1f0-f53f9662d026"
/>
Also fixed this in the PR.
Fixes manually created popups (via `Popup::new`) not closing, since
widget_clicked_elsewhere was always false.
This example would never close:
```rs
let mut open = true;
eframe::run_simple_native("My egui App", options, move |ctx, _frame| {
egui::CentralPanel::default().show(ctx, |ui| {
let response = egui::Popup::new(
Id::new("popup"),
ctx.clone(),
PopupAnchor::Position(Pos2::new(10.0, 10.0)),
LayerId::new(Order::Foreground, Id::new("popup")),
)
.open(open)
.show(|ui| {
ui.label("This is a popup!");
ui.label("You can put anything in here.");
});
if let Some(response) = response {
if response.response.should_close() {
open = false;
}
}
});
})
```
I also noticed that the Color submenu in the popups example had a double
arrow (must have been broken in the atoms PR):
<img width="248" height="110" alt="Screenshot 2025-08-07 at 13 42 28"
src="https://github.com/user-attachments/assets/a4e0c267-ae71-4b2c-a1f0-f53f9662d026"
/>
Also fixed this in the PR.
Fixes manually created popups (via
Popup::new) not closing, since widget_clicked_elsewhere was always false.This example would never close:
I also noticed that the Color submenu in the popups example had a double arrow (must have been broken in the atoms PR):
Also fixed this in the PR.