ref: a296903c76776fc1fca7fc09c53d5ca9c8059c03 gio/ui/layout/doc.go -rw-r--r-- 1.5 KiB View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-License-Identifier: Unlicense OR MIT

/*
Package layout implements layouts common to GUI programs.

Constraints and dimensions

Constraints and dimensions form the the interface between
layouts and interface child elements. Every layout operation
start with a set of constraints for acceptable widths and heights
of a child. The operation ends by the child computing and returning
its chosen size in the form of a Dimens.

For example, to add space above a widget:

	var cs layout.Constraints = ...

	// Configure a top inset.
	inset := layout.Inset{Top: ui.Dp(8), ...}
	// Start insetting and modify the constraints.
	cs = inset.Begin(..., cs)
	// Lay out widget and determine its size given the constraints.
	dimensions := widget.Layout(..., cs)
	// End the inset and account for the insets.
	dimensions = inset.End(dimensions)

Note that the example does not generate any garbage even though the
Inset is transient. Layouts that don't accept user input are designed
to escape to the heap during their use.

Layout operations are recursive: a child in a layout operation can
itself be another layout. That way, complex user interfaces can
be created from a few generic layouts.

This example both aligns and insets a child:

	inset := layout.Inset{...}
	cs = inset.Begin(..., cs)
	align := layout.Align{...}
	cs = align.Begin(..., cs)
	dims := widget.Layout(..., cs)
	dims = align.End(dims)
	dims = inset.End(dims)

More complex layouts such as Stack and Flex lay out multiple children,
and stateful layouts such as List accept user input.

*/
package layout