limn
    ↑↓ ChooseEnter OpenEsc Close
    GitHub

    Components/Overlays

    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.

    Native componentGuide source

    Preview

    CodeSource
    fn view(palette: ComponentPalette) -> Element {
        Tooltip::new(
            Button::new("plan", "Plan", palette).render(),
            "plan",
            "Plan mode",
            palette,
        )
        .render()
    }

    Examples

    Each one is the library drawing it. Press, type and hover.

    Title and shortcut
    CodeSource
    row(vec![
                Button::new("tooltip-plain", "Title only", palette)
                    .variant(ButtonVariant::Outline)
                    .tooltip("Save changes")
                    .render(),
                Button::new("tooltip-shortcut", "With shortcut", palette)
                    .variant(ButtonVariant::Outline)
                    .tooltip("Save changes")
                    .tooltip_shortcut("Ctrl+S")
                    .render(),
                IconButton::new("tooltip-icon", Icon::Refresh, palette)
                    .tooltip("Refresh")
                    .tooltip_shortcut("F5")
                    .render(),
            ])
    With description
    CodeSource
    row(vec![
                Tooltip::new(anchor("tooltip-rich", "Description"), "tooltip-rich", "Plan mode", palette)
                    .shortcut("Shift+Tab")
                    .description("The agent proposes steps and waits for your approval before editing files.")
                    .separator()
                    .footer("Available in any conversation")
                    .render(),
            ])
    Delay, title, pointer and fill
    CodeSource
    row(vec![
        Tooltip::new(anchor("tooltip-at-once", "At once"), "tooltip-at-once", "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(),
        Tooltip::new(anchor("tooltip-no-arrow", "No pointer"), "tooltip-no-arrow", "Without a pointer", palette)
            .arrow(false)
            .render(),
        Tooltip::new(anchor("tooltip-slow", "After a second"), "tooltip-slow", "A slower hint", palette)
            .delay_ms(1000)
            .render(),
    ])
    Placement
    CodeSource
    row(vec![
                Tooltip::new(anchor("tooltip-above", "Above"), "tooltip-above", "Above", palette)
                    .placement(TooltipPlacement::Above)
                    .render(),
                Tooltip::new(anchor("tooltip-below", "Below"), "tooltip-below", "Below", palette)
                    .placement(TooltipPlacement::Below)
                    .render(),
                Tooltip::new(anchor("tooltip-left", "Left"), "tooltip-left", "Left", palette)
                    .placement(TooltipPlacement::Left)
                    .render(),
                Tooltip::new(anchor("tooltip-right", "Right"), "tooltip-right", "Right", palette)
                    .placement(TooltipPlacement::Right)
                    .render(),
            ])

    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.

    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()
    OptionDefaultWhat it changes
    delay_ms350How 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_size12The title’s size. A one-line hint grows by what a larger title adds.
    title_font_familySansThe title’s face.
    arrowtrueThe small pointer that joins the hint to its anchor.
    backgroundthe palette’sThe 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.

    API reference

    The guide covers composition, options and actions. Generate the complete Rust type and builder reference from the checkout:

    cargo doc -p limn --open

    Component API overview · State and actions

    The example is drawn by crates/limn-gallery/src/pages/tooltip.rs.