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
+5 -5
View File
@@ -25,7 +25,7 @@ type Image struct {
Scale float32
}
func (im Image) Layout(c ui.Config, ops *ui.Ops, ctx *layout.Context) {
func (im Image) Layout(c *layout.Context) {
size := im.Src.Bounds()
wf, hf := float32(size.Dx()), float32(size.Dy())
var w, h int
@@ -35,7 +35,7 @@ func (im Image) Layout(c ui.Config, ops *ui.Ops, ctx *layout.Context) {
} else {
w, h = int(wf*im.Scale+.5), int(hf*im.Scale+.5)
}
cs := ctx.Constraints
cs := c.Constraints
d := image.Point{X: cs.Width.Constrain(w), Y: cs.Height.Constrain(h)}
aspect := float32(w) / float32(h)
dw, dh := float32(d.X), float32(d.Y)
@@ -48,7 +48,7 @@ func (im Image) Layout(c ui.Config, ops *ui.Ops, ctx *layout.Context) {
dr := f32.Rectangle{
Max: f32.Point{X: float32(d.X), Y: float32(d.Y)},
}
paint.ImageOp{Src: im.Src, Rect: im.Rect}.Add(ops)
paint.PaintOp{Rect: dr}.Add(ops)
ctx.Dimensions = layout.Dimensions{Size: d, Baseline: d.Y}
paint.ImageOp{Src: im.Src, Rect: im.Rect}.Add(c.Ops)
paint.PaintOp{Rect: dr}.Add(c.Ops)
c.Dimensions = layout.Dimensions{Size: d, Baseline: d.Y}
}