Skip to content

Add tooltip support for per-tab "close" button and "add tab" button #310

@ElouanPetereau

Description

@ElouanPetereau

Is your feature request related to a problem? Please describe.

AFAIK, there is no way to show a tooltip when hovering the per-tab "close" button (x) or the "add tab" button (+).

Tooltips already exist in other parts of the library:

  • show_tab_name_on_hover for tab labels
  • LeafTranslations::close_button_disabled_tooltip for the disabled close-all button
  • show_secondary_button_hint for secondary buttons on tab bars

But neither the close button on individual tabs nor the add button expose their egui::Response and no TabViewer callback gives access to it. You cannot attach .on_hover_text() or .on_hover_ui() to these elements.

Describe the solution you'd like

Add two new defaulted methods to TabViewer:

/// Optional tooltip text shown when hovering the close button of the given tab.
fn close_button_tooltip(&mut self, _tab: &mut Self::Tab) -> Option<String> {
    None
}

/// Optional tooltip text shown when hovering the add tab button.
fn add_button_tooltip(&mut self) -> Option<String> {
    None
}

Internally, the library would call response.on_hover_text(text) when the method returns Some.

This follows the same TabViewer callback pattern used elsewhere and does not seems to break any existing API.

Describe alternatives you've considered

  • Using on_tab_button to get the tab Response, estimating the close button position from the tab rect (offset by style padding, button size...), and calling egui::show_tooltip_at when the pointer falls inside that computed region.
  • Placing a transparent interactive widget on top of the close or add button rect to get a Response that .on_hover_text() can be chained on.

Both break when internal layout details (button size, padding, alignment) change between versions and are really dirty.

Additional context

In my case, clicking on the (+) button opens a popup dialog with a form to generate the next tab (which contains some kind of plots) so having a helper text on hover to explain what it will do would be ideal.
Also, on_tab_button (added in #93 already gives access to the tab label response. The close and add buttons are the only tab bar elements still missing this.

If this is a feature you would be interested to have I can work on a PR for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions