github.com/Seikaijyu/gio@v0.0.1/layout/doc.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 /* 4 Package layout implements layouts common to GUI programs. 5 6 # Constraints and dimensions 7 8 Constraints and dimensions form the interface between layouts and 9 interface child elements. This package operates on Widgets, functions 10 that compute Dimensions from a a set of constraints for acceptable 11 widths and heights. Both the constraints and dimensions are maintained 12 in an implicit Context to keep the Widget declaration short. 13 14 For example, to add space above a widget: 15 16 var gtx layout.Context 17 18 // Configure a top inset. 19 inset := layout.Inset{Top: 8, ...} 20 // Use the inset to lay out a widget. 21 inset.Layout(gtx, func() { 22 // Lay out widget and determine its size given the constraints 23 // in gtx.Constraints. 24 ... 25 return layout.Dimensions{...} 26 }) 27 28 Note that the example does not generate any garbage even though the 29 Inset is transient. Layouts that don't accept user input are designed 30 to not escape to the heap during their use. 31 32 Layout operations are recursive: a child in a layout operation can 33 itself be another layout. That way, complex user interfaces can 34 be created from a few generic layouts. 35 36 This example both aligns and insets a child: 37 38 inset := layout.Inset{...} 39 inset.Layout(gtx, func(gtx layout.Context) layout.Dimensions { 40 align := layout.Alignment(...) 41 return align.Layout(gtx, func(gtx layout.Context) layout.Dimensions { 42 return widget.Layout(gtx, ...) 43 }) 44 }) 45 46 More complex layouts such as Stack and Flex lay out multiple children, 47 and stateful layouts such as List accept user input. 48 */ 49 package layout