`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.
This commit is contained in:
Emil Ernerfeldt 2025-06-11 23:00:59 +02:00 committed by GitHub
parent 9f9153805d
commit f0abce9bb8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View File

@ -314,11 +314,15 @@ impl Widget for Button<'_> {
let (rect, mut response) = ui.allocate_at_least(desired_size, sense);
response.widget_info(|| {
let mut widget_info = WidgetInfo::new(WidgetType::Button);
widget_info.enabled = ui.is_enabled();
if let Some(galley) = &galley {
WidgetInfo::labeled(WidgetType::Button, ui.is_enabled(), galley.text())
} else {
WidgetInfo::new(WidgetType::Button)
widget_info.label = Some(galley.text().to_owned());
} else if let Some(image) = &image {
widget_info.label = image.alt_text.clone();
}
widget_info
});
if ui.is_rect_visible(rect) {

View File

@ -54,7 +54,7 @@ pub struct Image<'a> {
sense: Sense,
size: ImageSize,
pub(crate) show_loading_spinner: Option<bool>,
alt_text: Option<String>,
pub(crate) alt_text: Option<String>,
}
impl<'a> Image<'a> {