Am Donnerstag, den 16.03.2017, 09:55 +0000 schrieb Rúben Rodrigues:
> Hi,
> 
> THanks. This is dynamically? I need in c language if possible :S

Dynamic version:

...

static GtkCssProvider* provider = NULL;

static void
set_label_color(GtkWidget* label, const char* color)
{
    const char* format = "label { color: %s; }";
    size_t length = strlen(format) - 2 + 1;
    char style[length];
    sprintf(style, format, color);

    if (provider == NULL) {
        /* only create and add the provider the first time */
        provider = gtk_css_provider_new();
        gtk_style_context_add_provider(
            gtk_widget_get_style_context(label),
            GTK_STYLE_PROVIDER(provider),
            GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
        g_object_unref(provider);
    }

    gtk_css_provider_load_from_data(provider, style, -1, NULL);
}

...

This might not be ideal in all situations. Just make sure you don't
create a new provider everytime you set a new color. Hope that helps.

--Tilo
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to