Layout
A window shows one object. To show more, you put them in a container. A container holds a list of children and a layout, and the layout decides where each child goes and how big it is. Containers are canvas objects themselves, so you nest them to build a screen: a border around a scrolling list, a box of buttons in its top edge, and so on.
The container
package has a constructor for each common arrangement, such as
container.NewVBox and container.NewBorder. Each returns a
*bellui.Container
with a layout from the layout
package. container.New(layout, objects...) combines any layout with any
children.
This app shows the standard containers side by side:
w.SetContent(container.NewGridWithColumns(3,
cell("NewVBox", vbox()),
cell("NewHBox", hbox()),
cell("NewBorder", border()),
cell("NewGridWithColumns", grid()),
cell("NewGridWrap", gridWrap()),
cell("NewCenter", center()),
cell("NewStack", stack()),
cell("NewPadded", padded()),
cell("FormLayout", form()),
))The functions it calls, and the rest of the program, are on the Containers and layouts page.
How sizing works
Every object reports a minimum size (MinSize). A layout reads the
minimum sizes of its children, and its own MinSize is what it needs to fit
them. On desktop, the user cannot make a window smaller than its content’s
minimum size.
When the container is resized, the layout places the children. Some layouts keep children at their minimum size in one direction (a VBox keeps each child’s height); others stretch them to fill (a Stack, a grid cell). Knowing which one does what is most of the work of laying out a screen.