summaryrefslogtreecommitdiff
path: root/lib/astal/gtk4/src/widget/bin.vala
blob: 102957b73004f84387211dd86cbccb203ac69658 (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
/**
 * A widget with one child.
 * It is useful for deriving subclasses, since it provides common code needed for handling a single child widget.
 */
public class Astal.Bin : Gtk.Widget, Gtk.Buildable {
    construct { set_layout_manager(new Gtk.BinLayout()); }

    Gtk.Widget _child;
    public Gtk.Widget? child {
        get { return _child; }
        set {
            if (_child != null) {
                _child.unparent();
            }

            if (value != null) {
                _child = value;
                value.set_parent(this);
            }
        }
    }

    void add_child(Gtk.Builder builder, Object child, string? type) {
        if (child is Gtk.Widget) {
            this.child = child as Gtk.Widget;
        } else {
            base.add_child(builder, child, type);
        }
    }

    ~Bin() {
        if (child != null) {
            child.unparent();
        }
    }
}