Skip to content

Commit 5628fe9

Browse files
committed
Preserve text format in truncated label tooltip (#7514)
* Related rerun-io/rerun#10906 This changes the label hover ui to use the provided layout job instead of the text so that the text format is preserved.
1 parent 995b6a6 commit 5628fe9

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

crates/egui/src/widgets/label.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl Widget for Label {
282282
if ui.is_rect_visible(response.rect) {
283283
if show_tooltip_when_elided && galley.elided {
284284
// Show the full (non-elided) text on hover:
285-
response = response.on_hover_text(galley.text());
285+
response = response.on_hover_text(galley.job.clone());
286286
}
287287

288288
let response_color = if interactive {

tests/egui_tests/tests/regression_tests.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use egui::{Image, include_image};
1+
use egui::{Color32, Image, Label, RichText, TextWrapMode, include_image};
22
use egui_kittest::Harness;
33
use egui_kittest::kittest::Queryable as _;
44

@@ -12,3 +12,24 @@ fn image_button_should_have_alt_text() {
1212

1313
harness.get_by_label("Egui");
1414
}
15+
16+
#[test]
17+
fn hovering_should_preserve_text_format() {
18+
let mut harness = Harness::builder().with_size((200.0, 70.0)).build_ui(|ui| {
19+
ui.add(
20+
Label::new(
21+
RichText::new("Long text that should be elided and has lots of styling")
22+
.italics()
23+
.underline()
24+
.color(Color32::LIGHT_BLUE),
25+
)
26+
.wrap_mode(TextWrapMode::Truncate),
27+
);
28+
});
29+
30+
harness.get_by_label_contains("Long text").hover();
31+
32+
harness.run_steps(5);
33+
34+
harness.snapshot("hovering_should_preserve_text_format");
35+
}
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)