|
| 1 | +package canvas_test |
| 2 | + |
| 3 | +import ( |
| 4 | + "image/color" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "fyne.io/fyne/v2" |
| 8 | + "fyne.io/fyne/v2/canvas" |
| 9 | + "fyne.io/fyne/v2/test" |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | +) |
| 12 | + |
| 13 | +func TestArbitraryPolygon_NewAndDefaults(t *testing.T) { |
| 14 | + points := []fyne.Position{ |
| 15 | + {X: 0, Y: 0}, |
| 16 | + {X: 100, Y: 0}, |
| 17 | + {X: 100, Y: 100}, |
| 18 | + } |
| 19 | + fill := color.White |
| 20 | + p := canvas.NewArbitraryPolygon(points, fill) |
| 21 | + |
| 22 | + assert.Equal(t, points, p.Points) |
| 23 | + assert.Equal(t, fill, p.FillColor) |
| 24 | + assert.Nil(t, p.StrokeColor) |
| 25 | + assert.Equal(t, float32(0), p.StrokeWidth) |
| 26 | +} |
| 27 | + |
| 28 | +func TestArbitraryPolygon_Properties(t *testing.T) { |
| 29 | + p := canvas.NewArbitraryPolygon(nil, color.Black) |
| 30 | + p.StrokeWidth = 2.0 |
| 31 | + p.StrokeColor = color.NRGBA{R: 255, G: 0, B: 0, A: 255} |
| 32 | + p.CornerRadii = []float32{5, 10, 5} |
| 33 | + |
| 34 | + assert.Equal(t, float32(2.0), p.StrokeWidth) |
| 35 | + assert.Equal(t, color.NRGBA{R: 255, G: 0, B: 0, A: 255}, p.StrokeColor) |
| 36 | + assert.Equal(t, []float32{5, 10, 5}, p.CornerRadii) |
| 37 | +} |
| 38 | + |
| 39 | +func TestArbitraryPolygon_RendersToMarkup(t *testing.T) { |
| 40 | + points := []fyne.Position{ |
| 41 | + {X: 0, Y: 0}, |
| 42 | + {X: 10, Y: 0}, |
| 43 | + {X: 10, Y: 10}, |
| 44 | + } |
| 45 | + p := canvas.NewArbitraryPolygon(points, color.White) |
| 46 | + p.Resize(fyne.NewSize(10, 10)) |
| 47 | + |
| 48 | + test.AssertObjectRendersToMarkup(t, "arbitrary_polygon.xml", p) |
| 49 | +} |
0 commit comments