aboutsummaryrefslogtreecommitdiffstats
path: root/test/rows
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2026-02-10 16:56:06 -0500
committerSam Anthony <sam@samanthony.xyz>2026-02-10 16:56:06 -0500
commit430f97bed9d758de90a72b0c06b2be1989ba2b1d (patch)
tree057a578389bfafe595ba415797908979c3d09add /test/rows
parent3ce04a4d3dc8d174b520d85804e5c8dce8c5d08f (diff)
downloadgui-430f97bed9d758de90a72b0c06b2be1989ba2b1d.zip
add rows layout
Diffstat (limited to 'test/rows')
-rw-r--r--test/rows/main.go61
1 files changed, 61 insertions, 0 deletions
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())
+}