diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/region/main.go (renamed from test/region.go) | 4 | ||||
| -rw-r--r-- | test/rows/main.go | 61 |
2 files changed, 62 insertions, 3 deletions
diff --git a/test/region.go b/test/region/main.go index 682e23f..f335b4f 100644 --- a/test/region.go +++ b/test/region/main.go @@ -11,9 +11,7 @@ import ( "github.com/faiface/mainthread" ) -var ( - bg = gui.HexToColor("#999999") // background color -) +var bg = gui.HexToColor("#999999") // background color func main() { mainthread.Run(run) diff --git a/test/rows/main.go b/test/rows/main.go new file mode 100644 index 0000000..9848ddf --- /dev/null +++ b/test/rows/main.go @@ -0,0 +1,61 @@ +package main + +import ( + "image" + "image/color" + "image/draw" + + "github.com/faiface/gui" + "github.com/faiface/gui/layout" + "github.com/faiface/gui/win" + "github.com/faiface/mainthread" +) + +const ( + nrows = 16 + rowHeight = 12 + rowWidth = 128 +) + +var bg = gui.HexToColor("#ffffea") // background color + +func main() { + mainthread.Run(run) +} + +func run() { + w, err := win.New(win.Title("Grid Layout Test"), win.Resizable()) + if err != nil { + panic(err) + } + + mux, env := gui.NewMux(w) + + rows := layout.NewRows(mux.MakeEnv(), nrows, layout.Background(bg)) + for i, row := range rows { + go colorBlock(row, image.Pt(rowWidth, rowHeight), color.RGBA{uint8(i * 256 / 4), 0x20, 0x20, 0xFF}) + } + + for event := range env.Events() { + switch event.(type) { + case win.WiClose: + close(env.Draw()) + return + } + } +} + +func colorBlock(env gui.Env, size image.Point, c color.Color) { + redraw := func(img draw.Image) image.Rectangle { + r := image.Rectangle{img.Bounds().Min, img.Bounds().Min.Add(size)} + draw.Draw(img, r, &image.Uniform{c}, image.ZP, draw.Src) + return r + } + for event := range env.Events() { + switch event.(type) { + case gui.Resize: + env.Draw() <- redraw + } + } + close(env.Draw()) +} |