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

Fix bug causing tooltips with dynamic content to shrink #5168

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/egui/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,10 @@ impl Response {
#[doc(alias = "tooltip")]
pub fn on_hover_text_at_pointer(self, text: impl Into<WidgetText>) -> Self {
self.on_hover_ui_at_pointer(|ui| {
// Prevent `Area` auto-sizing from shrinking tooltips with dynamic content.
// See https://github.com/emilk/egui/issues/5167
ui.set_max_width(ui.spacing().tooltip_width);

ui.add(crate::widgets::Label::new(text));
})
}
Expand All @@ -803,6 +807,10 @@ impl Response {
#[doc(alias = "tooltip")]
pub fn on_hover_text(self, text: impl Into<WidgetText>) -> Self {
self.on_hover_ui(|ui| {
// Prevent `Area` auto-sizing from shrinking tooltips with dynamic content.
// See https://github.com/emilk/egui/issues/5167
ui.set_max_width(ui.spacing().tooltip_width);

ui.add(crate::widgets::Label::new(text));
})
}
Expand All @@ -822,6 +830,10 @@ impl Response {
/// Show this text when hovering if the widget is disabled.
pub fn on_disabled_hover_text(self, text: impl Into<WidgetText>) -> Self {
self.on_disabled_hover_ui(|ui| {
// Prevent `Area` auto-sizing from shrinking tooltips with dynamic content.
// See https://github.com/emilk/egui/issues/5167
ui.set_max_width(ui.spacing().tooltip_width);

ui.add(crate::widgets::Label::new(text));
})
}
Expand Down
6 changes: 6 additions & 0 deletions tests/test_size_pass/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ fn main() -> eframe::Result {
ui.label("World");
ui.label("Hellooooooooooooooooooooooooo");
});

ui.separator();

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));
});
})
}
Loading