Re: Porting Gtk2 styles to Gtk3
- From: Emmanuele Bassi <ebassi gmail com>
- To: zahlenmeer gmx de
- Cc: "gtk-app-devel-list gnome org" <gtk-app-devel-list gnome org>
- Subject: Re: Porting Gtk2 styles to Gtk3
- Date: Sun, 13 Nov 2016 15:26:44 +0000
Hi;
On 12 November 2016 at 19:02, <zahlenmeer gmx de> wrote:
I am struggling how to translate operators of the form
color = &style->light[GTK_STATE_PRELIGHT];
into proper Gtk3. The documentation says:
"One notable difference is the reduction from fg/bg/text/base colors to
only foreground/background, in exchange the widget is able to render its
various elements with different CSS classes, which can be themed
independently."
Your issues with this task is that you're approaching it by thinking
that only the syntax to style widgets has changed — whereas the whole
rendering API has been changed, starting in GTK+ 3.x.
You cannot query a color from the style and then draw with it, because
GTK+ uses CSS to render, and CSS does not have "colors". You cannot
query the state of the CSS style and then try to mimic a subset of it
with your own rendering code. You cannot assume themes will support
your widgets
The styling machinery in GTK+ 3.x (and 4.x) is not like the one in
GTK+ 2.x, where you could just define a few solid colors; it's a
complex rendering API that influences sizing blending of different
elements. They are conceptually different.
First question would be: What do the different colors stand for anyway?
What does light and dark mean when it comes to rendering? For example, I
am using the Arc Theme which does not provide .light or .dark classes
for different widgets.
The whole theme provides a dark variant of itself; a theme variant is
literally a separate theme, with a "-dark" suffix, that gets loaded
automatically on application request. That's also why various themes
are written using SASS and other CSS pre-processors.
But I also don't want to provide an
application-specific CSS file because the application should follow the
system theme.
If you want a custom widget to render with the system theme then
you'll need to use the gtk_render_* API and apply the same classes you
wish to reuse, like "osd" or "dim-label" or "linked" or
"suggested-action".
If your application is using custom widgets, with custom rendering,
though, you *will* have to provide application-specific CSS. You can
try to integrate with common system themes, by creating different CSS
fragments and loading them up depending on the theme name.
The second question would be how style properties fit into this as well.
Some colors are set explicitly via style properties, but those are also
deprecated. What would be the way to replace those?
Style properties are replaced by CSS properties where appropriate.
I am looking for the recommended way/best practise of styling widgets,
not some hacks and workarounds. Can anybody help me?
The overall best practices are:
* do not style your widgets unless absolutely necessary; build
composite widgets and let the system theme handle them for you
* if you have custom widgets, always use the gtk_render_* API and the
appropriate CSS classes to let GTK+ render them
* if you have custom widgets and you wish to render them in specific
ways then assign them an application-specific CSS class, and ship an
application-specific CSS fragment
* if you have custom widgets and you wish them to be rendered
differently depending on the system theme, then you'll have to ship an
application-specific CSS fragment for each theme you wish to support
In short: if you want your application to look like the rest of the
system UI, regardless of theme, then you'll have to use GTK widgets
that themes can style generically; if you have custom widgetry, then
you'll have to ship your own CSS fragments — possibly with support for
multiple themes.
Ciao,
Emmanuele.
--
https://www.bassi.io
[@] ebassi [@gmail.com]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]