From 430f97bed9d758de90a72b0c06b2be1989ba2b1d Mon Sep 17 00:00:00 2001 From: Sam Anthony Date: Tue, 10 Feb 2026 16:56:06 -0500 Subject: add rows layout --- test/rows/main.go | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 test/rows/main.go (limited to 'test/rows/main.go') 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()) +} -- cgit v1.2.3