From d3e4a040f483dee42d2c8f6fb06c481d4576b493 Mon Sep 17 00:00:00 2001 From: Lucas Meurer Date: Thu, 11 Sep 2025 17:18:53 +0200 Subject: [PATCH] Reset wrapping in label tooltip (#7535) * follow up to #7514 That PR changed the tooltip to preserve the wrapping, which made the tooltip kind of useless. With this PR the wrapping is reset for the tooltip. --- crates/egui/src/widgets/label.rs | 8 +++++++- tests/egui_tests/tests/regression_tests.rs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/egui/src/widgets/label.rs b/crates/egui/src/widgets/label.rs index f0ace5501..92a32a799 100644 --- a/crates/egui/src/widgets/label.rs +++ b/crates/egui/src/widgets/label.rs @@ -281,8 +281,14 @@ impl Widget for Label { if ui.is_rect_visible(response.rect) { if show_tooltip_when_elided && galley.elided { + // Keep the sections and text, but reset everything else (especially wrapping): + let job = crate::text::LayoutJob { + sections: galley.job.sections.clone(), + text: galley.job.text.clone(), + ..crate::text::LayoutJob::default() + }; // Show the full (non-elided) text on hover: - response = response.on_hover_text(galley.job.clone()); + response = response.on_hover_text(job); } let response_color = if interactive { diff --git a/tests/egui_tests/tests/regression_tests.rs b/tests/egui_tests/tests/regression_tests.rs index babfb2320..d02d04aa2 100644 --- a/tests/egui_tests/tests/regression_tests.rs +++ b/tests/egui_tests/tests/regression_tests.rs @@ -18,7 +18,7 @@ fn hovering_should_preserve_text_format() { let mut harness = Harness::builder().with_size((200.0, 70.0)).build_ui(|ui| { ui.add( Label::new( - RichText::new("Long text that should be elided and has lots of styling") + RichText::new("Long text that should be elided and has lots of styling and is long enough to have multiple lines.") .italics() .underline() .color(Color32::LIGHT_BLUE),