Skip to content
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

Extend Response with context_menu_custom method #4170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

WojciechMula
Copy link
Contributor

Method context_menu_custom allows to pass set of PointerButtons, that activate the context menu. This let to show menu on clicks by desired set of buttons/

Example:

use egui::PointerButtonSet;
use egui::PointerButtons;

let left_or_right = PointerButtonSet::from([
    PointerButtons::Primary,
    PointerButtons::Secondary,
]);

let response = ui.add(Label::new("Click me!").sense(Sense::click()));
response.context_menu_custom(left_or_right, |ui| {
    if ui.button("Close the menu").clicked() {
        ui.close_menu();
    }
});

Method `context_menu_custom` allows to pass set of PointerButtons,
that activate the context menu. This let to show menu on clicks
by desired set of buttons/

Example:

```
use egui::PointerButtonSet;
use egui::PointerButtons;

let left_or_right = PointerButtonSet::from([
    PointerButtons::Primary,
    PointerButtons::Secondary,
]);

let response = ui.add(Label::new("Click me!").sense(Sense::click()));
response.context_menu_custom(left_or_right, |ui| {
    if ui.button("Close the menu").clicked() {
        ui.close_menu();
    }
});
```
@enomado
Copy link
Contributor

enomado commented Mar 17, 2024

Hi there. I, as you, want more control to configure context menu apearing. I made some variants of possible API

#4162

Your feature could be made if there will be fully custom menu-starting function, which is not dependent on response

@emilk
Copy link
Owner

emilk commented Mar 25, 2024

What is the use case here? You want to activate a menu when both primary and secondary buttons are pressed?

If so, wouldn'ty if response.primary_clicked() && response.secondary_clicked() { /* show menu */ } be a better approach?

@WojciechMula
Copy link
Contributor Author

What is the use case here? You want to activate a menu when both primary and secondary buttons are pressed?

If so, wouldn'ty if response.primary_clicked() && response.secondary_clicked() { /* show menu */ } be a better approach?

Yes, this is my goal, to show menu on some non-standard event. But I see my solution is too restrictive, what if somebody wanted to open menu on key.

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.

3 participants