ui/layout: add common state to Context

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>
This commit is contained in:
Elias Naur
2019-09-24 21:10:35 +02:00
parent b928ee65f7
commit 2782436ffc
9 changed files with 157 additions and 156 deletions
+7 -7
View File
@@ -13,17 +13,17 @@ in an implicit Context to keep the Widget declaration short.
For example, to add space above a widget:
ctx := new(layout.Context)
ctx.Constraints = ...
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(..., ctx, func() {
inset.Layout(c, func() {
// Lay out widget and determine its size given the constraints.
...
dims := layout.Dimensions{...}
ctx.Dimensions = dims
c.Dimensions = dims
})
Note that the example does not generate any garbage even though the
@@ -37,10 +37,10 @@ be created from a few generic layouts.
This example both aligns and insets a child:
inset := layout.Inset{...}
inset.Layout(..., ctx, func() {
inset.Layout(c, func() {
align := layout.Align(...)
align.Layout(..., ctx, func() {
widget.Layout(..., ctx)
align.Layout(c, func() {
widget.Layout(c, ...)
})
})