summaryrefslogtreecommitdiff
path: root/lib/astal/gtk3/src/widget/stack.vala
diff options
context:
space:
mode:
Diffstat (limited to 'lib/astal/gtk3/src/widget/stack.vala')
-rw-r--r--lib/astal/gtk3/src/widget/stack.vala40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/astal/gtk3/src/widget/stack.vala b/lib/astal/gtk3/src/widget/stack.vala
new file mode 100644
index 0000000..4e856a6
--- /dev/null
+++ b/lib/astal/gtk3/src/widget/stack.vala
@@ -0,0 +1,40 @@
+/**
+ * Subclass of [[email protected]] that has a children setter which
+ * invokes [[email protected]_named] with the child's [[email protected]:name] property.
+ */
+public class Astal.Stack : Gtk.Stack {
+ /**
+ * Same as [[email protected]:visible-child-name].
+ */
+ [CCode (notify = false)]
+ public string shown {
+ get { return visible_child_name; }
+ set { visible_child_name = value; }
+ }
+
+ public List<weak Gtk.Widget> children {
+ set { _set_children(value); }
+ owned get { return get_children(); }
+ }
+
+ private void _set_children(List<weak Gtk.Widget> arr) {
+ foreach(var child in get_children()) {
+ remove(child);
+ }
+
+ var i = 0;
+ foreach(var child in arr) {
+ if (child.name != null) {
+ add_named(child, child.name);
+ } else {
+ add_named(child, (++i).to_string());
+ }
+ }
+ }
+
+ construct {
+ notify["visible_child_name"].connect(() => {
+ notify_property("shown");
+ });
+ }
+}