Commit 699936e
authored
button: expose preferred tooltip placement (#2971)
Button tooltips always use automatic positioning, even though the
existing tooltip overlay supports a preferred side. This adds
`tooltip_placement(Placement)` so callers can choose that side without
replacing the button’s tooltip handling.
```rust
Button::new("search")
.label("Search")
.tooltip("Find a document")
.tooltip_placement(Placement::Left)
```
It works with both `tooltip(...)` and `tooltip_with_action(...)`. The
side is a preference, not a fixed position. The existing positioner
still flips and clamps the tooltip when space is limited. Omitting the
setting preserves automatic positioning. Setting it without tooltip
content does nothing.
## Screenshots
| Left | Right |
| --- | --- |
| 
| 
|
| **Bottom, with shortcut** | **Top requested, falls back below** |
| 
| 
|
## Video
Recorded during my manual testing:
https://github.com/user-attachments/assets/094f000b-847b-4504-a31d-3fed9ecdd35d
## How to Test
On macOS:
```sh
MTL_HUD_ENABLED=1 ./script/run-story-macos Tooltip
```
Hover **Search**, **Info**, and **Hover me**, moving away between
buttons. Their tooltips should appear on the left, below with the
shortcut, and on the right.
To check fallback near the window edge:
```sh
cargo run -p tooltip_top_edge --locked
```
Hover the top button. It requests `Top`, but the tooltip should appear
below because there is no room above.
<details>
<summary>Automated checks</summary>
```sh
cargo test -p gpui-base -p gpui-component --lib --locked
cargo clippy -p gpui-base -p gpui-component -p gpui-component-story --all-targets --locked -- -D warnings
```
771 base tests and 418 component tests passed. Strict Clippy and
formatting passed. The top-edge example also passed its build and strict
Clippy check. There is no new automated test for the Button forwarding
method. Placement was checked visually on macOS.
</details>
## Checklist
- [x] Read
[CONTRIBUTING.md](https://github.com/longbridge/gpui-kit/blob/main/CONTRIBUTING.md)
and followed the guidelines.
- [x] Reviewed the changes, including the AI-assisted code.
- [x] Ran and manually tested the related Story examples on macOS.
This change is not platform-specific. Windows and Linux runtime and
performance were not tested.
## AI assistance
I tested the change in my application, then asked OpenAI’s `gpt-6-astra`
to extract it into this PR. The agent prepared the patch, examples,
verification scripts, and description, and ran the automated checks. I
reviewed the extracted patch, requested corrections, and tested it
myself on macOS.1 parent 21e802b commit 699936e
4 files changed
Lines changed: 44 additions & 17 deletions
File tree
- crates
- component/src/button
- story/src/stories
- examples/tooltip_top_edge/src
- website/docs/components
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
6 | | - | |
| 5 | + | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
209 | 209 | | |
210 | 210 | | |
211 | 211 | | |
| 212 | + | |
212 | 213 | | |
213 | 214 | | |
214 | 215 | | |
| |||
252 | 253 | | |
253 | 254 | | |
254 | 255 | | |
| 256 | + | |
255 | 257 | | |
256 | 258 | | |
257 | 259 | | |
| |||
368 | 370 | | |
369 | 371 | | |
370 | 372 | | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
371 | 382 | | |
372 | 383 | | |
373 | 384 | | |
| |||
536 | 547 | | |
537 | 548 | | |
538 | 549 | | |
| 550 | + | |
539 | 551 | | |
540 | 552 | | |
541 | 553 | | |
| |||
780 | 792 | | |
781 | 793 | | |
782 | 794 | | |
783 | | - | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
784 | 798 | | |
785 | | - | |
| 799 | + | |
786 | 800 | | |
787 | 801 | | |
788 | 802 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | | - | |
| 78 | + | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
| 84 | + | |
84 | 85 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | 86 | | |
91 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
92 | 98 | | |
93 | | - | |
| 99 | + | |
| 100 | + | |
94 | 101 | | |
95 | 102 | | |
96 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
| 310 | + | |
310 | 311 | | |
311 | 312 | | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
312 | 317 | | |
313 | 318 | | |
314 | 319 | | |
| |||
0 commit comments