shithub: mycel

Download patch

ref: 3260406659434893622caf40d0b6ef8884e7cc16
parent: 9d7238f38d954184eaae835f6f03dd73a6e3a9ba
author: Philip Silva <philip.silva@protonmail.com>
date: Fri Sep 3 06:06:57 EDT 2021

grid_test += maxWidths

--- a/browser/duitx/grid_test.go
+++ b/browser/duitx/grid_test.go
@@ -1,6 +1,7 @@
 package duitx
 
 import (
+	"image"
 	"testing"
 
 	"github.com/mjl-/duit"
@@ -41,5 +42,29 @@
 	g.initPos()
 	if len(g.pos) != 2 || len(g.pos[0]) != 2 || len(g.pos[1]) != 2 || g.pos[0][0] != 0 || g.pos[0][1] != 0 || g.pos[1][0] != 1 || g.pos[1][1] != 1 {
 		t.Fatalf("%+v", g.pos)
+	}
+}
+
+func TestMaxWidths(t *testing.T) {
+	opts := &duit.DUIOpts{
+		Dimensions: "400x300",
+	}
+	dui, err := duit.NewDUI("scroll_test", opts)
+	if err != nil { t.Fatalf("err: %v", err) }
+	g := Grid{
+		Kids: duit.NewKids(
+			&duit.Button{Text: "upper"},
+			&duit.Button{Text: "LL"},
+			&duit.Button{Text: "LR"},
+		),
+		Columns: 2,
+		Rows: 2,
+		RowSpans: []int{1,1,1},
+		ColSpans: []int{2,1,1},
+	}
+	g.initPos()
+	maxW, w, xs := g.maxWidths(dui, image.Point{X: 400, Y: 300})
+	if len(maxW) != 2 || maxW[0]+maxW[1] != w || len(xs) != 2 || xs[0] != 0 || xs[1] != maxW[0] {
+		t.Fatalf("%+v, %v, %+v", maxW, w, xs)
 	}
 }