mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 06:10:06 -04:00
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:
@@ -314,11 +314,15 @@ impl Widget for Button<'_> {
|
|||||||
|
|
||||||
let (rect, mut response) = ui.allocate_at_least(desired_size, sense);
|
let (rect, mut response) = ui.allocate_at_least(desired_size, sense);
|
||||||
response.widget_info(|| {
|
response.widget_info(|| {
|
||||||
|
let mut widget_info = WidgetInfo::new(WidgetType::Button);
|
||||||
|
widget_info.enabled = ui.is_enabled();
|
||||||
|
|
||||||
if let Some(galley) = &galley {
|
if let Some(galley) = &galley {
|
||||||
WidgetInfo::labeled(WidgetType::Button, ui.is_enabled(), galley.text())
|
widget_info.label = Some(galley.text().to_owned());
|
||||||
} else {
|
} else if let Some(image) = &image {
|
||||||
WidgetInfo::new(WidgetType::Button)
|
widget_info.label = image.alt_text.clone();
|
||||||
}
|
}
|
||||||
|
widget_info
|
||||||
});
|
});
|
||||||
|
|
||||||
if ui.is_rect_visible(rect) {
|
if ui.is_rect_visible(rect) {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ pub struct Image<'a> {
|
|||||||
sense: Sense,
|
sense: Sense,
|
||||||
size: ImageSize,
|
size: ImageSize,
|
||||||
pub(crate) show_loading_spinner: Option<bool>,
|
pub(crate) show_loading_spinner: Option<bool>,
|
||||||
alt_text: Option<String>,
|
pub(crate) alt_text: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Image<'a> {
|
impl<'a> Image<'a> {
|
||||||
|
|||||||
Reference in New Issue
Block a user