mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 15:45:38 +00:00
2782436ffc
Almost every layout and widget need the ui.Config for its environment, an ui.Ops to store operations. Stateful widgets need an input.Queue for events. Add all these common objects to Context, greatly simplifying the function signatures for Gio programs. Fixes gio#33 Signed-off-by: Elias Naur <mail@eliasnaur.com>
52 lines
1.5 KiB
Go
52 lines
1.5 KiB
Go
// SPDX-License-Identifier: Unlicense OR MIT
|
|
|
|
/*
|
|
Package layout implements layouts common to GUI programs.
|
|
|
|
Constraints and dimensions
|
|
|
|
Constraints and dimensions form the interface between layouts and
|
|
interface child elements. This package operates on Widgets, functions
|
|
that compute Dimensions from a a set of constraints for acceptable
|
|
widths and heights. Both the constraints and dimensions are maintained
|
|
in an implicit Context to keep the Widget declaration short.
|
|
|
|
For example, to add space above a widget:
|
|
|
|
c := &layout.Context{...}
|
|
c.Reset(...)
|
|
|
|
// Configure a top inset.
|
|
inset := layout.Inset{Top: ui.Dp(8), ...}
|
|
// Use the inset to lay out a widget.
|
|
inset.Layout(c, func() {
|
|
// Lay out widget and determine its size given the constraints.
|
|
...
|
|
dims := layout.Dimensions{...}
|
|
c.Dimensions = dims
|
|
})
|
|
|
|
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 not 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{...}
|
|
inset.Layout(c, func() {
|
|
align := layout.Align(...)
|
|
align.Layout(c, func() {
|
|
widget.Layout(c, ...)
|
|
})
|
|
})
|
|
|
|
More complex layouts such as Stack and Flex lay out multiple children,
|
|
and stateful layouts such as List accept user input.
|
|
|
|
*/
|
|
package layout
|