Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Context::is_context_menu_open() (#3267)
I encountered a case where I needed to know if an egui context menu was open, even if the mouse cursor was not in an egui area (full details in discord). I found that every resource I needed to detect that the menu was open was either private, or pub(crate). While it is possible to wrap the `Response::context_menu()` in code to do state-tracking, it becomes necessary to duplicate that code in every place you use a context menu. In this commit, I add `Context::is_context_menu_open()`. Named similarly to `Context::is_pointer_over_area()`, this method will return true if any context menu is open. This is possible because the context menu uses a temp var with a fixed Id to store its state. This method just fetches the state, and interrogates it to see if there is a menu present. One helper method, `BarState::has_root()`, was added as all the fields needed to perform the check were private to the `menu` module. I've also updated the Context Menu demo to show the result of `is_context_menu_open()` to verify the code functions as expected.
- Loading branch information