diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-10-09 14:26:58 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-10-09 14:26:58 +0000 |
commit | b5f7d5712469309744375511c28dd330b5f46998 (patch) | |
tree | a4efca93f21ad3754470a89e8974be55fb05054f | |
parent | 6a6ef0f437ecdd2677b7b459d921980ddf77ca31 (diff) | |
parent | 0db5c7f421d117021e78741400840c0cf497c0c5 (diff) | |
download | gtk+-b5f7d5712469309744375511c28dd330b5f46998.tar.gz |
Merge branch 'matthiasc/for-main' into 'main'
gtk-demo: Modernize accordion demo
See merge request GNOME/gtk!5105
-rw-r--r-- | demos/gtk-demo/css_accordion.c | 33 | ||||
-rw-r--r-- | demos/gtk-demo/css_accordion.css | 20 | ||||
-rw-r--r-- | demos/gtk-demo/demo.gresource.xml | 1 | ||||
-rw-r--r-- | tests/animated-revealing.c | 6 | ||||
-rw-r--r-- | tests/testgtk.c | 26 |
5 files changed, 47 insertions, 39 deletions
diff --git a/demos/gtk-demo/css_accordion.c b/demos/gtk-demo/css_accordion.c index c544f8a02d..6d327a8aab 100644 --- a/demos/gtk-demo/css_accordion.c +++ b/demos/gtk-demo/css_accordion.c @@ -1,20 +1,16 @@ /* Theming/CSS Accordion * * A simple accordion demo written using CSS transitions and multiple backgrounds + * */ #include <gtk/gtk.h> static void -apply_css (GtkWidget *widget, GtkStyleProvider *provider) +destroy_provider (GtkWidget *window, + GtkStyleProvider *provider) { - GtkWidget *child; - - gtk_style_context_add_provider (gtk_widget_get_style_context (widget), provider, G_MAXUINT); - for (child = gtk_widget_get_first_child (widget); - child != NULL; - child = gtk_widget_get_next_sibling (child)) - apply_css (child, provider); + gtk_style_context_remove_provider_for_display (gtk_widget_get_display (window), provider); } GtkWidget * @@ -24,8 +20,8 @@ do_css_accordion (GtkWidget *do_widget) if (!window) { - GtkWidget *container, *child; - GtkStyleProvider *provider; + GtkWidget *container, *styled_box, *child; + GtkCssProvider *provider; window = gtk_window_new (); gtk_window_set_title (GTK_WINDOW (window), "CSS Accordion"); @@ -33,10 +29,13 @@ do_css_accordion (GtkWidget *do_widget) gtk_window_set_default_size (GTK_WINDOW (window), 600, 300); g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window); + styled_box = gtk_frame_new (NULL); + gtk_window_set_child (GTK_WINDOW (window), styled_box); + gtk_widget_add_css_class (styled_box, "accordion"); 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_window_set_child (GTK_WINDOW (window), container); + gtk_frame_set_child (GTK_FRAME (styled_box), container); child = gtk_button_new_with_label ("This"); gtk_box_append (GTK_BOX (container), child); @@ -56,10 +55,16 @@ do_css_accordion (GtkWidget *do_widget) child = gtk_button_new_with_label (":-)"); gtk_box_append (GTK_BOX (container), child); - provider = GTK_STYLE_PROVIDER (gtk_css_provider_new ()); - gtk_css_provider_load_from_resource (GTK_CSS_PROVIDER (provider), "/css_accordion/css_accordion.css"); + provider = gtk_css_provider_new (); + gtk_css_provider_load_from_resource (provider, "/css_accordion/css_accordion.css"); + + gtk_style_context_add_provider_for_display (gtk_widget_get_display (window), + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - apply_css (window, provider); + g_signal_connect (window, "destroy", + G_CALLBACK (destroy_provider), provider); + g_object_unref (provider); } if (!gtk_widget_get_visible (window)) diff --git a/demos/gtk-demo/css_accordion.css b/demos/gtk-demo/css_accordion.css index ce3346d78e..5d219da998 100644 --- a/demos/gtk-demo/css_accordion.css +++ b/demos/gtk-demo/css_accordion.css @@ -1,13 +1,13 @@ -@import url("resource://css_accordion/reset.css"); +.accordion, .accordion * { + all: unset; -* { transition-property: color, background-color, border-color, background-image, padding, border-width; transition-duration: 1s; font: 20px Cantarell; } -window { +.accordion { 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, @@ -18,7 +18,7 @@ window { background-size: 20px 20px; } -button { +.accordion button { color: black; background-color: #bbb; border-style: solid; @@ -28,25 +28,25 @@ button { padding: 12px 4px; } -button:first-child { +.accordion button:first-child { border-radius: 5px 0 0 5px; } -button:last-child { +.accordion button:last-child { border-radius: 0 5px 5px 0; border-width: 2px; } -button:hover { +.accordion button:hover { padding: 12px 48px; background-color: #4870bc; } -button *:hover { +.accordion button *:hover { color: white; } -button:hover:active, -button:active { +.accordion button:hover:active, +.accordion button:active { background-color: #993401; } diff --git a/demos/gtk-demo/demo.gresource.xml b/demos/gtk-demo/demo.gresource.xml index 65b87365e2..9eca1c16a7 100644 --- a/demos/gtk-demo/demo.gresource.xml +++ b/demos/gtk-demo/demo.gresource.xml @@ -24,7 +24,6 @@ </gresource> <gresource prefix="/css_accordion"> <file>css_accordion.css</file> - <file>reset.css</file> </gresource> <gresource prefix="/css_basics"> <file>css_basics.css</file> diff --git a/tests/animated-revealing.c b/tests/animated-revealing.c index 040e2c3e34..5e5f666a53 100644 --- a/tests/animated-revealing.c +++ b/tests/animated-revealing.c @@ -67,15 +67,15 @@ main(int argc, char **argv) cssprovider = gtk_css_provider_new (); gtk_css_provider_load_from_data (cssprovider, "* { padding: 2px; text-shadow: 5px 5px 2px grey; }", -1); + gtk_style_context_add_provider_for_display (gdk_display_get_default (), + GTK_STYLE_PROVIDER (cssprovider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); for (x = 0; x < 10; x++) { for (y = 0; y < 20; y++) { widget = gtk_label_new ("Hello World"); - gtk_style_context_add_provider (gtk_widget_get_style_context (widget), - GTK_STYLE_PROVIDER (cssprovider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); gtk_grid_attach (GTK_GRID (grid), widget, x, y, 1, 1); } } diff --git a/tests/testgtk.c b/tests/testgtk.c index 6de750e9b3..e7cebbc100 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -193,26 +193,30 @@ create_alpha_window (GtkWidget *widget) if (!window) { + static GtkCssProvider *provider = NULL; GtkWidget *content_area; GtkWidget *vbox; GtkWidget *label; GdkDisplay *display; - GtkCssProvider *provider; window = gtk_dialog_new_with_buttons ("Alpha Window", GTK_WINDOW (gtk_widget_get_root (widget)), 0, "_Close", 0, NULL); - provider = gtk_css_provider_new (); - gtk_css_provider_load_from_data (provider, - "dialog {\n" - " background: radial-gradient(ellipse at center, #FFBF00, #FFBF0000);\n" - "}\n", - -1); - gtk_style_context_add_provider (gtk_widget_get_style_context (window), - GTK_STYLE_PROVIDER (provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - g_object_unref (provider); + gtk_widget_add_css_class (window, "alpha"); + if (provider == NULL) + { + provider = gtk_css_provider_new (); + gtk_css_provider_load_from_data (provider, + "dialog.alpha {\n" + " background: radial-gradient(ellipse at center, #FFBF00, #FFBF0000);\n" + "}\n", + -1); + gtk_style_context_add_provider_for_display (gtk_widget_get_display (window), + GTK_STYLE_PROVIDER (provider), + GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + g_object_unref (provider); + } content_area = gtk_dialog_get_content_area (GTK_DIALOG (window)); |