Skip to content

Commit

Permalink
gtk: Rework AccessibleExtManual
Browse files Browse the repository at this point in the history
Adds compile-time type safety to accessible properties, relations and
states.
  • Loading branch information
jf2048 authored and bilelmoussaoui committed Jan 4, 2022
1 parent a03f57d commit 8a89be8
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 35 deletions.
9 changes: 8 additions & 1 deletion examples/custom_widget/ex_button/imp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ impl ObjectSubclass for ExButton {

// Make it look like a GTK button.
klass.set_css_name("button");

// Make it appear as a button to accessibility tools.
klass.set_accessible_role(gtk::AccessibleRole::Button);
}
}

Expand All @@ -39,13 +42,17 @@ impl ObjectImpl for ExButton {
self.parent_constructed(obj);

// Create the child label.
let child = gtk::Label::new(Some("Hello world!"));
let label = "Hello world!";
let child = gtk::Label::new(Some(label));
child.set_parent(obj);
*self.child.borrow_mut() = Some(child.upcast::<gtk::Widget>());

// Make it look like a GTK button with a label (as opposed to an icon).
obj.add_css_class("text-button");

// Tell accessibility tools the button has a label.
obj.update_property(&[gtk::accessible::Property::Label(label)]);

// Connect a gesture to handle clicks.
let gesture = gtk::GestureClick::new();
gesture.connect_released(|gesture, _, _, _| {
Expand Down
3 changes: 2 additions & 1 deletion examples/custom_widget/ex_button/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ use gtk::glib;

glib::wrapper! {
pub struct ExButton(ObjectSubclass<imp::ExButton>)
@extends gtk::Widget;
@extends gtk::Widget,
@implements gtk::Accessible;
}

impl Default for ExButton {
Expand Down
Loading

0 comments on commit 8a89be8

Please sign in to comment.