Unexpected size allocation when using halign=Center
Steps to reproduce
I have an image using the Picture widget inside a horizontally and vertically centered GtkBox, that takes up (or is allocated to) more space then it needs.
The setup:
-> MainWindow
-> GtkBox
-> PictureWidget
Here is a MWE in C that displays the behaviour, compiled with:
gcc $(pkg-config --cflags gtk4) -o main main.c $(pkg-config --libs gtk4)
.
Current behavior
The Picture widget is taking up more space then its natural width, when selecting the object with Inspector it looks like the following:
The "margins" are not contained in the image file itself, when the window is resized so there is no room for the empty space the image is not shrunk. (So it is not a static margin that is added)
Expected outcome
I expect the GtkBox with halign = Center to allocate precisely its natural size.
Version information
- Gtk version: 4.16.5
- OS: Fedora 41
- Wayland
- Driver: mesa 24.3.2
Additional information
This seems like such a common usecase / pattern that I feel like I am missing something, I asked about this in the Matrix chat but didn't figure it out with the help I got there.