mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-08 22:28:09 +00:00
Preferences: inputs expose their labels to accessibility tools
The Preferences labeled() helper painted the visible label and then drew the input beside it without associating them. Call label_inputs_by so screen readers and the test harness can find each field by its label.
This commit is contained in:
@@ -667,11 +667,13 @@ fn bool_row(ui: &mut egui::Ui, d: &mut Dialog, key: &str, label: &str) {
|
||||
fn labeled(ui: &mut egui::Ui, label: &str, add: impl FnOnce(&mut egui::Ui)) {
|
||||
let t = Tokens::get(ui.ctx());
|
||||
ui.horizontal(|ui| {
|
||||
ui.allocate_ui_with_layout(egui::vec2(210.0, 22.0), egui::Layout::left_to_right(egui::Align::Center), |ui| {
|
||||
ui.set_min_width(210.0);
|
||||
ui.add(egui::Label::new(egui::RichText::new(format!("{}{}", tl!(label), tl!(":"))).color(t.text)).truncate());
|
||||
});
|
||||
add(ui);
|
||||
let label = ui
|
||||
.allocate_ui_with_layout(egui::vec2(210.0, 22.0), egui::Layout::left_to_right(egui::Align::Center), |ui| {
|
||||
ui.set_min_width(210.0);
|
||||
ui.add(egui::Label::new(egui::RichText::new(format!("{}{}", tl!(label), tl!(":"))).color(t.text)).truncate())
|
||||
})
|
||||
.inner;
|
||||
ui.label_inputs_by(label.id, add);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -955,6 +955,27 @@ fn ok_refuses_a_typed_folder_that_choose_would_refuse() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// Preferences form rows associate each input with its visible label for accessibility tools.
|
||||
#[test]
|
||||
fn preference_inputs_expose_their_visible_labels() {
|
||||
use egui_kittest::kittest::Queryable;
|
||||
let mut app = app();
|
||||
open(&mut app, Some("General"));
|
||||
let mut fonts = false;
|
||||
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(900.0, 700.0)).with_accessibility_check(false).build_ui_state(
|
||||
move |ui, app: &mut VectorcraftApp| {
|
||||
if !std::mem::replace(&mut fonts, true) {
|
||||
crate::theme::install_fonts(ui.ctx());
|
||||
return;
|
||||
}
|
||||
show(app, ui.ctx());
|
||||
},
|
||||
app,
|
||||
);
|
||||
h.run_steps(3);
|
||||
let _ = h.get_by_role_and_label(egui::accesskit::Role::TextInput, "Keyboard Increment:");
|
||||
}
|
||||
|
||||
/// Under automation roots, OK refuses a typed folder outside them before it looks at the folder.
|
||||
#[test]
|
||||
fn ok_refuses_a_typed_folder_outside_the_automation_roots_before_looking_at_it() {
|
||||
|
||||
Reference in New Issue
Block a user