feat(tooltip): add preferred placement and hide_active_tooltip API#2464
Open
gaoyia wants to merge 1 commit into
Open
feat(tooltip): add preferred placement and hide_active_tooltip API#2464gaoyia wants to merge 1 commit into
gaoyia wants to merge 1 commit into
Conversation
Add `TooltipPreferredPlacement` (`Auto`, `Left`, `Right`, `Above`, `Below`, `AboveCursor`) so managed tooltips can be positioned relative to their trigger, with `Auto` keeping the existing above/below flip behavior. `AboveCursor` anchors the tooltip above the pointer and is useful for extremely narrow windows. Also expose: - `Button::tooltip_placement` to choose a placement per button. - `hide_active_tooltip` to immediately dismiss the managed tooltip on the current window (e.g. before opening a menu), and dismiss tooltips on right/middle mouse down in addition to left. The default placement is `Auto`, so existing call sites keep their current behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
TooltipPreferredPlacement(Auto,Left,Right,Above,Below,AboveCursor) so managed tooltips can be positioned relative to their trigger, withAutokeeping the existing above/below flip behavior.AboveCursoranchors the tooltip above the pointer and is useful for extremely narrow windows.Also expose:
Button::tooltip_placementto choose a placement per button.hide_active_tooltipto immediately dismiss the managed tooltip on the current window (e.g. before opening a menu), and dismiss tooltips on right/middle mouse down in addition to left.The default placement is
Auto, so existing call sites keep their current behavior.Description
Managed tooltips (owned by each window's
RootviaTooltipOverlay) could previously only appear above or below their trigger, chosen automatically by available space. This is insufficient for extremely narrow windows, where there is no room above or below the trigger and the tooltip gets clipped.This PR adds an opt-in
TooltipPreferredPlacementso a tooltip can be explicitly placed to theLeft,Right,Above,Below, or anchoredAboveCursor. Internals:tooltip_overlay_positionnow dispatches on the preferred placement; the previous auto-flip logic is preserved verbatim astooltip_overlay_position_autoand used byAuto.Left/Right/Above/Belowreuse the existing four-edge clamp (clamp_tooltip_bounds).AboveCursoruses a dedicatedclamp_tooltip_above_cursorthat clamps horizontally and against the bottom edge, but intentionally allows overflow past the top edge so the tooltip can fully render out of a short window.window.mouse_position()on hover) are threaded throughTooltipContentandTooltipOverlayPositioner.hide_active_tooltipis exposed to let callers dismiss the current tooltip immediately (e.g. before opening a menu). Managed elements now dismiss the tooltip on right/middle mouse down as well as left.Autois the default everywhere, so existing call sites are unaffected.Break Changes
None.
How to Test
cargo test -p gpui-component— includes new unit teststooltip_overlay_position_left_of_triggerandtooltip_overlay_position_above_cursor, alongside the existing placement tests.cargo run— open the story gallery and hover tooltip triggers to confirm default (Auto) behavior is unchanged..tooltip_placement(TooltipPreferredPlacement::Left)shows its tooltip to the left, and thatAboveCursorrenders correctly near a screen edge / in a short window.Checklist
cargo runfor story tests related to the changes.