Skip to content

Commit

Permalink
SwitchModelButton: set accessible label, description, and state
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Jun 19, 2024
1 parent 5fcab34 commit e98b2c4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/Widgets/SwitchModelButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Granite.SwitchModelButton : Gtk.ToggleButton {
hexpand = true,
vexpand = true,
max_width_chars = 25,
mnemonic_widget = this
};

var description_label = new Gtk.Label (null) {
Expand All @@ -68,9 +69,11 @@ public class Granite.SwitchModelButton : Gtk.ToggleButton {
};
button_switch.set_parent (this);

accessible_role = SWITCH;

bind_property ("text", label, "label");
bind_property ("description", description_label, "label");
bind_property ("active", button_switch, "active", GLib.BindingFlags.BIDIRECTIONAL);
bind_property ("active", button_switch, "active", BIDIRECTIONAL | SYNC_CREATE);

var controller = new Gtk.GestureClick ();
add_controller (controller);
Expand All @@ -80,7 +83,13 @@ public class Granite.SwitchModelButton : Gtk.ToggleButton {
button_switch.activate ();
});

notify["active"].connect (() => {
update_state (Gtk.AccessibleState.CHECKED, active, -1);
});

notify["description"].connect (() => {
update_property (Gtk.AccessibleProperty.DESCRIPTION, description, -1);

if (description == null || description == "") {
box.remove (description_revealer);
} else {
Expand Down

0 comments on commit e98b2c4

Please sign in to comment.