Skip to content

Commit

Permalink
Added examples who uses it with screen reader
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudio-code committed Mar 15, 2024
1 parent 53f3ec6 commit 63fbc9a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions book/src/accessibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,48 @@ Bugs in your code, your code can design fall, widgets, relations or incorrect st

Roles like <a class=file-link href="https://gtk-rs.org/gtk4-rs/stable/latest/docs/gtk4/enum.AccessibleRole.html#variant.Button">AccessibleRole::Button</a> 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 <a class=file-link href="https://gtk-rs.org/gtk4-rs/git/docs/gtk4/accessible/enum.Property.html" >Property::Description</a> 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();
}
```

0 comments on commit 63fbc9a

Please sign in to comment.