(In Gtk3) I am ordering elements in a GtkApplicationWindow. The app window’s top-level layout container is a GtkBox with vertical orientation. The box contains two elements, a GtkScrolledWindow (with a GtkTextView inside of it), and GtkLabel below for reporting messages.
I made sure the top-level Box and the GtkScrolledWindow both have their expand properties set to TRUE, and both have their valign and halign properties set to fill. I made sure to call pack_start with the expand and fill arguments set to TRUE when I insert the GtkScrolledWindow.
But for whatever reason, the GtkScrolledWindow never tries to fill all available space. It seems to take up some default minimum size. Setting the height-request and width-request properties to some positive integer fixes the size of the GtkScrolledWindow such that I can’t even resize the GtkApplicationWindow that contains it, so that doesn’t work.
I have set GTK_DEBUG=interactive and I have been fiddling with the properties of the widget tree, but nothing seems to work. I also tried using alternatives to GtkBox as the layout container, such as a GtkGrid with two rows and one column instead of a GtkBox, or using a GtkLayout container instead of a GtkScrolledWindow, neither worked. I am completely out of ideas here.
Can someone please explain to me how I can tell the GtkScrolledWindow to “expand” and “fill” all vertical space allocated to it by it’s layout container, that is, how can I tell it to honor the vexpand=true and valign=fill properties that I set for it?
I can’t really help you with GTK 3 (which is what your usage of pack_start suggests), but in GTK 4, setting vexpand on the scrolled window would have been enough for the box to give the scrolled window (& the contained text view) all the vertical space not taken up by the label.
After investigating further, I have some corrections to make to my original post (sorry everyone, I didn’t fully understand the problem before posting).
First I should note that I am creating a custom widget which has the ScrolledWindow and Label grouped together in a Box as a single assembly. In my original post I thought I was adding this assembly as the direct child of the ApplicationWindow, but it turns out I was actually adding it to a Box that was the child of the ApplicationWindow. So the actual widget tree looks something like this:
ApplicationWindow
Box (container for elements added to application window)
Box (for my custom widget)
ScrolledWindow
TextView
Label (for reporting messages)
For reasons, the top-most Box in that hierarchy must be there, so I can’t just place my custom widget directly into the ApplicationWindow.
I have been diligent about making sure all the Boxes as well as the ScrolledWindow and TextView have their vexpand properties set to TRUE and their valign properties set to FILL. But the original problem still remains as stated: the ScrolledWindow is not sizing itself to all of the available space given to it in the Box.
So is the reason that the ScrolledWindow is not expanding to take up all the space allocated to it because it exists in a Box within a Box? I tried setting the resize-mode property to GTK_RESIZE_PARENT but this does not seem to do anything. Should I maybe be handling the size-allocate signal for the ScrolledWindow widget?
@cpb@bugaevc thanks for both of your replies, they actually were helpful in pointing me in the correct direction to debug the issue, although I haven’t quite solved it yet.
GtkScrolledWindow has 4 functions that modify its sizing behaviour: gtk_scrolled_window_set_min_content_height,gtk_scrolled_window_set_max_content_height, and two related to the width. Sometimes this helps even when other methods fail.
I believe I tried this once, but it did not solve the issue. I can try again soon to be sure. What happened when I tried it was that setting the minimum content height/width to some non-negative number prevents the ApplicationWindow from being resized.
I would like for the TextView to take up all space given to it by the Box, but still allow end users to resize the ApplicationWindow to something smaller or bigger. I want the ApplicationWindow to allocate the amount of space available for the TextView, and I want the TextView to take up all space allocated to it. Right now, I can resize the ApplicationWindow without any problem, just that when I do, the TextView (contained within the ScolledWindow does not fill all of the space given to it.