diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2012-05-24 14:14:17 -0400 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2012-05-30 13:17:23 -0400 |
commit | 98fa2a39bc87f6857ec38173d45b1801088099cd (patch) | |
tree | b5fbdec97167c0b583c6a862d95c35ae30755cfb /demos | |
parent | 64611054293d06a8b5ccdc41580ed3d3a805577e (diff) | |
download | gtk+-98fa2a39bc87f6857ec38173d45b1801088099cd.tar.gz |
gtk-demo: add a test for a CSS accordion
Diffstat (limited to 'demos')
-rw-r--r-- | demos/gtk-demo/Makefile.am | 2 | ||||
-rw-r--r-- | demos/gtk-demo/brick.png | bin | 0 -> 11104 bytes | |||
-rw-r--r-- | demos/gtk-demo/css_accordion.c | 77 | ||||
-rw-r--r-- | demos/gtk-demo/css_accordion.css | 52 | ||||
-rw-r--r-- | demos/gtk-demo/demo.gresource.xml | 3 |
5 files changed, 134 insertions, 0 deletions
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am index 7ef52f7109..52e38df068 100644 --- a/demos/gtk-demo/Makefile.am +++ b/demos/gtk-demo/Makefile.am @@ -15,6 +15,7 @@ demos = \ clipboard.c \ colorsel.c \ combobox.c \ + css_accordion.c \ css_basics.c \ dialog.c \ drawingarea.c \ @@ -113,6 +114,7 @@ RESOURCES= application.ui \ theming.ui \ gtk-logo-24.png \ gtk-logo-48.png \ + css_accordion.css \ css_basics.css \ fancy.css \ reset.css diff --git a/demos/gtk-demo/brick.png b/demos/gtk-demo/brick.png Binary files differnew file mode 100644 index 0000000000..e5ea7792c9 --- /dev/null +++ b/demos/gtk-demo/brick.png diff --git a/demos/gtk-demo/css_accordion.c b/demos/gtk-demo/css_accordion.c new file mode 100644 index 0000000000..c101061836 --- /dev/null +++ b/demos/gtk-demo/css_accordion.c @@ -0,0 +1,77 @@ +/* CSS Theming/CSS Accordion + * + * A simple accordion demo written using CSS transitions and multiple backgrounds + * + */ + +#include <gtk/gtk.h> + +static GtkWidget *window = NULL; + +static void +apply_css (GtkWidget *widget, GtkStyleProvider *provider) +{ + gtk_style_context_add_provider (gtk_widget_get_style_context (widget), provider, G_MAXUINT); + if (GTK_IS_CONTAINER (widget)) + gtk_container_forall (GTK_CONTAINER (widget), (GtkCallback) apply_css, provider); +} + +GtkWidget * +do_css_accordion (GtkWidget *do_widget) +{ + if (!window) + { + GtkWidget *container, *child; + GtkStyleProvider *provider; + GBytes *bytes; + gsize data_size; + const guint8 *data; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_transient_for (GTK_WINDOW (window), GTK_WINDOW (do_widget)); + gtk_window_set_default_size (GTK_WINDOW (window), 600, 300); + g_signal_connect (window, "destroy", + G_CALLBACK (gtk_widget_destroyed), &window); + + container = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_widget_set_halign (container, GTK_ALIGN_CENTER); + gtk_widget_set_valign (container, GTK_ALIGN_CENTER); + gtk_container_add (GTK_CONTAINER (window), container); + + child = gtk_button_new_with_label ("This"); + gtk_container_add (GTK_CONTAINER (container), child); + + child = gtk_button_new_with_label ("Is"); + gtk_container_add (GTK_CONTAINER (container), child); + + child = gtk_button_new_with_label ("A"); + gtk_container_add (GTK_CONTAINER (container), child); + + child = gtk_button_new_with_label ("CSS"); + gtk_container_add (GTK_CONTAINER (container), child); + + child = gtk_button_new_with_label ("Accordion"); + gtk_container_add (GTK_CONTAINER (container), child); + + child = gtk_button_new_with_label (":-)"); + gtk_container_add (GTK_CONTAINER (container), child); + + provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ()); + bytes = g_resources_lookup_data ("/css_accordion/gtk.css", 0, NULL); + data = g_bytes_get_data (bytes, &data_size); + + gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider), data, data_size, NULL); + + apply_css (window, provider); + } + + if (!gtk_widget_get_visible (window)) + gtk_widget_show_all (window); + else + { + gtk_widget_destroy (window); + window = NULL; + } + + return window; +} diff --git a/demos/gtk-demo/css_accordion.css b/demos/gtk-demo/css_accordion.css new file mode 100644 index 0000000000..ffca895b08 --- /dev/null +++ b/demos/gtk-demo/css_accordion.css @@ -0,0 +1,52 @@ +@import url("reset.css"); + +* { + transition-property: color, background-color, border-color, background-image, padding, border-width; + transition-duration: 1s; + + font: Cantarell 20px; +} + +GtkWindow { + background: linear-gradient(153deg, #151515, #151515 5px, transparent 5px) 0 0, + linear-gradient(333deg, #151515, #151515 5px, transparent 5px) 10px 5px, + linear-gradient(153deg, #222, #222 5px, transparent 5px) 0 5px, + linear-gradient(333deg, #222, #222 5px, transparent 5px) 10px 10px, + linear-gradient(90deg, #1b1b1b, #1b1b1b 10px, transparent 10px), + linear-gradient(#1d1d1d, #1d1d1d 25%, #1a1a1a 25%, #1a1a1a 50%, transparent 50%, transparent 75%, #242424 75%, #242424); + background-color: #131313; + background-size: 20px 20px; +} + +.button { + color: black; + background-color: #bbb; + border-style: solid; + border-width: 2px 0 2px 2px; + border-color: #333; + + padding: 12px 4px; +} + +.button:first-child { + border-radius: 5px 0 0 5px; +} + +.button:last-child { + border-radius: 0 5px 5px 0; + border-width: 2px; +} + +.button:hover { + padding: 12px 48px; + background-color: #4870bc; +} + +.button *:hover { + color: white; +} + +.button:hover:active, +.button:active { + background-color: #993401; +}
\ No newline at end of file diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml index 67aeff4f1b..fa090f5e9d 100644 --- a/demos/gtk-demo/demo.gresource.xml +++ b/demos/gtk-demo/demo.gresource.xml @@ -11,6 +11,9 @@ <gresource prefix="/"> <file>reset.css</file> </gresource> + <gresource prefix="/css_accordion"> + <file alias="gtk.css">css_accordion.css</file> + </gresource> <gresource prefix="/css_basics"> <file alias="gtk.css">css_basics.css</file> </gresource> |