summaryrefslogtreecommitdiff
path: root/lib/astal/gtk4/src/widget/box.vala
blob: 28f2b003e0deb93427eb86ace511d3e7142da86d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
public class Astal.Box : Gtk.Box {
    /**
     * Corresponds to [[email protected] :orientation].
     */
    [CCode (notify = false)]
    public bool vertical {
        get { return orientation == Gtk.Orientation.VERTICAL; }
        set { orientation = value ? Gtk.Orientation.VERTICAL : Gtk.Orientation.HORIZONTAL; }
    }

    construct {
        notify["orientation"].connect(() => {
            notify_property("vertical");
        });
    }

    public List<weak Gtk.Widget> children {
        set {
            foreach (var child in children) {
                remove(child);
            }
            foreach (var child in value) {
                append(child);
            }
        }
        owned get {
            var list = new List<weak Gtk.Widget>();
            var child = get_first_child();
            while (child != null) {
                list.append(child);
                child = child.get_next_sibling();
            }
            return list;
        }
    }

    public Gtk.Widget? child {
        owned get {
            foreach (var child in children) {
                return child;
            }
            return null;
        }
        set {
            var list = new List<weak Gtk.Widget>();
            list.append(child);
            this.children = children;
        }
    }
}