-
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
Response.context_menu
now returns the response of the context menu, if open
#3904
Conversation
Another downside is that it makes it harder to use the BitOr operator. |
With the fix I see the point in another downside: method chaining becomes impossible. We won't be able to call smth like |
I meant if you wanted to union the responses from multiple widgets as a single expression while inserting context menus and tooltips for each of them, like this: fn my_composite_widget(ui: &mut Ui) -> Response {
let ctx_menu = |ui: &mut Ui, option| {
ui.label(option);
};
ui.button("Button 1")
.context_menu(|ui| ctx_menu(ui, "Menu 1"))
| ui.button("Button 2")
.on_hover_text("Tooltip 2")
.context_menu(|ui| ctx_menu(ui, "Menu 2"))
| ui.button("Button 3")
.context_menu(|ui| ctx_menu(ui, "Menu 3"))
} Though I suppose this could be solved by adding an inspect method like in the standard library. And it would be easy for anyone to create a trait containing a method like this and implement it for |
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 think this makes sense, since the context_menu
method needs to return something to the user
@YgorSouza, does it this code fit your needs? fn my_composite_widget(ui: &mut Ui) -> egui::Response {
let ctx_menu = |ui: &mut Ui, option| {
ui.label(option);
};
let btn1 = ui.button("Button 1");
let btn2 = ui.button("Button 2").on_hover_text("Tooltip 2");
let btn3 = ui.button("Button 3");
btn1.context_menu(|ui| ctx_menu(ui, "Menu 1"));
btn2.context_menu(|ui| ctx_menu(ui, "Menu 2"));
btn3.context_menu(|ui| ctx_menu(ui, "Menu 3"));
return btn1 | btn2 | btn3;
} I see it a little wordy but more consistent. If there is a way to make it both very laconic and avoid Thinking out loud:
I will play around a bit trying to implement this idea. |
@emilk , I have merged last changes from the |
@YgorSouza you can also use https://crates.io/crates/tap |
context_menu
's self argResponse.context_menu
now returns the response of the context menu, if open
… if open (emilk#3904) Hi everyone! It's a great pleasure to work with such a library. It feels like a breath of fresh air! **Problem:** The current implementation of `context_menu` consumes `self` and returns it. However, the underlying `menu::context_menu` requires only a reference to `self`, so it is safe to change the `context_menu` signature. **Fix:** 1. Change signature to take a ref to `self`. 2. Return the `Option<InnerResponse<()>>` from the underlying method call **Pros:** 1. No `let response = response.context_menu(|| {...})` pattern 2. Better consistency with other `show`-like methods, as it is in the `Window::show` 3. Less ownership gymnastics **Cons:** 1. Breaking change 2. Smth else what I don't see ? **Additional info:** - This method is also addressed in [this PR](emilk#857). - `check.sh` fails only on `cargo check --quiet -p eframe --no-default-features --features wgpu` with `"The platform you're compiling for is not supported by winit"` error, should it be launched at all ?
Hi everyone! It's a great pleasure to work with such a library. It feels like a breath of fresh air!
Problem:
The current implementation of
context_menu
consumesself
and returns it. However, the underlyingmenu::context_menu
requires only a reference toself
, so it is safe to change thecontext_menu
signature.Fix:
self
.Option<InnerResponse<()>>
from the underlying method callPros:
let response = response.context_menu(|| {...})
patternshow
-like methods, as it is in theWindow::show
Cons:
Additional info:
check.sh
fails only oncargo check --quiet -p eframe --no-default-features --features wgpu
with"The platform you're compiling for is not supported by winit"
error, should it be launched at all ?