-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Reset Memory::popup to None if a popup was abandoned
#4697
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
Conversation
| /// 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>)>, |
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'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.
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.
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>,|
Closing in favor of #5814 |
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`)  After  * Closes #3657 * [x] I have followed the instructions in the PR template
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
any_popup_open()remainstrueeven when there are no popups #3657BEFORE
Screenshot.2024-06-23.at.18.41.41.mp4
AFTER
Screenshot.2024-06-23.at.18.56.01.mp4
Notice that
WRONGflashes for one frame. That's expected because on the frame the combo box disappears,any_popup_openstill returns true, since we don't know it has disappeared until the end of the frame.