Skip to content

Commit

Permalink
SwitchModelButton: use box layout (#709)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeremy Wootten <[email protected]>
  • Loading branch information
danirabbit and jeremypw authored Mar 23, 2024
1 parent 11e5174 commit 61f1c03
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/Widgets/SwitchModelButton.vala
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,16 @@ public class Granite.SwitchModelButton : Gtk.ToggleButton {
child = description_label
};

layout_manager = new Gtk.BoxLayout (HORIZONTAL);

var box = new Gtk.Box (VERTICAL, 0);
box.append (label);
box.set_parent (this);

var button_switch = new Gtk.Switch () {
valign = Gtk.Align.START
};

var grid = new Gtk.Grid () {
column_spacing = 12
};
grid.attach (label, 0, 0);
grid.attach (button_switch, 1, 0, 1, 2);

child = grid;
button_switch.set_parent (this);

bind_property ("text", label, "label");
bind_property ("description", description_label, "label");
Expand All @@ -82,11 +81,17 @@ public class Granite.SwitchModelButton : Gtk.ToggleButton {

notify["description"].connect (() => {
if (description == null || description == "") {
grid.remove (description_revealer);
box.remove (description_revealer);
} else {
grid.attach (description_revealer, 0, 1);
box.append (description_revealer);
button_switch.bind_property ("active", description_revealer, "reveal-child", GLib.BindingFlags.SYNC_CREATE);
}
});
}

~SwitchModelButton () {
while (get_first_child () != null) {
get_first_child ().unparent ();
}
}
}

0 comments on commit 61f1c03

Please sign in to comment.