Preserve text format in truncated label tooltip (#7514)

* Related https://github.com/rerun-io/rerun/issues/10906

This changes the label hover ui to use the provided layout job instead
of the text so that the text format is preserved.
This commit is contained in:
Lucas Meurer 2025-09-08 15:41:05 +02:00 committed by GitHub
parent 34cd613378
commit e5d0b93633
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 2 deletions

View File

@ -282,7 +282,7 @@ impl Widget for Label {
if ui.is_rect_visible(response.rect) {
if show_tooltip_when_elided && galley.elided {
// Show the full (non-elided) text on hover:
response = response.on_hover_text(galley.text());
response = response.on_hover_text(galley.job.clone());
}
let response_color = if interactive {

View File

@ -1,4 +1,4 @@
use egui::{Image, include_image};
use egui::{Color32, Image, Label, RichText, TextWrapMode, include_image};
use egui_kittest::Harness;
use egui_kittest::kittest::Queryable as _;
@ -12,3 +12,24 @@ fn image_button_should_have_alt_text() {
harness.get_by_label("Egui");
}
#[test]
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")
.italics()
.underline()
.color(Color32::LIGHT_BLUE),
)
.wrap_mode(TextWrapMode::Truncate),
);
});
harness.get_by_label_contains("Long text").hover();
harness.run_steps(5);
harness.snapshot("hovering_should_preserve_text_format");
}

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:dc03cdc22b410ed90fdbbc45ced5c61027463132c490673170aab9044d683f88
size 10254