Context keeps the current Constraints and Dimensions so the layout
function scopes don't have to.
With
ctx := new(layout.Context)
a label with margins and alignment goes from
return al.Layout(ops, cs, func(cs layout.Constraints) layout.Dimensions {
in := layout.Inset{...}
return in.Layout(c, ops, cs, func(cs layout.Constraints) layout.Dimensions {
return text.Label{...}.Layout(ops, cs)
})
})
to
al.Layout(ops, ctx, func() {
in := layout.Inset{...}
in.Layout(c, ops, ctx, func() {
text.Label{...}.Layout(ops, ctx)
})
})
It was a difficult trade-off between the verbose functional approach
and the shorter but more complex Context.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
To keep the interface slim, remove the helper methods and shorten
the essential method, Pixels, to Px.
Add and use unexported Config implementation in the app package.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
The dp and sp units are approximate and mostly used for layout
dimensions that operate in whole pixels. This change alters the
Config methods to return pixels in ints instead of floats, which
results in smoother use for layout and emphasize the inexactness of
the device independent units.
Clients can still access to raw PxPrDp and PxPrSp factors from
Config.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
And use a constant 72 DPI for the default scale, to ensure consistent
image sizes across display densities.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
In preparation for an OpColor (and future OpGradient and similar).
Label and Editor no longer take an explicit source image. They
draw with the current image.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
The layout package switched from interfaces to functions for
composing layouts. The switch made sure that no garbage is
generated for transient layouts such as Align, Inset, Stack, Flex.
Unfortunately, that left the stateful widgets and layouts: as soon
as their layout methods are embedded in a transient layout, a
closure is generated that escapes to the heap.
To avoid garbage for both transient as well as stateful widgets,
replace the functional approach with explicit begin/end methods.
A begin method generally starts an op block and returns the adjusted
constraints. An end method takes computed dimensions, ends its op
block and returns adjusted dimensions.
Signed-off-by: Elias Naur <mail@eliasnaur.com>
Pros:
- Much less per-frame garbage
- Allow future preprocessing of ops while building it
- Much fewer interface calls and pointer chasing
- Allow future serialization of ops for remote rendering
Cons:
- Slightly clumsier API
Signed-off-by: Elias Naur <mail@eliasnaur.com>
gioui.org/ui was renamed from gioui.org/ui/ui before the release,
but the import order wasn't changed accordingly.
Signed-off-by: Elias Naur <mail@eliasnaur.com>