diff --git a/crates/egui/src/widgets/label.rs b/crates/egui/src/widgets/label.rs index e0f21fd1..86259ab2 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 babfb232..d02d04aa 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), diff --git a/tests/egui_tests/tests/snapshots/hovering_should_preserve_text_format.png b/tests/egui_tests/tests/snapshots/hovering_should_preserve_text_format.png index 7db5ec76..2b3ac7a5 100644 --- a/tests/egui_tests/tests/snapshots/hovering_should_preserve_text_format.png +++ b/tests/egui_tests/tests/snapshots/hovering_should_preserve_text_format.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:0fdc04ac6f24c20688c846af8759f91db2b3f8a93abcd0c5669c9050b98451ea -size 10152 +oid sha256:cac533a01c65c8eef093efcd4c9036da50f898ea2436612990f4c2365c98ad83 +size 12126