From d203255ec20bb6e3b2917dd4aee53dee3a090137 Mon Sep 17 00:00:00 2001 From: Aylur Date: Wed, 11 Sep 2024 22:39:15 +0000 Subject: add: stack widget --- core/src/meson.build | 1 + core/src/widget/box.vala | 2 +- core/src/widget/stack.vala | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 core/src/widget/stack.vala (limited to 'core/src') diff --git a/core/src/meson.build b/core/src/meson.build index 7cb7762..d7d3871 100644 --- a/core/src/meson.build +++ b/core/src/meson.build @@ -39,6 +39,7 @@ sources = [ 'widget/overlay.vala', 'widget/scrollable.vala', 'widget/slider.vala', + 'widget/stack.vala', 'widget/widget.vala', 'widget/window.vala', 'astal.vala', diff --git a/core/src/widget/box.vala b/core/src/widget/box.vala index 6bd1bcb..d522967 100644 --- a/core/src/widget/box.vala +++ b/core/src/widget/box.vala @@ -7,7 +7,7 @@ public class Box : Gtk.Box { } /** - * wether to implicity destroy previous children when setting them + * whether to implicity destroy previous children when setting them */ public bool no_implicit_destroy { get; set; default = false; } 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 children { + set { _set_children(value); } + owned get { return get_children(); } + } + + private void _set_children(List 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()); + } + } + } +} -- cgit v1.2.3