GTK4: Replacement for `pack-type`

Gtk+ 3 had an pack-type packing property which allowed to put an child to the other side of an GtkBox.

Since packing is now removed in GTK4, what would the ideal way of putting an item to the other side of an GtkBox?
I have seen some people using hexpand and halign, but that seems like an workaround rather than a solution…

The pack-type child property had various downsides, including the fact that it wasn’t immediately clear how it would interact with the styling system until the very end of the layout, and it complicated the layout machinery itself. The position in the box should not be controlled by a layout propery: it should be the index of the child widget.

Why would it be a workaround, when it’s precisely what the API is meant to be doing? The alignment flags control how a widget should occupy the area allocated by its parent; the expansion flags control whether a widget should be allocated that area in the first place.

It felt less meant for it than a literal “put it at the end” property.

But given your arguments, it does make sense. So halign and hexpand it is.

you can use gtk_box_prepend to place a child at the start of the children

or you can use gtk_box_insert_child_after to place a child somewhere in the middle

Sometimes to control the layout of the widgets inside a container you have to create dummy objects whose sole role are to occupy space or expand to push other objects to the end. Like here.

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