Skip to content

Commit 5bc19f3

Browse files
authored
Report image alt text as text if widget contains no other text (#7142)
- Same as #7136 but now for atomics
1 parent 6eb7bb6 commit 5bc19f3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

crates/egui/src/atomics/atoms.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ impl<'a> Atoms<'a> {
4242
}
4343
}
4444
}
45+
46+
// If there is no text, try to find an image with alt text.
47+
if string.is_none() {
48+
string = self.iter().find_map(|a| match &a.kind {
49+
AtomKind::Image(image) => image.alt_text.as_deref().map(Cow::Borrowed),
50+
_ => None,
51+
});
52+
}
53+
4554
string
4655
}
4756

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use egui::{include_image, Image};
2+
use egui_kittest::kittest::Queryable as _;
3+
use egui_kittest::Harness;
4+
5+
#[test]
6+
fn image_button_should_have_alt_text() {
7+
let harness = Harness::new_ui(|ui| {
8+
_ = ui.button(
9+
Image::new(include_image!("../../../crates/eframe/data/icon.png")).alt_text("Egui"),
10+
);
11+
});
12+
13+
harness.get_by_label("Egui");
14+
}

0 commit comments

Comments
 (0)