summaryrefslogtreecommitdiff
path: root/core/src/widget/stack.vala
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/widget/stack.vala')
-rw-r--r--core/src/widget/stack.vala34
1 files changed, 34 insertions, 0 deletions
diff --git a/core/src/widget/stack.vala b/core/src/widget/stack.vala
new file mode 100644
index 0000000..d1d345f
--- /dev/null
+++ b/core/src/widget/stack.vala
@@ -0,0 +1,34 @@
+public class Astal.Switch : Gtk.Stack {
+ /**
+ * whether to implicity destroy previous children when setting them
+ */
+ public bool no_implicit_destroy { get; set; default = 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()) {
+ if (no_implicit_destroy)
+ remove(child);
+ else if (arr.find(child).length() == 0)
+ child.destroy();
+ }
+
+ var i = 0;
+ foreach(var child in arr) {
+ if (child.name != null) {
+ add_named(child, child.name);
+ } else {
+ add_named(child, (++i).to_string());
+ }
+ }
+ }
+}