Layout

Multiple objects in Fyne are grouped in a fyne.Container type and its child objects are laid out by fyne.Layout. Various standard layouts are provided, as detailed in the following table. A layout provides two functions: first, it manages the size and position for a list of fyne.CanvasObject objects; and second, it must define the minimum size required to fit all of the objects it arranges:

BorderLayout The border layout places a specific canvas object at each of the top, bottom, left, and right edges of a container. Any other objects in the container will fill the central space.
BoxLayout The box layout is either vertical or horizontal (created with NewVBoxLayout() or NewHBoxLayout() functions). It will arrange items in a list, each at their minimum height (vertical) or width (horizontal), and the other dimension will expand to the container edge. A box layout may also contain a spacer that will expand to fill available space (normally created with NewSpacer()).
FixedGridLayout The fixed grid layout specifies the size of every cell and then arranges them in rows within the available space. A new row is created when the next widget would have extended beyond the container width.
GridLayout The grid layout has a specified number of columns and each child object will be the appropriate fraction of the container width. The height is defined similarly, depending on the number of child canvas objects. For example, with five objects in two columns, there will be three equal height rows.
MaxLayout This is the simplest layout. Every item is set to the same size to fill the available space. Be careful to specify container objects in the correct order (the first will be drawn under any subsequent items). For example, a button may simply be a rectangle with text positioned above where both should expand equally.

 

It is also possible to write a custom layout by implementing the fyne.Layout interface. The MinSize() function should determine the size required (probably respecting the MinSize() function of the child objects) and the Layout() function calls Move() and Resize() on child objects to configure the display for rendering.

Whilst containers and layouts are useful, most of our time will be spent with higher-level widget definitions, so let's see what is available.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.249.174