github.com/utopiagio/gio@v0.0.8/widget/icon_test.go (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 package widget 4 5 import ( 6 "image" 7 "image/color" 8 "testing" 9 10 "github.com/utopiagio/gio/layout" 11 "github.com/utopiagio/gio/op" 12 13 "golang.org/x/exp/shiny/materialdesign/icons" 14 ) 15 16 func TestIcon_Alpha(t *testing.T) { 17 icon, err := NewIcon(icons.ToggleCheckBox) 18 if err != nil { 19 t.Fatal(err) 20 } 21 22 col := color.NRGBA{B: 0xff, A: 0x40} 23 24 gtx := layout.Context{ 25 Ops: new(op.Ops), 26 Constraints: layout.Exact(image.Pt(100, 100)), 27 } 28 29 _ = icon.Layout(gtx, col) 30 } 31 32 // TestWidgetConstraints tests that widgets returns dimensions within their constraints. 33 func TestWidgetConstraints(t *testing.T) { 34 _cs := func(v ...layout.Constraints) []layout.Constraints { return v } 35 for _, tc := range []struct { 36 label string 37 widget layout.Widget 38 constraints []layout.Constraints 39 }{ 40 { 41 label: "Icon", 42 widget: func(gtx layout.Context) layout.Dimensions { 43 ic, _ := NewIcon(icons.ToggleCheckBox) 44 return ic.Layout(gtx, color.NRGBA{A: 0xff}) 45 }, 46 constraints: _cs( 47 layout.Constraints{ 48 Min: image.Pt(20, 0), 49 Max: image.Pt(100, 100), 50 }, 51 layout.Constraints{ 52 Max: image.Pt(100, 100), 53 }, 54 ), 55 }, 56 } { 57 t.Run(tc.label, func(t *testing.T) { 58 for _, cs := range tc.constraints { 59 gtx := layout.Context{ 60 Constraints: cs, 61 Ops: new(op.Ops), 62 } 63 dims := tc.widget(gtx) 64 csr := image.Rectangle{ 65 Min: cs.Min, 66 Max: cs.Max, 67 } 68 if !dims.Size.In(csr) { 69 t.Errorf("dims size %v not within constraints %v", dims.Size, csr) 70 } 71 } 72 }) 73 } 74 }