summaryrefslogtreecommitdiff
path: root/lib/astal/gtk3/src/widget/centerbox.vala
blob: 0459c17ce103cc5e499d9a65f8163e57b3e79fb5 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
public class Astal.CenterBox : Gtk.Box, Gtk.Buildable {
    /**
     * 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");
        });
    }

    static construct {
        set_css_name("centerbox");
    }

    private Gtk.Widget _start_widget;
    public Gtk.Widget start_widget {
        get { return _start_widget; }
        set {
            if (_start_widget != null)
                remove(_start_widget);

            if (value != null)
                pack_start(value, true, true, 0);
        }
    }

    private Gtk.Widget _end_widget;
    public Gtk.Widget end_widget {
        get { return _end_widget; }
        set {
            if (_end_widget != null)
                remove(_end_widget);

            if (value != null)
                pack_end(value, true, true, 0);
        }
    }

    public Gtk.Widget center_widget {
        get { return get_center_widget(); }
        set {
            if (center_widget != null)
                remove(center_widget);

            if (value != null)
                set_center_widget(value);
        }
    }

    void add_child(Gtk.Builder builder, Object child, string? type) {
        if (child is Gtk.Widget) {
            switch (type) {
                case "start":
                    start_widget = child as Gtk.Widget;
                    break;
                case "center":
                    center_widget = child as Gtk.Widget;
                    break;
                case "end":
                    end_widget = child as Gtk.Widget;
                    break;
                default:
                    base.add_child(builder, child, type);
                    break;
            }
        } else {
            base.add_child(builder, child, type);
        }
    }
}