This repository has been archived by the owner on Mar 4, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 90
/
main.rs
52 lines (39 loc) · 1.44 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use gtk::prelude::*;
use gtk::{atk, gio};
fn build_ui(application: >k::Application) {
let window = gtk::ApplicationWindow::new(application);
window.set_title("Accessibility");
window.set_position(gtk::WindowPosition::Center);
let button = gtk::Button::with_label("Click me!");
let label = gtk::Label::new(Some("0"));
let vbox = gtk::Box::new(gtk::Orientation::Vertical, 0);
if let (Some(button_obj), Some(label_obj)) = (button.accessible(), label.accessible()) {
// We set the description
button_obj.set_description("Button to increase label value");
// Then we setup the relation saying that the label is linked to the button.
let relation_set = label_obj
.ref_relation_set()
.expect("Failed to get relation for label");
let relation = atk::Relation::new(&[button_obj], atk::RelationType::LabelFor);
relation_set.add(&relation);
}
vbox.add(&button);
vbox.add(&label);
window.add(&vbox);
button.connect_clicked(move |_| {
let value = label.text().parse().unwrap_or(0) + 1;
label.set_text(&value.to_string());
});
window.show_all();
}
fn main() {
let application = gtk::Application::new(
Some("com.github.accessibility"),
gio::ApplicationFlags::empty(),
);
application.connect_activate(|app| {
// We build the application UI.
build_ui(app);
});
application.run();
}