Kl4rry / simp

🖼️ Simp is a fast and simple GPU-accelerated image manipulation program.
Apache License 2.0
299 stars 11 forks source link

Display tooltips in menus #9

Closed Kl4rry closed 2 years ago

Kl4rry commented 2 years ago

It would be very nice to see the keybinds in the menu. But I don't think it's currently supported in egui.

bartios commented 2 years ago

As far as I know you can add tooltips with egui by using the on_hover_ui or on_hover_ui_at_pointer methods on Response. There are also variants to just add a label by passing in text. Using them would look a little bit like this:

ui.label("Some label text").on_hover_text_at_pointer("Some tooltip text");

You might have already considered this option and discarded it because it has some flaw, if that is the case please add your thoughts.

Kl4rry commented 2 years ago

These tooltips are only visible when hovered which is worse then the native Windows and MacOS shortcut tooltips. bild But they are still better then nothing so it seems like a good idea to add them.

bartios commented 2 years ago

Styling buttons in that way seems far too big a hassle at this point but we can still get close by using a grid. The following code can be used as a really quick example.

ui.menu_button("menu", |ui| {
                egui::Grid::new("grid_id").num_columns(2).show(ui, |ui|{
                    ui.button("first button");
                    ui.with_layout(egui::Layout::default().with_cross_align(egui::Align::RIGHT), |ui|{
                        ui.label("Cmd + F");
                    });
                    ui.end_row();
                    ui.button("second button");
                    ui.with_layout(egui::Layout::default().with_cross_align(egui::Align::RIGHT), |ui|{
                        ui.label("Cmd + S");
                    });
                    ui.end_row();
                    ui.button("third button");
                    ui.with_layout(egui::Layout::default().with_cross_align(egui::Align::RIGHT), |ui|{
                        ui.label("Cmd + T");
                    });
                    ui.end_row();
                })
            });

Which shows up looking like this:

Screenshot 2022-08-31 at 14 56 29

To use it it should probably be encapsulated into a custom thing which just asks for tuples of 2 strings and lets us hide all the layout and styling stuff.

Kl4rry commented 2 years ago

I think this solution with some small tweaks is preferable to hover tooltips. All thats needed is a slight margin to the right of the label and it would be nice if the buttons where the same width.