Report image alt text as text if widget contains no other text (#7142)

- Same as https://github.com/emilk/egui/pull/7136 but now for atomics
This commit is contained in:
Lucas Meurer 2025-06-13 13:54:07 +02:00 committed by GitHub
parent 6eb7bb6e08
commit 5bc19f3ca3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View File

@ -42,6 +42,15 @@ impl<'a> Atoms<'a> {
}
}
}
// If there is no text, try to find an image with alt text.
if string.is_none() {
string = self.iter().find_map(|a| match &a.kind {
AtomKind::Image(image) => image.alt_text.as_deref().map(Cow::Borrowed),
_ => None,
});
}
string
}

View File

@ -0,0 +1,14 @@
use egui::{include_image, Image};
use egui_kittest::kittest::Queryable as _;
use egui_kittest::Harness;
#[test]
fn image_button_should_have_alt_text() {
let harness = Harness::new_ui(|ui| {
_ = ui.button(
Image::new(include_image!("../../../crates/eframe/data/icon.png")).alt_text("Egui"),
);
});
harness.get_by_label("Egui");
}