mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 02:15:34 +00:00
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:
+7
-7
@@ -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, ...)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user