RGBA and Dark themes

Anyone have any approaches to dealing with “dark” themes and using rgba colors?

For example I have the following shades of grey defined
my $rgbaedit1=Gtk3::Gdk::RGBA->new(0,0,0,0.1);
my $rgbaedit2=Gtk3::Gdk::RGBA->new(0,0,0,0.2);
my $rgbaedit3=Gtk3::Gdk::RGBA->new(0,0,0,0.3);
my $rgbaedit4=Gtk3::Gdk::RGBA->new(0,0,0,0.4);

Which are used to show contrast for various cells in treeviews

All looks good until I test with dark themes

Then of course the underlying very dark background floods through the alpha channel and makes the cells unreadable

I think I have the following choices

  1. Go through all the base widgets setting background to a light color
  2. Attempting to parse theme to see if it is dark
  3. Going back to using rgb or named colors without alpha channels


There aren’t standard or simple approaches, sorry. The truth of the matter is that setting colors is always going to conflict with some theme or other.

That is not really possible.

You can’t really do that either, because CSS backgrounds are not simply colors. Themes could use gradients, images, or blend modes between various layers. Unless you’re going to write a fully compliant CSS parser and then sample pixels at the end of a rendering, you won’t really know what colors comes out at the end before GTK knows it. This is also why GTK doesn’t provide any API to do this.

Or, possibly, stop using colors from your own application.

One option is to enforce at start up a specific theme—Adwaita, which is shipped by GTK, so you can always rely on its availability. Another option is to check the current UI against a whitelist of themes, and select the colors that look best with any of them; if the current theme is not in the whitelist, fall back to Adwaita.

I’m sorry, but themes are not really conducive to any form of stable UI or set of assumptions; they are not a tractable problem. The only way to make it tractable is to ship a theme with your application—or rely on GTK’s default theme—and ignore whatever theme the user decided to set.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.