Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

juancampa
Copy link
Contributor

@juancampa juancampa commented Jun 23, 2024

BEFORE

Screenshot.2024-06-23.at.18.41.41.mp4

AFTER

Screenshot.2024-06-23.at.18.56.01.mp4

Notice that WRONG flashes for one frame. That's expected because on the frame the combo box disappears, any_popup_open still returns true, since we don't know it has disappeared until the end of the frame.

/// The bool is used to detect if a popup stopped showing before calling close_popup
#[cfg_attr(feature = "persistence", serde(skip))]
popup: Option<Id>,
popup: Option<(Id, std::sync::Arc<AtomicBool>)>,
Copy link
Contributor Author

@juancampa juancampa Jun 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using an AtomicBool here because I didn't want to change is_popup_open to take &mut self.

An alternative is to add another function, something like retain_popup(&mut self) that explicitly sets a retained bool to true. But would will be a breaking change and existing apps will need to call it or popups will only last for one frame.

I'm open to suggestions.

Copy link
Owner

@emilk emilk Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not at all obvious from reading this what the bool is for though., or why it is behind an Arc.

It seems to answer the question "Was is_popup_open called for this this frame?", i.e. "Does anyone care that this is open?".

I suggest making a struct with a name field so the motivation behind this can be documented.

We should also document that if is_popup_open is not called during a frame, the popup auto-closes.
Since this in fact makes it change state, I think making it take a &mut makes sense.

So I suggest

struct OpenPopup {
    id: Id,
    shown_this_frame: bool,
}

…

popup: Option<OpenPopup>,

@juancampa juancampa marked this pull request as ready for review June 23, 2024 23:11
@juancampa
Copy link
Contributor Author

Closing in favor of #5814

@juancampa juancampa closed this Mar 17, 2025
lucasmerlin pushed a commit that referenced this pull request Mar 20, 2025
Breaking changes:
- When using the Memory::popup state, it's now required to call
keep_popup_open each frame or the popup will close.
- Usually handled by the `Popup` struct, but required for custom popups
using the state in `Memory` directly

-----

If a popup is abandoned `Memory::popup` would remain `Some`. This is
problematic if, for example, you have logic that checks
`is_any_popup_open`.

This PR adds a new requirement for popups keeping their open state in
`Memory::popup`. They must call `Memory::keep_popup_open` as long as
they are being rendered. The recent changes in #5716 make this easy to
implement.

Supersedes #4697 which had an awkward implementation

These two videos show a case where a context menu was open when the
underlying widget got removed.

Before (`any_popup_open` remains `true`)
![Screenshot 2025-03-16 at 18 22
50](https://github.com/user-attachments/assets/22db64dd-e6f2-4501-9bda-39f470b9210c)

After
![Screenshot 2025-03-16 at 18 21
14](https://github.com/user-attachments/assets/bd4631b1-a0ad-4047-a14d-cd4999710e07)



* Closes #3657
* [x] I have followed the instructions in the PR template
darkwater pushed a commit to darkwater/egui that referenced this pull request Aug 24, 2025
Breaking changes:
- When using the Memory::popup state, it's now required to call
keep_popup_open each frame or the popup will close.
- Usually handled by the `Popup` struct, but required for custom popups
using the state in `Memory` directly

-----

If a popup is abandoned `Memory::popup` would remain `Some`. This is
problematic if, for example, you have logic that checks
`is_any_popup_open`.

This PR adds a new requirement for popups keeping their open state in
`Memory::popup`. They must call `Memory::keep_popup_open` as long as
they are being rendered. The recent changes in emilk#5716 make this easy to
implement.

Supersedes emilk#4697 which had an awkward implementation

These two videos show a case where a context menu was open when the
underlying widget got removed.

Before (`any_popup_open` remains `true`)
![Screenshot 2025-03-16 at 18 22
50](https://github.com/user-attachments/assets/22db64dd-e6f2-4501-9bda-39f470b9210c)

After
![Screenshot 2025-03-16 at 18 21
14](https://github.com/user-attachments/assets/bd4631b1-a0ad-4047-a14d-cd4999710e07)



* Closes emilk#3657
* [x] I have followed the instructions in the PR template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

any_popup_open() remains true even when there are no popups

2 participants