From 976638c016eb21ade63779c9dade6110983dc75b Mon Sep 17 00:00:00 2001 From: Aylur Date: Wed, 19 Jun 2024 02:30:46 +0200 Subject: add(box): implicit_destroy this is a convinience property that is mostly useful in gjs and lua when binding children to a variable where these children set up connections themselves --- src/widget/box.vala | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/widget/box.vala b/src/widget/box.vala index 9993a38..d1c4a6b 100644 --- a/src/widget/box.vala +++ b/src/widget/box.vala @@ -6,6 +6,11 @@ public class Box : Gtk.Box { set { orientation = value ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; } } + /** + * wether to implicity destroy previous children when setting them + */ + public bool implicit_destroy { get; set; default = false; } + public List children { set { _set_children(value); } owned get { return get_children(); } @@ -36,8 +41,12 @@ public class Box : Gtk.Box { } private void _set_children(List arr) { - foreach(var child in get_children()) - remove(child); + foreach(var child in get_children()) { + if (implicit_destroy) + child.destroy(); + else + remove(child); + } foreach(var child in arr) add(child); -- cgit v1.2.3