GTK 4 removes these GtkBox child properties, so you should stop using them. You can replace GtkBox:padding using the “margin” properties on your GtkBox child widgets.
Could someone please explain me whats the story with in “margin” property in GTK4?
The margin property was removed because we can’t have a shorthand version, like CSS does; in other words, we cannot have:
// 20px on every direction
g_object_set (widget, "margin", 20, NULL);
// 20px vertical direction, 30px horizontal direction
g_object_set (widget, "margin", 20, 30, NULL);
// different margins for each directions
g_object_set (widget, "margin", 10, 20, 30, 40, NULL);
An alternative would be to have margin-{start|end|top|bottom} properties, and a margin property that set them all to the same value; but the margin property would need to be write-only, as it wouldn’t make sense to read it.
In practice, margins are really more commonly set using GtkBuilder XML files; and even there, it’s less often the case of same margin in all directions. For instance, the padding in an horizontal Box would be set by the two margin-start and margin-end properties, whereas the padding in a vertical Box would be set by the two margin-top and margin-bottom properties.
Finally: margin properties are hard coded, and part of your layout. If you want to leave it to the theme, for instance to increase affordances for accessibility, you should be using CSS.
I have recently finally added a setMargin() procedure manually for the Nim bindings:
proc setMargin*(w: Widget; m: int) =
setMarginStart(w, m)
setMarginEnd(w, m)
setMarginTop(w, m)
setMarginBottom(w, m)
Because I had to set margins in some of the examples in the GTK4 Nim book to make widgets and their borders better visible, and I was not willing to waste four lines for that.