How to find CSS style syntax changes between Gtk 3.12 and Gtk 3.22

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

How to find CSS style syntax changes between Gtk 3.12 and Gtk 3.22

Richard Shann
I have a test program that pops up a label with a customized background
and foreground color. This works in 3.12 using the syntax

"GtkLabel {background-color: #FFFF00;}"

and

"GtkLabel {color: #FF00FF;}"

but fails in 3.22

How can I track changes needed to CSS syntax from one version to another
in the documentation (mostly I struggle to find the correct syntax :( )

Any help appreciated: test code follows.

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><8><8><8><8><8><
//gcc -Wall TestStyleChange.c -o TestStyleChange `pkg-config --cflags --libs gtk+-3.0`

#include<gtk/gtk.h>
void set_background_color(GtkWidget *w, gchar *color)
{
GtkCssProvider *gcp;
GtkStyleContext *gsc;
gsc = gtk_widget_get_style_context(w);
const gchar *type = g_type_name (G_TYPE_FROM_INSTANCE (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);
}

void set_foreground_color(GtkWidget *w, gchar *color)
{
GtkCssProvider *gcp;
GtkStyleContext *gsc;
gsc = gtk_widget_get_style_context(w);
const gchar *type = g_type_name (G_TYPE_FROM_INSTANCE (w));
gchar *str = g_strdup_printf ("%s {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);
}

int main(int argc, char **argv)
 {
   gtk_init(&argc, &argv);

   GtkWidget *top_window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
   g_signal_connect (top_window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
   
   GtkWidget *eventbox = gtk_event_box_new ();
   GtkWidget *label=gtk_label_new("Label");
   
   set_background_color (label, "#FFFF00");
   set_foreground_color (label, "#FF00FF");
 
   gtk_widget_set_size_request(label, 400, 400);
   gtk_container_add (GTK_CONTAINER (eventbox), label);
   gtk_container_add (GTK_CONTAINER(top_window), eventbox);
   gtk_widget_show_all (top_window);

   gtk_main();

   return 0;  
 }


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><8><8><8><8><8><

Richard Shann

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: How to find CSS style syntax changes between Gtk 3.12 and Gtk 3.22

Emmanuele Bassi
On 7 May 2017 at 16:52, Richard Shann <[hidden email]> wrote:

> I have a test program that pops up a label with a customized background
> and foreground color. This works in 3.12 using the syntax
>
> "GtkLabel {background-color: #FFFF00;}"
>
> and
>
> "GtkLabel {color: #FF00FF;}"
>
> but fails in 3.22

The selector for labels is "label" since GTK+ 3.20.

> How can I track changes needed to CSS syntax from one version to another
> in the documentation (mostly I struggle to find the correct syntax :( )

The CSS selectors and classes for widgets and widget components were
not stable, or documented, until GTK+ 3.20, while themeing features
were still a work in progress driven by the requirements of theme
authors; starting from GTK+ 3.22, the 3.x series is now feature
frozen, and both the selectors and classes are considered API stable:

  https://blog.gtk.org/2016/09/01/versioning-and-long-term-stability-promise-in-gtk/

Each GTK+ widget class has its own styling documentation, for instance:

  https://developer.gnome.org/gtk3/stable/GtkLabel.html#id-1.3.8.2.10.3

Ciao,
 Emmanuele.

--
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: How to find CSS style syntax changes between Gtk 3.12 and Gtk 3.22

Richard Shann
On Sun, 2017-05-07 at 17:54 +0100, Emmanuele Bassi wrote:

> On 7 May 2017 at 16:52, Richard Shann <[hidden email]> wrote:
> > I have a test program that pops up a label with a customized
> background
> > and foreground color. This works in 3.12 using the syntax
> >
> > "GtkLabel {background-color: #FFFF00;}"
> >
> > and
> >
> > "GtkLabel {color: #FF00FF;}"
> >
> > but fails in 3.22
>
> The selector for labels is "label" since GTK+ 3.20.

Thank you very much for this. Is there a function to get the selector
for a widget? Sort of gchar *gtk_widget_get_css_selector (GtkWidget *w)
thing? Looking through a few widgets it seems the rule is chop off the
Gtk prefix and lower case what remains ... is that guaranteed?

Richard


_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: How to find CSS style syntax changes between Gtk 3.12 and Gtk 3.22

Emmanuele Bassi
On Sun, 7 May 2017 at 19:53, Richard Shann <[hidden email]> wrote:

> On Sun, 2017-05-07 at 17:54 +0100, Emmanuele Bassi wrote:
> > On 7 May 2017 at 16:52, Richard Shann <[hidden email]> wrote:
> > > I have a test program that pops up a label with a customized
> > background
> > > and foreground color. This works in 3.12 using the syntax
> > >
> > > "GtkLabel {background-color: #FFFF00;}"
> > >
> > > and
> > >
> > > "GtkLabel {color: #FF00FF;}"
> > >
> > > but fails in 3.22
> >
> > The selector for labels is "label" since GTK+ 3.20.
>
> Thank you very much for this. Is there a function to get the selector
> for a widget? Sort of gchar *gtk_widget_get_css_selector (GtkWidget *w)
> thing?


I'm not sure what would that accomplish. Could you elaborate?

Looking through a few widgets it seems the rule is chop off the
> Gtk prefix and lower case what remains ... is that guaranteed?


No, it's not. It's part of the API reference for a reason.

If somebody creates a custom widget, with a custom CSS element name, then
they will have to document it.

Ciao,
 Emmanuele.
--
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: How to find CSS style syntax changes between Gtk 3.12 and Gtk 3.22

Richard Shann
On Sun, 2017-05-07 at 19:52 +0000, Emmanuele Bassi wrote:

>
> On Sun, 7 May 2017 at 19:53, Richard Shann <[hidden email]>
> wrote:
>
>         On Sun, 2017-05-07 at 17:54 +0100, Emmanuele Bassi wrote:
>         > On 7 May 2017 at 16:52, Richard Shann
>         <[hidden email]> wrote:
>         > > I have a test program that pops up a label with a
>         customized
>         > background
>         > > and foreground color. This works in 3.12 using the syntax
>         > >
>         > > "GtkLabel {background-color: #FFFF00;}"
>         > >
>         > > and
>         > >
>         > > "GtkLabel {color: #FF00FF;}"
>         > >
>         > > but fails in 3.22
>         >
>         > The selector for labels is "label" since GTK+ 3.20.
>        
>         Thank you very much for this. Is there a function to get the
>         selector
>         for a widget? Sort of gchar *gtk_widget_get_css_selector
>         (GtkWidget *w)
>         thing?
>
>
> I'm not sure what would that accomplish. Could you elaborate?

It would enable my program to work. Currently it gets the string
"GtkLabel" from the type name of the widget, and that works for setting
the background color of various widgets in the program, replacing
deprecated calls.

>
>
>         Looking through a few widgets it seems the rule is chop off
>         the
>         Gtk prefix and lower case what remains ... is that guaranteed?
>
>
> No, it's not. It's part of the API reference for a reason.
>
> If somebody creates a custom widget, with a custom CSS element name,
> then they will have to document it.
>
yes, but surely there is no harm in you documenting what you do with the
widgets that come with Gtk in order to create a selector name? Otherwise
a) we have to look it up each time
b) we can't create it programmatically for programs like the one I
posted.

Richard

>


_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: How to find CSS style syntax changes between Gtk 3.12 and Gtk 3.22

Emmanuele Bassi
On 7 May 2017 at 20:57, Richard Shann <[hidden email]> wrote:

> On Sun, 2017-05-07 at 19:52 +0000, Emmanuele Bassi wrote:
>>
>> On Sun, 7 May 2017 at 19:53, Richard Shann <[hidden email]>
>> wrote:
>>
>>         On Sun, 2017-05-07 at 17:54 +0100, Emmanuele Bassi wrote:
>>         > On 7 May 2017 at 16:52, Richard Shann
>>         <[hidden email]> wrote:
>>         > > I have a test program that pops up a label with a
>>         customized
>>         > background
>>         > > and foreground color. This works in 3.12 using the syntax
>>         > >
>>         > > "GtkLabel {background-color: #FFFF00;}"
>>         > >
>>         > > and
>>         > >
>>         > > "GtkLabel {color: #FF00FF;}"
>>         > >
>>         > > but fails in 3.22
>>         >
>>         > The selector for labels is "label" since GTK+ 3.20.
>>
>>         Thank you very much for this. Is there a function to get the
>>         selector
>>         for a widget? Sort of gchar *gtk_widget_get_css_selector
>>         (GtkWidget *w)
>>         thing?
>>
>>
>> I'm not sure what would that accomplish. Could you elaborate?
>
> It would enable my program to work. Currently it gets the string
> "GtkLabel" from the type name of the widget, and that works for setting
> the background color of various widgets in the program, replacing
> deprecated calls.

I'm still puzzled as to why you need programmatic access to the CSS
element name.

Are you generating CSS fragments from a generic function with only the
widget type as the input?

You can use `gtk_widget_class_get_css_name()`:

  https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-class-get-css-name

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.

>>         Looking through a few widgets it seems the rule is chop off
>>         the
>>         Gtk prefix and lower case what remains ... is that guaranteed?
>>
>>
>> No, it's not. It's part of the API reference for a reason.
>>
>> If somebody creates a custom widget, with a custom CSS element name,
>> then they will have to document it.
>>
> yes, but surely there is no harm in you documenting what you do with the
> widgets that come with Gtk in order to create a selector name?

Yes, that's why it's documented.

> Otherwise
> a) we have to look it up each time

Well, you have to look up all API when using it.

> b) we can't create it programmatically for programs like the one I
> posted.

You cannot generate random CSS fragments and expect them to work regardless.

CSS state is complex, and it depends on the current user theme. That's
why the recommended approach is to use additional classes. Selectors
with higher specificity are easier to apply, much more efficient, and
generally speaking, much more clean to conceptually understand.

Ciao,
 Emmanuele.

--
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: How to find CSS style syntax changes between Gtk 3.12 and Gtk 3.22

Richard Shann
On Mon, 2017-05-08 at 08:42 +0100, Emmanuele Bassi wrote:

> On 7 May 2017 at 20:57, Richard Shann <[hidden email]> wrote:
> > On Sun, 2017-05-07 at 19:52 +0000, Emmanuele Bassi wrote:
> >>
> >> On Sun, 7 May 2017 at 19:53, Richard Shann <[hidden email]>
> >> wrote:
> >>
> >>         On Sun, 2017-05-07 at 17:54 +0100, Emmanuele Bassi wrote:
> >>         > On 7 May 2017 at 16:52, Richard Shann
> >>         <[hidden email]> wrote:
> >>         > > I have a test program that pops up a label with a
> >>         customized
> >>         > background
> >>         > > and foreground color. This works in 3.12 using the syntax
> >>         > >
> >>         > > "GtkLabel {background-color: #FFFF00;}"
> >>         > >
> >>         > > and
> >>         > >
> >>         > > "GtkLabel {color: #FF00FF;}"
> >>         > >
> >>         > > but fails in 3.22
> >>         >
> >>         > The selector for labels is "label" since GTK+ 3.20.
> >>
> >>         Thank you very much for this. Is there a function to get the
> >>         selector
> >>         for a widget? Sort of gchar *gtk_widget_get_css_selector
> >>         (GtkWidget *w)
> >>         thing?
> >>
> >>
> >> I'm not sure what would that accomplish. Could you elaborate?
> >
> > It would enable my program to work. Currently it gets the string
> > "GtkLabel" from the type name of the widget, and that works for setting
> > the background color of various widgets in the program, replacing
> > deprecated calls.
>
> I'm still puzzled as to why you need programmatic access to the CSS
> element name.
>
> Are you generating CSS fragments from a generic function with only the
> widget type as the input?

yes

>
> You can use `gtk_widget_class_get_css_name()`:
>
>   https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-class-get-css-name
>

thanks for alerting me to this. My development system is Debian Stable,
so I don't have access to this function as it is from 3.20, however it
gave me a starting point for looking at what will be possible.

> 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)

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. But I will have to wait for
Debian to catch up with Gtk 3.20 before I can seriously look at this.

Thanks again for your responses.

Richard Shann


_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: How to find CSS style syntax changes between Gtk 3.12 and Gtk 3.22

Emmanuele Bassi
On 8 May 2017 at 12:04, Richard Shann <[hidden email]> 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 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; CSS classes
work regardless of what the CSS name of a widget is.

Ciao,
 Emmanuele.

--
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: How to find CSS style syntax changes between Gtk 3.12 and Gtk 3.22

Richard Shann
On Mon, 2017-05-08 at 12:28 +0100, Emmanuele Bassi wrote:

> On 8 May 2017 at 12:04, Richard Shann <[hidden email]> 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



_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: How to find CSS style syntax changes between Gtk 3.12 and Gtk 3.22

Emmanuele Bassi
On 2017-05-08 at 13:57, Richard Shann wrote:
> On Mon, 2017-05-08 at 12:28 +0100, Emmanuele Bassi wrote:

> > > 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?

CSS classes are not related to widget classes.

https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors

> Are there a gtk_css_class_new() and a gtk_widget_assign_css_class()
> functions to use them?

You want `GtkStyleContext` and `gtk_style_context_add_class()`:

https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-get-style-context
https://developer.gnome.org/gtk3/stable/GtkStyleContext.html#gtk-style-context-add-class

> I'm completely at sea.

You probably want to read the API reference, then:

https://developer.gnome.org/gtk3/stable/theming.html

Additionally, you may want to read online resources about CSS.

> 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
> }

Please, don't do this.

This won't work for various widgets, and there's no guarantee it'll ever
work at all. There is *no* programmatic relationship between the CSS
element name and the type name.

For instance, `GtkRadioMenuItem` has a CSS element name called
`menuitem` and a sub-element called `radio`, with a `left` or `right`
class depending on the text direction. Thus, the selector is going to
be:

    menuitem radio { ... }

The GtkSeparatorMenuItem, on the other hand, has a single CSS element
name called `separator`.

Ciao,
 Emmanuele.

--
https://www.bassi.io
[@] ebassi [@gmail.com]
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: How to find CSS style syntax changes between Gtk 3.12 and Gtk 3.22

Richard Shann
On Wed, 2017-05-10 at 18:34 +0100, Emmanuele Bassi wrote:

> On 2017-05-08 at 13:57, Richard Shann wrote:
> > On Mon, 2017-05-08 at 12:28 +0100, Emmanuele Bassi wrote:
>
> > > > 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?
>
> CSS classes are not related to widget classes.
>
> https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors
>
> > Are there a gtk_css_class_new() and a gtk_widget_assign_css_class()
> > functions to use them?
>
> You want `GtkStyleContext` and `gtk_style_context_add_class()`:
>
> https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-get-style-context
> https://developer.gnome.org/gtk3/stable/GtkStyleContext.html#gtk-style-context-add-class
>
> > I'm completely at sea.
>
> You probably want to read the API reference, then:
>
> https://developer.gnome.org/gtk3/stable/theming.html

Thank you for the references. I had seen that stuff but was lost right
at the start, it would seem that a background in HTML would be helpful,
and

>
> Additionally, you may want to read online resources about CSS.

some notion about what CSS is. So I will have a lot of reading to do.

But, meanwhile, I see that the code I posted (which I didn't originate,
just cooked up from someone else's earlier posting) did use
`GtkStyleContext` though not 'gtk_style_context_add_class()' but rather
'gtk_style_context_add_provider()' so perhaps it is ok code, if the
lookup of the css selector were more robust.
I append a copy, in case anyone cares to point out deficiencies.

Richard Shann

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><
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><



_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list