From 63fbc9a4eef68992a8ce63d6fbce3efa7dc346f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cclaudio-code=E2=80=9D?= Date: Thu, 14 Mar 2024 21:21:58 -0300 Subject: [PATCH] Added examples who uses it with screen reader --- book/src/accessibility.md | 44 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/book/src/accessibility.md b/book/src/accessibility.md index 15b1902a0d8a..7bc526a5c6e6 100644 --- a/book/src/accessibility.md +++ b/book/src/accessibility.md @@ -10,4 +10,48 @@ Bugs in your code, your code can design fall, widgets, relations or incorrect st Roles like AccessibleRole::Button can affect presentation, keyboard focus, relationship with other elements. +When adding Switch accessible role we are saying for assistive technologies that that component will have the keyboard interactions expected by a switch. +```rust ,no_run,compile_fail + +let switch = Switch::builder() + .active(true) + .accessible_role(AccessibleRole::Switch) + .build(); +``` + +For example With it code, we add description with Property::Description will be read when enable screen reader and move the mouse over the button. + +```rust ,no_run,compile_fail +#use gtk::accessible::Property; +#use gtk::{glib, Application, Button}; +#use gtk::{prelude::*, AccessibleRole, ApplicationWindow}; +# +fn main() -> glib::ExitCode { + let app = Application::builder() + .application_id("org.test.accessible") + .build(); + app.connect_activate(build_ui); + app.run() +} + +fn build_ui(app: &Application) { + let button = Button::builder() + .label("error") + .margin_end(11) + .margin_top(11) + .margin_start(11) + .margin_bottom(11) + .accessible_role(AccessibleRole::Button) + .build(); + button.update_property(&[ + Property::Description("It is accessible label to help people to understend it button"), + ]); + let window = ApplicationWindow::builder() + .application(app) + .title("accessible example") + .child(&button) + .build(); + window.present(); +} +```