gioui.org/ui@v0.0.0-20190926171558-ce74bc0cbaea/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  	gtx := &layout.Context{...}
    17  	gtx.Reset(...)
    18  
    19  	// Configure a top inset.
    20  	inset := layout.Inset{Top: ui.Dp(8), ...}
    21  	// Use the inset to lay out a widget.
    22  	inset.Layout(gtx, func() {
    23  		// Lay out widget and determine its size given the constraints.
    24  		...
    25  		dims := layout.Dimensions{...}
    26  		gtx.Dimensions = dims
    27  	})
    28  
    29  Note that the example does not generate any garbage even though the
    30  Inset is transient. Layouts that don't accept user input are designed
    31  to not escape to the heap during their use.
    32  
    33  Layout operations are recursive: a child in a layout operation can
    34  itself be another layout. That way, complex user interfaces can
    35  be created from a few generic layouts.
    36  
    37  This example both aligns and insets a child:
    38  
    39  	inset := layout.Inset{...}
    40  	inset.Layout(gtx, func() {
    41  		align := layout.Align(...)
    42  		align.Layout(gtx, func() {
    43  			widget.Layout(gtx, ...)
    44  		})
    45  	})
    46  
    47  More complex layouts such as Stack and Flex lay out multiple children,
    48  and stateful layouts such as List accept user input.
    49  
    50  */
    51  package layout