github.com/jmigpin/editor@v1.6.0/util/uiutil/widget/boxlayout_test.go (about) 1 package widget 2 3 //import ( 4 // "image" 5 // "testing" 6 //) 7 8 //func TestBoxLayout1(t *testing.T) { 9 // r1 := NewRectangle(nil) 10 // r2 := NewRectangle(nil) 11 // r3 := NewRectangle(nil) 12 // r4 := NewRectangle(nil) 13 14 // s1 := image.Point{5, 5} 15 // r1.Size, r2.Size, r3.Size, r4.Size = s1, s1, s1, s1 16 17 // l1 := NewBoxLayout() 18 // l1.Bounds = image.Rect(0, 0, 100, 100) 19 // l1.Append(r1, r2, r3, r4) 20 // l1.CalcChildsBounds() 21 // if !(r1.Bounds == image.Rect(0, 0, 5, 5) && 22 // r2.Bounds == image.Rect(5, 0, 10, 5) && 23 // r3.Bounds == image.Rect(10, 0, 15, 5) && 24 // r4.Bounds == image.Rect(15, 0, 20, 5)) { 25 // t.Log(r1.Bounds, r2.Bounds, r3.Bounds, r4.Bounds) 26 // t.Fatal() 27 // } 28 29 // l1.SetChildFlex(r2, true, false) 30 // l1.CalcChildsBounds() 31 // if !(r1.Bounds == image.Rect(0, 0, 5, 5) && 32 // r2.Bounds == image.Rect(5, 0, 90, 5) && 33 // r3.Bounds == image.Rect(90, 0, 95, 5) && 34 // r4.Bounds == image.Rect(95, 0, 100, 5)) { 35 // t.Log(r1.Bounds, r2.Bounds, r3.Bounds, r4.Bounds) 36 // t.Fatal() 37 // } 38 39 // l1.SetChildFlex(r1, true, false) 40 // l1.SetChildFlex(r2, true, false) 41 // l1.SetChildFlex(r3, true, false) 42 // l1.SetChildFlex(r4, true, false) 43 // l1.CalcChildsBounds() 44 // if !(r1.Bounds == image.Rect(0, 0, 25, 5) && 45 // r2.Bounds == image.Rect(25, 0, 50, 5) && 46 // r3.Bounds == image.Rect(50, 0, 75, 5) && 47 // r4.Bounds == image.Rect(75, 0, 100, 5)) { 48 // t.Log(r1.Bounds, r2.Bounds, r3.Bounds, r4.Bounds) 49 // t.Fatal() 50 // } 51 //} 52 53 //func TestBoxLayout2(t *testing.T) { 54 // r1 := NewRectangle(nil) 55 // r2 := NewRectangle(nil) 56 // r3 := NewRectangle(nil) 57 // r4 := NewRectangle(nil) 58 59 // s1 := image.Point{10, 10} 60 // r1.Size, r2.Size, r3.Size, r4.Size = s1, s1, s1, s1 61 // r2.Size = image.Point{5, 5} 62 63 // l1 := NewBoxLayout() 64 // l1.Bounds = image.Rect(0, 0, 100, 100) 65 // l1.Append(r1, r2, r3, r4) 66 // l1.CalcChildsBounds() 67 // t.Log(r1.Bounds, r2.Bounds, r3.Bounds, r4.Bounds) 68 69 // l1.SetChildFill(r2, false, true) 70 // // r2 fill y is set to true, but only measuring, should not affect anything 71 // m := l1.Measure(image.Point{50, 50}) 72 // p := image.Point{35, 10} 73 // if m != p { 74 // t.Log(m) 75 // t.Fatal() 76 // } 77 78 // // r2 fill y is set to true, should affect r2.max.y 79 // t.Log(r1.Bounds, r2.Bounds, r3.Bounds, r4.Bounds) 80 // l1.CalcChildsBounds() 81 // if !(r1.Bounds == image.Rect(0, 0, 10, 10) && 82 // r2.Bounds == image.Rect(10, 0, 15, 100) && 83 // r3.Bounds == image.Rect(15, 0, 25, 10) && 84 // r4.Bounds == image.Rect(25, 0, 35, 10)) { 85 // t.Log(r1.Bounds, r2.Bounds, r3.Bounds, r4.Bounds) 86 // t.Fatal() 87 // } 88 89 // // should divide space among "fillables" 90 // t.Log(r1.Bounds, r2.Bounds, r3.Bounds, r4.Bounds) 91 // l1.SetChildFill(r2, true, false) 92 // l1.SetChildFill(r4, true, false) 93 // l1.CalcChildsBounds() 94 // if !(r1.Bounds == image.Rect(0, 0, 10, 10) && 95 // r2.Bounds == image.Rect(10, 0, 50, 5) && 96 // r3.Bounds == image.Rect(50, 0, 60, 10) && 97 // r4.Bounds == image.Rect(60, 0, 100, 10)) { 98 // t.Log(r1.Bounds, r2.Bounds, r3.Bounds, r4.Bounds) 99 // t.Fatal() 100 // } 101 102 // // should ignore the fillables 103 // l1.SetChildFill(r2, true, true) 104 // l1.SetChildFill(r4, true, true) 105 // m = l1.Measure(image.Point{50, 50}) 106 // p = image.Point{35, 10} 107 // if m != p { 108 // t.Log(m) 109 // t.Fatal() 110 // } 111 112 // // have no flex in y, should get maximum value in y 113 // l1.SetChildFlex(r1, false, true) 114 // m = l1.Measure(image.Point{50, 50}) 115 // p = image.Point{35, 50} 116 // if m != p { 117 // t.Log(m) 118 // t.Fatal() 119 // } 120 121 // // flex should have priority over the fill, but in y they should all get the value 122 // // r1,r2,r4 should have maximum y 123 // t.Log(r1.Bounds, r2.Bounds, r3.Bounds, r4.Bounds) 124 // l1.CalcChildsBounds() 125 // if !(r1.Bounds == image.Rect(0, 0, 10, 100) && 126 // r2.Bounds == image.Rect(10, 0, 50, 100) && 127 // r3.Bounds == image.Rect(50, 0, 60, 10) && 128 // r4.Bounds == image.Rect(60, 0, 100, 100)) { 129 // t.Log(r1.Bounds, r2.Bounds, r3.Bounds, r4.Bounds) 130 // t.Fatal() 131 // } 132 133 // // flex in x 134 // l1.SetChildFlex(r1, true, false) 135 // l1.SetChildFill(r2, true, true) 136 // l1.SetChildFill(r4, true, true) 137 // m = l1.Measure(image.Point{50, 50}) 138 // p = image.Point{50, 10} 139 // if m != p { 140 // t.Log(m) 141 // t.Fatal() 142 // } 143 144 // // flex in x, flex has priority over fill 145 // t.Log(r1.Bounds, r2.Bounds, r3.Bounds, r4.Bounds) 146 // l1.CalcChildsBounds() 147 // if !(r1.Bounds == image.Rect(0, 0, 75, 10) && 148 // r2.Bounds == image.Rect(75, 0, 80, 100) && 149 // r3.Bounds == image.Rect(80, 0, 90, 10) && 150 // r4.Bounds == image.Rect(90, 0, 100, 100)) { 151 // t.Log(r1.Bounds, r2.Bounds, r3.Bounds, r4.Bounds) 152 // t.Fatal() 153 // } 154 //}