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

Context menu on hover / clickable tooltips #1010

Closed
emilk opened this issue Dec 28, 2021 · 5 comments · Fixed by #4596
Closed

Context menu on hover / clickable tooltips #1010

emilk opened this issue Dec 28, 2021 · 5 comments · Fixed by #4596
Assignees
Labels
feature New feature or request rerun Desired for Rerun.io

Comments

@emilk
Copy link
Owner

emilk commented Dec 28, 2021

It would be great to be able to bring up a context menu just by hovering an element. It would act similar to a tooltip, but a tooltip you can interact with (it won't go away when you move the mouse).

@mankinskin
Copy link
Contributor

mankinskin commented Apr 16, 2022

For anyone looking into implementing this, this would probably be an abstraction over the trigger mechanism for bringing up a stationary menu, i.e. a menu created at some other element (represented by response):

egui/egui/src/menu.rs

Lines 284 to 308 in 2d2022f

if (response.clicked() && root.is_menu_open(id)) || input.key_pressed(Key::Escape) {
// menu open and button clicked or esc pressed
return MenuResponse::Close;
} else if (response.clicked() && !root.is_menu_open(id))
|| (response.hovered() && root.is_some())
{
// menu not open and button clicked
// or button hovered while other menu is open
let pos = response.rect.left_bottom();
return MenuResponse::Create(pos, id);
} else if input.pointer.any_pressed() && input.pointer.primary_down() {
if let Some(pos) = input.pointer.interact_pos() {
if let Some(root) = root.inner.as_mut() {
if root.id == id {
// pressed somewhere while this menu is open
let menu_state = root.menu_state.read();
let in_menu = menu_state.area_contains(pos);
if !in_menu {
return MenuResponse::Close;
}
}
}
}
}
MenuResponse::Stay

you can see that a menu is already opened by hovering if another menu is open already (L288).

the menu doesn't really have a mechanism for configuring it yet, but I suppose this could be easily added with some enums and a MenuConfig struct or something like that. Would be great if all these behaviours could be configured.

@apexys
Copy link

apexys commented Dec 11, 2023

It would also be interesting to be able to open a context menu with a left click or through some other action programmatically.

@emilk emilk added this to the Next Major Release milestone May 24, 2024
@emilk
Copy link
Owner Author

emilk commented May 24, 2024

This could also be implemented as "Tooltips stay put when you move the mouse onto them"

@emilk emilk added the rerun Desired for Rerun.io label May 24, 2024
@emilk emilk changed the title Context menu on hover Context menu on hover / clickable tooltips May 24, 2024
@emilk emilk assigned emilk and unassigned emilk May 28, 2024
@YgorSouza
Copy link
Contributor

This could also be seen as a Window that is anchored to a Response and closes when you click outside it, like the solution proposed for #4463. This is called a Popup in other UI libraries, but egui already uses popup to refer to the ComboBox drawer.

@emilk
Copy link
Owner Author

emilk commented Jun 3, 2024

Follow-up issue:

emilk added a commit that referenced this issue Jun 3, 2024
* Closes #1010

### In short
You can now put interactive widgets, like buttons and hyperlinks, in an
tooltip using `on_hover_ui`. If you do, the tooltip will stay open as
long as the user hovers it.

There is a new demo for this in the egui demo app (egui.rs):


![interactive-tooltips](https://github.com/emilk/egui/assets/1148717/97335ba6-fa3e-40dd-9da0-1276a051dbf2)

### Design
Tooltips can now contain interactive widgets, such as buttons and links.
If they do, they will stay open when the user moves their pointer over
them.

Widgets that do not contain interactive widgets disappear as soon as you
no longer hover the underlying widget, just like before. This is so that
they won't annoy the user.

To ensure not all tooltips with text in them are considered interactive,
`selectable_labels` is `false` for tooltips contents by default. If you
want selectable text in tooltips, either change the `selectable_labels`
setting, or use `Label::selectable`.

```rs
ui.label("Hover me").on_hover_ui(|ui| {
    ui.style_mut().interaction.selectable_labels = true;
    ui.label("This text can be selected.");

    ui.add(egui::Label::new("This too.").selectable(true));
});
```

### Changes
* Layers in `Order::Tooltip` can now be interacted with
hacknus pushed a commit to hacknus/egui that referenced this issue Oct 30, 2024
* Closes emilk#1010

### In short
You can now put interactive widgets, like buttons and hyperlinks, in an
tooltip using `on_hover_ui`. If you do, the tooltip will stay open as
long as the user hovers it.

There is a new demo for this in the egui demo app (egui.rs):


![interactive-tooltips](https://github.com/emilk/egui/assets/1148717/97335ba6-fa3e-40dd-9da0-1276a051dbf2)

### Design
Tooltips can now contain interactive widgets, such as buttons and links.
If they do, they will stay open when the user moves their pointer over
them.

Widgets that do not contain interactive widgets disappear as soon as you
no longer hover the underlying widget, just like before. This is so that
they won't annoy the user.

To ensure not all tooltips with text in them are considered interactive,
`selectable_labels` is `false` for tooltips contents by default. If you
want selectable text in tooltips, either change the `selectable_labels`
setting, or use `Label::selectable`.

```rs
ui.label("Hover me").on_hover_ui(|ui| {
    ui.style_mut().interaction.selectable_labels = true;
    ui.label("This text can be selected.");

    ui.add(egui::Label::new("This too.").selectable(true));
});
```

### Changes
* Layers in `Order::Tooltip` can now be interacted with
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request rerun Desired for Rerun.io
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants