-
Notifications
You must be signed in to change notification settings - Fork 1.8k
⚠️ Close popup if Memory::keep_popup_open
isn't called
#5814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
⚠️ Close popup if Memory::keep_popup_open
isn't called
#5814
Conversation
cc @lucasmerlin who is actively working on popups |
Preview available at https://egui-pr-preview.github.io/pr/5814-juanclean-up-abandoned-popups |
@lucasmerlin, on a slight tangent, I noticed a couple of potential performance improvements to the new popup system while working on this btw:
Fixing the first one would make the second one a non-issue. To illustrate this point with our application, these green rects show all the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I think this makes sense.
About the optimization, best thing I can imagine that wouldn't make the api less ergonomic would be storing the Popup in a |
Feedback addressed 👍. This could be a breaking change for anyone using
Makes sense. I mentioned it since there's been quite a bit of work recently to reduce the size of structs, so yeah this should help 👍 With regards to |
Memory::keep_popup_open
isn't called
I've updated the title and description so we'll remember to adress it in the Changelog 👍🏻
Great idea! |
/// This is needed because in some cases popups can go away without `close_popup` being | ||
/// called. For example, when a context menu is open and the underlying widget stops | ||
/// being rendered. | ||
pub fn keep_popup_open(&mut self, popup_id: Id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like there is a more elegant solution to this problem that I'm not seeing 😆
We could replace is_popup_open
with show_popup_if_open(popup_id, closure)
, but that's a bit annoying too (especially when it comes to lifetimes and locks), so… no.
I'm also not in love with this function name, but again fail to come up with something better.
so… LGTM :)
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`)  After  * Closes emilk#3657 * [x] I have followed the instructions in the PR template
Breaking changes:
Popup
struct, but required for custom popups using the state inMemory
directlyIf a popup is abandoned
Memory::popup
would remainSome
. This is problematic if, for example, you have logic that checksis_any_popup_open
.This PR adds a new requirement for popups keeping their open state in
Memory::popup
. They must callMemory::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
remainstrue
)After

any_popup_open()
remainstrue
even when there are no popups #3657