On Mon, 2017-05-08 at 08:42 +0100, Emmanuele Bassi wrote:
> On 7 May 2017 at 20:57, Richard Shann <rich...@rshann.plus.com> wrote:
> > On Sun, 2017-05-07 at 19:52 +0000, Emmanuele Bassi wrote:
> >>
> >> On Sun, 7 May 2017 at 19:53, Richard Shann <rich...@rshann.plus.com>
> >> wrote:
> >>
> >>         On Sun, 2017-05-07 at 17:54 +0100, Emmanuele Bassi wrote:
> >>         > On 7 May 2017 at 16:52, Richard Shann
> >>         <rich...@rshann.plus.com> 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
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to