Re: How to find CSS style syntax changes between Gtk 3.12 and Gtk 3.22
- From: Richard Shann <richard rshann plus com>
- To: Emmanuele Bassi <ebassi gmail com>
- Cc: "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org>
- Subject: Re: How to find CSS style syntax changes between Gtk 3.12 and Gtk 3.22
- Date: Mon, 08 May 2017 13:57:40 +0100
On Mon, 2017-05-08 at 12:28 +0100, Emmanuele Bassi wrote:
On 8 May 2017 at 12:04, Richard Shann <richard rshann plus com> wrote:
But I'd strongly recommend you use CSS classes instead of styling the
bare element name.
CSS selectors in GTK+ work exactly like the HTML counterpart; you can
style "div" or "p" directly, but it's often much more appropriate to
create a specific CSS class, like "green-background", and add it to
the widget you wish to style.
I didn't find anything describing creating a GtkWidgetClass in the
gtk3/stable documentation, it seems that there is a field in the
GtkWidget structure pointing to such a structure accessed via
GTK_WIDGET_GET_CLASS (widget)
Yes, this is part of basic GObject usage: each instance has a pointer
to its instantiating class structure.
so I imagine that using
gtk_widget_class_set_css_name (class, name)
could mean you would get control over the style of that widget and any
others whose class you assigned that name.
You don't have *control* over the style. You can *add* to the existing
style — which may include undoing what the existing style does, but
then you need to know what the style does, or essentially reset CSS
properties by using their initial state, see:
https://drafts.csswg.org/css-cascade-3/#initial
This is how CSS works. The only way for you to control the style of a
GTK+ application
I haven't thought about trying to control the style of my application,
just do things like creating a label with a certain background color.
is to ship your own theme, and load it in place of
the user theme.
CSS is a *very* powerful set of rules for rendering content using a
declarative syntax; it's *really* not a bunch of color definitions,
like the style system in GTK+ 2.x. You will need to learn how CSS
works in order to use it.
But I will have to wait for
Debian to catch up with Gtk 3.20 before I can seriously look at this.
And this is why I suggest you use a CSS class, instead;
Is that something different from the GtkWidgetClass that the widget has?
Are there a gtk_css_class_new() and a gtk_widget_assign_css_class()
functions to use them?
I'm completely at sea. Meanwhile for anyone with an application that has
to compile with versions of Gtk+ before and after version 3.20 here is
the code that is currently working for me to set the background color of
a widget:
8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><
static gchar *get_css_selector (GtkWidget *w)
{
static gchar *ret = NULL;
#if ((GTK_MAJOR_VERSION==3) && (GTK_MINOR_VERSION>=20))
g_free (ret);
ret = g_ascii_strdown (g_strdup (g_type_name (G_TYPE_FROM_INSTANCE (w))), -1);
return ret+3;
#else
ret = (gchar *)g_type_name (G_TYPE_FROM_INSTANCE (w));
return ret;
#endif
}
void set_background_color(GtkWidget *w, gchar *color)
{
GtkCssProvider *gcp;
GtkStyleContext *gsc;
gsc = gtk_widget_get_style_context(w);
gchar *type = get_css_selector(w);
gchar *str = g_strdup_printf ("%s {background-color: %s;}", type, color); //g_print ("%s", str);
gcp= gtk_css_provider_new();
gtk_css_provider_load_from_data(gcp, str, -1, 0);
g_free (str);
gtk_style_context_add_provider(gsc, GTK_STYLE_PROVIDER(gcp),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><8><
Thank you for your patience,
Richard Shann
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]