Gtk container layout and widget size: minimum, natural, default sizes explained

I was reading through the GtkWidget documentation in the section on height-for-width geometry management, and the documentation makes several mentions of the terms “natural size” or “minimum size,” or “default size.” For example in this passage here:

First, the default minimum and natural width for each widget in the interface will be computed using gtk_widget_get_preferred_width(). Because the preferred widths for each container depend on the preferred widths of their children, this information propagates up the hierarchy, and finally a minimum and natural width is determined for the entire toplevel.

However, I can’t find the definition of the terms “minimum width” or “natural width” anywhere. They don’t appear to be in the glossary. I can guess from the definition of these words in the English language that “minimum” is the size that must be allocated even if no space is available, “natural” is the minimum size that would be allocated if there is abundant space available, but I can’t really guess what “default size” means.

Is there an authoritative source where I can lookup these terms? Or, next best thing, please explain it to me in this thread? (And maybe, could someone put them in the glossary?)

If by “glossary” you mean the old GTK 2.x glossary that was barely touched for GTK 3.x, then: yes, the definitions are missing, mainly because height-for-width and width-for-height geometry was introduced with GTK 3.x.

We don’t have a proper documentation of the layout machinery in GTK, outside of references in GtkWidget (and GtkContainer for GTK 3.x); it’s a known issue, but nobody has shown up to do the work of documenting things.

As a general rule: the minimum size is the size required to display the minimum amount of content in a widget. A widget cannot be allocated less than the minimum size it requires. The natural size is the amount of content that a widget prefers to display in normal conditions. A widget may be allocated more than the natural size it requires, or less, depending on the layout management of its parent container. What to do when the widget is allocated a different natural size than the one it requires is entirely left to the widget implementation: some widgets decide to add extra room, other widgets may disclose additional content, other widgets may decide to hide content, or show a different layout entirely.

If we expressed these requirements in the form of constraints, using something like the visual format language syntax:

[widget(>=minimum@required, ==natural@medium)]

Where minimum is the minimum size, and natural is the natural size.

2 Likes