package main import ( "image" "gioui.org/ui" "gioui.org/ui/app" "gioui.org/ui/f32" "gioui.org/ui/layout" "gioui.org/ui/paint" gio "git.wow.st/gmp/giowrap" ) func main() { go func() { w := app.NewWindow() ops := new(ui.Ops) gcs := make([]gio.GridChild, 0) for e := range w.Events() { if e, ok := e.(app.UpdateEvent); ok { ops.Reset() c := &e.Config cs := layout.RigidConstraints(e.Size) nrows := 5 ncols := 10 grid := gio.Grid{Cols: ncols} cs = grid.Init(ops, cs) for i := 0; i < nrows*ncols; i++ { grid.Begin() dims := layoutRect(c, ops, cs) gcs = append(gcs, grid.End(dims)) } grid.Layout(gcs...) w.Update(ops) gcs = gcs[0:0] } } }() app.Main() } func layoutRect(c ui.Config, ops *ui.Ops, cs layout.Constraints) layout.Dimens { ins := layout.UniformInset(ui.Px(10)) cs = ins.Begin(c, ops, cs) paint.PaintOp{Rect: f32.Rectangle{ Max: f32.Point{ X: float32(cs.Width.Max), Y: float32(cs.Width.Max), }, }}.Add(ops) dims := layout.Dimens{ Size: image.Point{ X: cs.Width.Max, Y: cs.Width.Max, }, } return ins.End(dims) }