Custom GtkHeaderBar



I'd like to create a custom GtkHeaderBar in GTK 3.22.

If I use GtkBox as the header, it can draw the background color.
If I use a class inherited from GtkBox, it draws the transparent color.

Seems GtkBox uses rgba from ".titlebar:not(headerbar)" of gtk-contained.css:1736 but the inherited class uses "window.csd > .titlebar:not(headerbar)" of gtk-contained.css:2041 from Inspector.

How can I set the non-transparent color in the inherited class?
The following is the test code.

public class CustomHeader : Gtk.Box {
    public CustomHeader(Gtk.Orientation orientation,
                        int             spacing) {
        GLib.Object(
            orientation : orientation,
            spacing : spacing
        );
    }
}

public class TestWindow : Gtk.Window {
    public TestWindow() {
        GLib.Object(
            type : Gtk.WindowType.TOPLEVEL
        );

#if USE_HBOX
        var header = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
#else
        var header = new CustomHeader(Gtk.Orientation.HORIZONTAL, 0);
#endif
        header.set_css_name("headerbar");
        var vvbox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
        header.pack_start(vvbox, true, true, 0);
        var label = new Gtk.Label("Title");
        label.get_style_context().add_class("title");
        vvbox.pack_start(label, true, false, 0);
        var sub_label = new Gtk.Label("Subtitle");
        sub_label.get_style_context().add_class("subtitle");
        vvbox.pack_start(sub_label, true, false, 0);
        set_titlebar(header);
        var vbox = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
        add(vbox);
        var llabel = new Gtk.Label("test");
        vbox.pack_start(llabel, true, true, 0);
    }

    public static int main (string[] args) {
        Gtk.init (ref args);

        var window = new TestWindow();
        window.show_all();

        Gtk.main();
        return 0;
    }
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]