1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 05:10:03 -04:00

Fix manual Popup not closing (#7383)

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.
This commit is contained in:
Lucas Meurer
2025-08-07 14:18:04 +02:00
committed by GitHub
parent 36a4981f29
commit e8e99a0bb6
2 changed files with 25 additions and 22 deletions

View File

@@ -2,8 +2,8 @@ use crate::rust_view_ui;
use egui::color_picker::{Alpha, color_picker_color32};
use egui::containers::menu::{MenuConfig, SubMenuButton};
use egui::{
Align, Align2, ComboBox, Frame, Id, Layout, Popup, PopupCloseBehavior, RectAlign, RichText,
Tooltip, Ui, UiBuilder, include_image,
Align, Align2, Atom, Button, ComboBox, Frame, Id, Layout, Popup, PopupCloseBehavior, RectAlign,
RichText, Tooltip, Ui, UiBuilder, include_image,
};
/// Showcase [`Popup`].
@@ -79,13 +79,15 @@ impl PopupsDemo {
} else {
egui::Color32::WHITE
};
let mut color_button =
SubMenuButton::new(RichText::new("Background").color(text_color));
color_button.button = color_button.button.fill(self.color);
color_button.button = color_button
.button
.right_text(RichText::new(SubMenuButton::RIGHT_ARROW).color(text_color));
color_button.ui(ui, |ui| {
let button = Button::new((
RichText::new("Background").color(text_color),
Atom::grow(),
RichText::new(SubMenuButton::RIGHT_ARROW).color(text_color),
))
.fill(self.color);
SubMenuButton::from_button(button).ui(ui, |ui| {
ui.spacing_mut().slider_width = 200.0;
color_picker_color32(ui, &mut self.color, Alpha::Opaque);
});