Tweaking the CSS stylesheet

One thing forgotten to be updated, the FAQ. Since the add of new themes, the correct folder to use is : ~/.config/darktable/themes (last folder needs to be created). And copying the CSS and editing it is just the easiest way but not the better. The better is to import the default CSS (or the one you want to edit by the @import line (just copy it from a default css (grey, dark or darker one for example) and edit the line to point to where the default css is. Then just copy parts you want to change and edit them. That’s easier to maintain after than having lot of lines not changed.

I will try to remember to propose an updated FAQ soon (no time this day and probably no more tomorrow).

1 Like

That is exactly what I want to do. But the first attempt was just to create a copy to test the functionality ( … and it did not work). Thank you for the fast clarification.

OK, all stylesheets in /opt/darktable/share/darktable/themes remain unchanged, tweaks are applied to a copy of darktable-elegant-grey.css in ~/.config/darktable/themes. The import chain is

~/.config/darktable/themes/darktable-elegant-grey.css
imports
/opt/darktable/share/darktable/themes/darktable-elegant-dark.css
which imports
/opt/darktable/share/darktable/themes/darktable-elegant-darker.css
which imports
/opt/darktable/share/darktable/themes/darktable.css

This works as expected, but two questions remain. The first is :

*
{ font-size: 0.9rem; }

works as expected, the components are scaled down by 10 % relative to the predefinded value of 1em from darktable.css. This is shown on the right side of the screenshot.


But using

*
{ font-size: 0.9em; }

scales down most components far more than 10%, most components become really tiny as shown on the left side of the screenshot. I’m not the super expert on CSS, but I used it several times, so I know about inheritance of properties and about scaling lengths of components (widths, heights, sizes…), overwriting properties by subsequent definitions. But the behaviour above seems curious to me.

Using 1rem or 1em generates the same result. Sizes of components appear identical. But scaling this size (whatever absolute value it represents) in both cases by a simple linear factor (0.9) behaves completely different. In the first case the result is as expected, in the latter case it is not. This scaling is simplest math. I’m wondering what happens here ?

The second question is related to the size of the label of the dropdown (see second screenshot). Scaling the font-size to 0.9rem as shown above has different impacts on the sizes of header_label, darktable_label, view_label on one side and view_dropdown on the other side.

dropdown
The code snippet below shows the relevant part taken from darktable.css.

#header_label,
#darktable_label,
#view_label,
#view_dropdown
{
background-color: transparent;
font-size: 1.5em;
margin:0;
border:0;
vpadding:0;
}

I wanted to compensate the different sizes by increasing the font-size of the dropdown. But nothing changes if I set for example

#view_dropdown
{
font-size: 2.5em;
}

in the local darktable-elegant-grey.css, while the same code for the other components works as expected. I looked for further appearances of #view_dropdown in darktable.css, but none of them should have an influence on the font-size. Again I’m wondering what happens ? Bug, or am I missing something fundamental ?

edit : there seems to be an issue uploading the screenshots (png files). Its shown “uploading…” when I drag an drop the images, but they are not shown.

second edit : I just figured out the answer to the first question

  • the unit rem always refers to the root element which in the present case is the size of the font delivered by GTK+3.
  • the unit em always refers to the parent of the actual element. In the present case this means that an element embedded into another element is scaled two times by the factor used (0.9 x 0.9 in the example above). And so on. The deeper an element is embedded into others the smaller it gets when scaling with unit em.

On this point of view in my opinion it would be more comfortable for the user, if darktable.css would always refer to the root element in line 163 by using font-size= 1rem. This would make tweaking the file simpler, because it is more predictable what is happening, when an (child, grandchild…) element is to be scaled later.

In CSS, em units scales the font size of the currently selected element. rem units scale the font size of the current element using the font size of the document’s root element. If the size of the root element and the current element differ, then rem and em will give different results.

@Mica
In CSS, em units scales the font size of the currently selected element. rem units scale the font size of the current element using the font size of the document’s root element. If the size of the root element and the current element differ, then rem and em will give different results.

Of course, but this is a very general remark. Why should we have two different “units” if they had the same function. So it is obvious that they behave different. But the problem is a bit more complicated and appears if your objects which you want to give a style, have a highly hierarchical structure (which is the case at the dartable GUI). The article https://alligator.io/css/rem-vs-em-units/ exactly decribes what I mean and gives some excellent examples. My conclusion of this article is : It would be a very approriate solution to set

font-size= 1rem

instead of 1em at line 163 of darktable.css. If a user wants to downscale all elements by 10%, he (she) only has to set font-size= 0.9rem and 95% of the work is done. Only some small tweaks ( about 4 or 5) have to be done for some elements to get a good looking and well balanced style.

rem is just rarely used and it’s difficult to think and adapt to all users cases/wanted uses and specific DPI scale factor used on different OS. And good thing about CSS is it’s quite easily tweakable. So feel free to adjust it as you want. That’s the goal of CSS themes.

rem is quite recent (2013) regardless of others CSS units and W3C just say that on their webpage units : “Because they are so new, they don’t work everywhere yet. But, as of early 2015, several browsers support them.” (CSS: em, px, pt, cm, in…)

Anyway, I will test if it could be better to change that (and verify which Gtk versions correctly renders this quite recent unit. I spent quite a lot of hours tweaking and adjust CSS to finish Aurélien big work on the UI and correct a lot of UI glitches. What I learnt making this work is that changing a parameter could sometimes breaks other parts (sometimes not visible at first). And I have read some different fonts rendering between Gtk+ 3.22 and 3.24… So we have to be careful.

I totally agree ! And I really appreciate your work. What I said is just a proposal resulting from the experiences I made the last days. I just modified to 0.9em and the result was a UI totally messed up. I had some previous experience using CSS, but last time I used it is some years ago. So I had to (re)learn and remember a lot of things. My fear is that users with less pre-experience on CSS will be massive confused if they get a totally messed up UI by just changing one single parameter : what the f… is this !? … and will quickly give up. Therefore I shared my experiences here. Another article about the discussion on using rem or em, and the pros and cons, can be found on REM vs EM – The Great Debate | Zell Liew .

Thank you, and please contiunue your great job !

1 Like

And thanks for sharing that. Most users will not change CSS and default CSS works great on many systems (seems that systems with Gtk+ 3.22 have some font glitches). So this problem is quite minor I think. Anyway, that doesn’t mean of course this can’t be improved. Maybe, use rem will help solve some glitches (or not).

On my monitor the “darktable-elegant-grey” style shows reddish artefacts in small fonts e.g. within the filmic box (see the “middle grey luminance” text below):

crop_1

As the standard darktable font works fine I copied “darktable-elegant-grey.css” and “darktable.css” to my personal themes- folder. I then renamed “darktable-elegant-grey.css” to “darktable-grey.css”. In “darktable-grey.css” I changed line 21:

OLD: @import url(“darktable-elegant-dark.css”);
NEW: @import url(“darktable.css”);

“darktable-grey” now uses the standard font with grey settings:

crop_2

Not as elegant :wink: but ok for me.

Greets,
Jürgen

This is probably the way your system is set to render fonts… The equivalent of clear type needs to be applied, but I don’t remember what it is called off the top of my head.

And that’s not as elegant as we make it. So it’s the way your OS render it that’s not good. Which following ones do you have ?

  • OS release ?
  • Gtk version used ?
  • If on Linux, which desktop environment ?
  • Default OS font and font size ?

And could you test by using darktable-elegant-grey.css (default one so your OLD line) and change on darktable.css theme line 163 from 1.0em to 1.0rem ? And post here what that renders ?

Hi, my OS is Win10, editing line 163 does not change anything. I have to apologize, but don´t have any clue which GTK is used. How can I find that ?

May be it is simply the res of my monitor that´s not sufficient for this font (1680 x 1050 ).

Greets
Jürgen

Don’t care about Gtk version if you are on Windows. I don’t use Windows so can’t help more here.
Thanks for testing change on line 163. I was quite sure that will not change anything but in case of…

I had a similar problem years ago (2013 I think) on an old windows xp system. There were settings (about settings -> screen settings -> advanced or similar) to tweak the way fonts are rendered and how anti aliasing should be applied (or not). I have a dim reminder that this improved the situation a bit, but the result was not satisfying. I remember that I had to install a third party tool (don’t remember the name, too long ago) which allowed further tweakings (for example the algorithm used for anti aliasing) and this helped more.
I moved to linux some month later (best decision of my life… :smile: ). So unfortunately I can’t tell you how to tweak this parameters in Windows 10. But I’m quite shure there are settings for this. Use a search engine to search for keywords like fonts rendering anti aliasing ClearType… You will get numerous results which can help you along.
Sorry, that’s not very precise, but as already stated before, I’m not using windows anymore.

1 Like

Thanks @Nilvus and @pehar for your replies! I think I can live with the standard font:

Just a thing about those using darktable on KDE. I’ve just read that from the last KDE Plasma 5.18 LTS release : “GTK application fonts and icons now respect your Plasma settings for improved visual integration.”

That’s just confirm that KDE doesn’t render correctly fonts for Gtk apps (so darktable) on previous 5.18 release. So that should be better with that last release. Most of the times of what I see when helping KDE users to have better font rendering was to adjust anti-aliasing options (for some cases I see, it’s quite similar for Windows).

dt 3.1.0+1383
Several changes have been implemented in the sylesheets during the last weeks. I did some tweeks to make the components of the sidebars smaller. At one point I’m struggeling : I want to shrink the font-size of the labels of the bauhaus-sliders (shown in green in the screenshot).

bauhaus-slider
I have found no way so far to do so. Which property has to be changed in the CSS stylesheet ? Or is it impossible to tweek this labels independent of the other parts of the sliders because they are hardcoded as part of the sliders ?

The following seems to work for me

#iop-plugin-ui
{
  font-size: 0.7em;
}

If you can work out how to run it, GTK+ Inspector is a useful tool for working out how to identify individual UI elements.

1 Like

Thank you very much, #iop-plugin-ui was the component I was looking for. With font-size: 0.9em everything is well balanced now.
I heard about GTKInspector before, but I was not aware that it is already installed. I only had to activate it (enabling keybindings for DEBUG mode). Very useful tool to identify UI items and their hierarchie. Thanks again for this tip and your support.

1 Like

If you haven’t spotted it the latest master has a new option in the ‘general’ section of the preferences dialog where you can key small CSS tweaks, allowing you to still use a core darktable theme without having to set up your own. That’s what I used to test the suggestion above.