Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add accessibility to ProgressBar and Spinner #4139

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/egui/src/data/output.rs
Original file line number Diff line number Diff line change
@@ -633,6 +633,7 @@ impl WidgetInfo {
WidgetType::ColorButton => "color button",
WidgetType::ImageButton => "image button",
WidgetType::CollapsingHeader => "collapsing header",
WidgetType::ProgressIndicator => "progress indicator",
WidgetType::Label | WidgetType::Other => "",
};

2 changes: 2 additions & 0 deletions crates/egui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -643,6 +643,8 @@ pub enum WidgetType {

CollapsingHeader,

ProgressIndicator,

/// If you cannot fit any of the above slots.
///
/// If this is something you think should be added, file an issue.
1 change: 1 addition & 0 deletions crates/egui/src/response.rs
Original file line number Diff line number Diff line change
@@ -779,6 +779,7 @@ impl Response {
WidgetType::Slider => Role::Slider,
WidgetType::DragValue => Role::SpinButton,
WidgetType::ColorButton => Role::ColorWell,
WidgetType::ProgressIndicator => Role::ProgressIndicator,
WidgetType::Other => Role::Unknown,
});
if let Some(label) = info.label {
11 changes: 11 additions & 0 deletions crates/egui/src/widgets/progress_bar.rs
Original file line number Diff line number Diff line change
@@ -113,6 +113,17 @@ impl Widget for ProgressBar {
let (outer_rect, response) =
ui.allocate_exact_size(vec2(desired_width, height), Sense::hover());

response.widget_info(|| {
let mut info = if let Some(ProgressBarText::Custom(text)) = &text {
WidgetInfo::labeled(WidgetType::ProgressIndicator, text.text())
} else {
WidgetInfo::new(WidgetType::ProgressIndicator)
};
info.value = Some((progress as f64 * 100.0).floor());

info
});

if ui.is_rect_visible(response.rect) {
if animate {
ui.ctx().request_repaint();
3 changes: 2 additions & 1 deletion crates/egui/src/widgets/spinner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use epaint::{emath::lerp, vec2, Color32, Pos2, Rect, Shape, Stroke};

use crate::{Response, Sense, Ui, Widget};
use crate::{Response, Sense, Ui, Widget, WidgetInfo, WidgetType};

/// A spinner widget used to indicate loading.
///
@@ -66,6 +66,7 @@ impl Widget for Spinner {
.size
.unwrap_or_else(|| ui.style().spacing.interact_size.y);
let (rect, response) = ui.allocate_exact_size(vec2(size, size), Sense::hover());
response.widget_info(|| WidgetInfo::new(WidgetType::ProgressIndicator));
self.paint_at(ui, rect);

response