Tooltip
A hint for a control: its name, its shortcut and, when needed, a sentence on what it does. It appears after the pointer rests on the control for 350 ms, or at once with keyboard focus.
Import
use limn::{Component, Tooltip, TooltipPlacement};
Usage
A tooltip wraps its anchor where the anchor is built. It adds no layout size, takes no keyboard input and reports no action, so there is nothing to handle.
fn view(palette: ComponentPalette) -> Element {
Tooltip::new(
Button::new("plan", "Plan", palette).render(),
"plan",
"Plan mode",
palette,
)
.render()
}
The arguments are the anchor, the anchor’s ID, the title and the palette. An anchor that is not a control gets a hover region, with no click action and no keyboard stop.
On a button
Button::new("save", "Save", palette)
.tooltip("Save changes")
.tooltip_shortcut("Ctrl+S")
.render()
Button and IconButton take their hint directly, so they need
no wrapper. tooltip_with(TooltipSpec) takes a description, a placement and
a width as well.
Shortcut, description and footer
Tooltip::new(anchor, "plan", "Plan mode", palette)
.shortcut("Shift+Tab")
.description("The agent proposes the steps and waits for approval.")
.separator()
.footer("Available in any conversation")
.render()
shortcut shows keycaps beside the title. description adds a paragraph
that wraps, separator a hairline between two sections and footer
secondary information. icon_row(label, items) adds a row of labelled icons
built from TooltipItems. Empty text is ignored.
Delay, title, pointer and fill
Tooltip::new(anchor, "server", "Rust workshop", palette)
.placement(TooltipPlacement::Right)
.delay_ms(0)
.title_font_size(16.0)
.title_font_family(FontFamily::SansMedium)
.background(Color::rgb(10, 10, 12))
.render()
| Option | Default | What it changes |
|---|---|---|
delay_ms | 350 | How long the pointer rests before the hint shows; 0 shows it at once, for a strip of marks read by moving along it. Keyboard focus shows it at once either way. |
title_font_size | 12 | The title’s size. A one-line hint grows by what a larger title adds. |
title_font_family | Sans | The title’s face. |
arrow | true | The small pointer that joins the hint to its anchor. |
background | the palette’s | The fill of the hint and its pointer. |
They are kept as TooltipOptions on the rendered ElementKind::Tooltip.
Placement
Tooltip::new(anchor, "more", "More", palette)
.placement(TooltipPlacement::Right)
.render()
Above unless set; Below, Left and Right are the others. The hint flips
to the opposite side when the preferred one would leave the window.
Width
max_width is 360 unless set and never under 32; the window bounds it too.
A file path
Tooltip::for_path(anchor, "tab-3", "src/pages/menus.rs", palette).render()
Tooltip::for_path names a file: its name as the title and the directory
that holds it beneath, no wider than 320.
Motion
The hint fades in and out, and moving between neighbouring controls does not blink; see Animation.
Accessibility
A hint is not seen by who cannot hover, so its title is told to the platform
as the description of the first control in its anchor. The hint of a Button
or an IconButton names an icon alone and describes a button with a label. A
passive anchor is not told to the platform at all.