-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Make egu::menu
types public
#4544
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
emilk
changed the title
Suggestion to make some structs public for possibiity to create custom context menu
Make May 27, 2024
egu::menu
types public
emilk
approved these changes
May 27, 2024
emilk
reviewed
May 27, 2024
Шs there anything else I need to add or did you want me to add a description only to MenuState struct? |
No - just get the CI green and I can hit merge |
Thank you, I've done it |
hacknus
pushed a commit
to hacknus/egui
that referenced
this pull request
Oct 30, 2024
Sometimes we need to fix the current state of the application in the moment when you open the context menu, to save it, and to use it during creation of context menu and response handling. Making some structs, related with menu creating, allow us to create functions for this cases. For example, ```rust pub fn context_menu_custom<'a, T>( response: &Response, //variable for fixing state in the moment when you open context menu state: &mut T, //function which allow to get some king of state. //In this case state depends on cursor position, in other cases it may depend on system time or something else get_state: impl FnOnce(Pos2) -> T, //set contents of menu depending on state set_contents: impl 'a + FnOnce(&T) -> Box<dyn 'a + FnOnce(&mut Ui)>, ) -> Option<InnerResponse<()>> { let menu_id = Id::new("__egui::context_menu"); let mut bar_state = BarState::load(&response.ctx, menu_id); let root = &mut bar_state; let menu_response = MenuRoot::context_interaction(response, root); if let egui::menu::MenuResponse::Create(p, _) = &menu_response { *state = get_state(*p); }; let add_contents = set_contents(&state); MenuRoot::handle_menu_response(root, menu_response); let inner_response = bar_state.show(response, add_contents); bar_state.store(&response.ctx, menu_id); inner_response } ``` The example of using such function you may see in [`my repository`](https://github.com/sor-ca/context_menu) It is very simple example, and is this case, the problem may be solved without fn context_menu_custom, but in more complex situations, it may be very useful Related issue: emilk#4162 <!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> --------- Co-authored-by: Emil Ernerfeldt <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sometimes we need to fix the current state of the application in the moment when you open the context menu, to save it, and to use it during creation of context menu and response handling. Making some structs, related with menu creating, allow us to create functions for this cases. For example,
The example of using such function you may see in
my repository
It is very simple example, and is this case, the problem may be solved without fn context_menu_custom, but in more complex situations, it may be very useful
Related issue: #4162