GTK4 margins -- is unit pixels, points or what else

I am currently writing some examples and explanations for Nim with GTK4.

Started with https://gitlab.gnome.org/GNOME/gtk/-/blob/master/tests/simple.c Comparing the C GTK3, the C GTK4 and the Nim version of it. Of course we know that this old GTK2 style is deprecated – the rest of the text will only use the new app style for all examples. But that example contains

gtk_widget_set_margin_top (button, 10);
gtk_widget_set_margin_bottom (button, 10);
gtk_widget_set_margin_start (button, 10);
gtk_widget_set_margin_end (button, 10);

Obviously the literal value 10 is very arbitrary. It should match in some way the user selected font size. In HTML and CSS often em and ex units are used instead of points. So is the literal 10 above a point, that is generally 1/72 inch, or a pixel. And does it depend on user display configuration? I think the Gnome desktop has some HiDPI settings which may modify the layout.

It’s pixels. All the API in GTK is pixel based.

The CSS style engine can use other units when it comes to lengths.

All pixels in GTK are logical pixels, as opposed to physical ones. In other words: the size of a β€œpixel” depends on the scaling factor applied to the widget.

2 Likes

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