Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tooltips with dynamic contents shrink #5167

Closed
emilk opened this issue Sep 25, 2024 · 0 comments · Fixed by #5168
Closed

Tooltips with dynamic contents shrink #5167

emilk opened this issue Sep 25, 2024 · 0 comments · Fixed by #5168
Labels
bug Something is broken

Comments

@emilk
Copy link
Owner

emilk commented Sep 25, 2024

Simple repro:

let time = ui.input(|i| i.time);
ui.label("Hover for a tooltip with changing content")
    .on_hover_text(format!("A number: {}", time % 10.0));

The tooltips starts out wide, then quickly shrinks, wrapping the text at an unnatural place:

image

Cause

The first frame, the Area measures the contents and remember it for the next frame.
The next frame it uses this size as the max-width, which means the new text will wrap at this width.

If the text is wider next frame, this means the text will wrap earlier than the default Spacing::tooltip_width, which is already a problem. But it gets worse.

When the text wraps, it usually becomes less wide than the wrap width (because we wrap at word boundaries), so the Area learns that the content is now more narrow, and uses this smaller width as the next wrap-width next frame. The result is a width that just keeps shrinking.

Solution

The general solution is to be found in

A simple fix is just to add ui.set_max_width(ui.spacing().tooltip_width); to the tooltip:

.on_hover_ui with dynamic content can still hit the shrinking problem. The general solution depends on solving #5138 but a work-around is to add this to your tooltips:

 response.on_hover_ui(|ui| {
+    ui.set_max_width(ui.spacing().tooltip_width);
     // …
 });
@emilk emilk added the bug Something is broken label Sep 25, 2024
@emilk emilk added this to the Next Major Release milestone Sep 25, 2024
emilk added a commit that referenced this issue Sep 25, 2024
Affects `.on_hover_text(…)` with dynamic content (i.e. content
that changes over time).

* Closes #5167
@emilk emilk closed this as completed in 3805584 Sep 25, 2024
hacknus pushed a commit to hacknus/egui that referenced this issue Oct 30, 2024
Affects `.on_hover_text(…)` with dynamic content (i.e. content that
changes over time).

* Closes emilk#5167

`.on_hover_ui` with dynamic content can still hit the shrinking problem.
The general solution depends on solving
emilk#5138 but a work-around is to add
this to your tooltips:

```diff
 response.on_hover_ui(|ui| {
+    ui.set_max_width(ui.spacing().tooltip_width);
     // …
 });
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant