Skip to content

Commit f0abce9

Browse files
authored
Button inherits the alt_text of the Image in it, if any (#7136)
If a `Button` has an `Image` in it (and no text), then the `Image::alt_text` will be used as the accessibility label for the button.
1 parent 9f91538 commit f0abce9

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

crates/egui/src/widgets/button.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,15 @@ impl Widget for Button<'_> {
314314

315315
let (rect, mut response) = ui.allocate_at_least(desired_size, sense);
316316
response.widget_info(|| {
317+
let mut widget_info = WidgetInfo::new(WidgetType::Button);
318+
widget_info.enabled = ui.is_enabled();
319+
317320
if let Some(galley) = &galley {
318-
WidgetInfo::labeled(WidgetType::Button, ui.is_enabled(), galley.text())
319-
} else {
320-
WidgetInfo::new(WidgetType::Button)
321+
widget_info.label = Some(galley.text().to_owned());
322+
} else if let Some(image) = &image {
323+
widget_info.label = image.alt_text.clone();
321324
}
325+
widget_info
322326
});
323327

324328
if ui.is_rect_visible(rect) {

crates/egui/src/widgets/image.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct Image<'a> {
5454
sense: Sense,
5555
size: ImageSize,
5656
pub(crate) show_loading_spinner: Option<bool>,
57-
alt_text: Option<String>,
57+
pub(crate) alt_text: Option<String>,
5858
}
5959

6060
impl<'a> Image<'a> {

0 commit comments

Comments
 (0)