forked from AuroraMiddleware/gtk
Use gtk_window_set_titlebar in testheaderbar
This demonstrates how custom titlebars work both with and without csd.
This commit is contained in:
parent
30d0542309
commit
55969a8a0c
@ -1,7 +1,24 @@
|
|||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
|
|
||||||
static const gchar css[] =
|
static const gchar css[] =
|
||||||
".header { -GtkWidget-window-dragging: true; }";
|
".background { "
|
||||||
|
" background-image: -gtk-gradient (linear, center top, center bottom, "
|
||||||
|
" from (red), "
|
||||||
|
" to (blue)); "
|
||||||
|
" border-radius: 10px 10px 0px 0px; "
|
||||||
|
" border-width: 0px; "
|
||||||
|
"}"
|
||||||
|
".titlebar:backdrop { "
|
||||||
|
" background-image: none; "
|
||||||
|
" background-color: @bg_color; "
|
||||||
|
" border-radius: 10px 10px 0px 0px; "
|
||||||
|
"}"
|
||||||
|
".titlebar { "
|
||||||
|
" background-image: -gtk-gradient (linear, center top, center bottom, "
|
||||||
|
" from (white), "
|
||||||
|
" to (@bg_color)); "
|
||||||
|
" border-radius: 10px 10px 0px 0px; "
|
||||||
|
"}";
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char *argv[])
|
main (int argc, char *argv[])
|
||||||
@ -18,13 +35,8 @@ main (int argc, char *argv[])
|
|||||||
|
|
||||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
|
|
||||||
gtk_widget_realize (window);
|
|
||||||
gdk_window_set_decorations (gtk_widget_get_window (window),
|
|
||||||
GDK_DECOR_BORDER);
|
|
||||||
|
|
||||||
header = gtk_header_bar_new ();
|
header = gtk_header_bar_new ();
|
||||||
gtk_style_context_add_class (gtk_widget_get_style_context (header),
|
gtk_style_context_add_class (gtk_widget_get_style_context (header), "titlebar");
|
||||||
"header");
|
|
||||||
provider = gtk_css_provider_new ();
|
provider = gtk_css_provider_new ();
|
||||||
gtk_css_provider_load_from_data (provider, css, -1, NULL);
|
gtk_css_provider_load_from_data (provider, css, -1, NULL);
|
||||||
gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (window),
|
gtk_style_context_add_provider_for_screen (gtk_widget_get_screen (window),
|
||||||
@ -38,16 +50,16 @@ main (int argc, char *argv[])
|
|||||||
|
|
||||||
gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button);
|
gtk_header_bar_pack_end (GTK_HEADER_BAR (header), button);
|
||||||
|
|
||||||
|
gtk_window_set_titlebar (GTK_WINDOW (window), header);
|
||||||
|
|
||||||
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||||
|
|
||||||
gtk_container_add (GTK_CONTAINER (window), box);
|
gtk_container_add (GTK_CONTAINER (window), box);
|
||||||
|
|
||||||
gtk_box_pack_start (GTK_BOX (box), header, FALSE, FALSE, 0);
|
|
||||||
|
|
||||||
footer = gtk_header_bar_new ();
|
footer = gtk_header_bar_new ();
|
||||||
gtk_header_bar_pack_start (GTK_HEADER_BAR (footer), gtk_button_new_with_label ("Start"));
|
gtk_header_bar_pack_start (GTK_HEADER_BAR (footer), gtk_button_new_with_label ("Start"));
|
||||||
gtk_header_bar_set_custom_title (GTK_HEADER_BAR (footer), gtk_check_button_new_with_label ("Middle"));
|
gtk_header_bar_set_custom_title (GTK_HEADER_BAR (footer), gtk_check_button_new_with_label ("Middle"));
|
||||||
gtk_header_bar_pack_end (GTK_HEADER_BAR (footer), gtk_button_new_with_label ("End"));
|
gtk_header_bar_pack_end (GTK_HEADER_BAR (footer), gtk_button_new_with_label ("End 1"));
|
||||||
|
gtk_header_bar_pack_end (GTK_HEADER_BAR (footer), gtk_button_new_with_label ("End 2"));
|
||||||
gtk_box_pack_end (GTK_BOX (box), footer, FALSE, FALSE, 0);
|
gtk_box_pack_end (GTK_BOX (box), footer, FALSE, FALSE, 0);
|
||||||
|
|
||||||
content = gtk_image_new_from_icon_name ("start-here-symbolic", GTK_ICON_SIZE_DIALOG);
|
content = gtk_image_new_from_icon_name ("start-here-symbolic", GTK_ICON_SIZE_DIALOG);
|
||||||
@ -55,7 +67,6 @@ main (int argc, char *argv[])
|
|||||||
|
|
||||||
gtk_box_pack_start (GTK_BOX (box), content, FALSE, TRUE, 0);
|
gtk_box_pack_start (GTK_BOX (box), content, FALSE, TRUE, 0);
|
||||||
|
|
||||||
|
|
||||||
gtk_widget_show_all (window);
|
gtk_widget_show_all (window);
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
|
Loading…
Reference in New Issue
Block a user