-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
rectangle.go
46 lines (36 loc) · 968 Bytes
/
rectangle.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package canvas
import (
"image/color"
"fyne.io/fyne/v2"
)
// Declare conformity with CanvasObject interface
var _ fyne.CanvasObject = (*Rectangle)(nil)
// Rectangle describes a colored rectangle primitive in a Fyne canvas
type Rectangle struct {
baseObject
FillColor color.Color // The rectangle fill color
StrokeColor color.Color // The rectangle stroke color
StrokeWidth float32 // The stroke width of the rectangle
}
// Refresh causes this object to be redrawn in it's current state
func (r *Rectangle) Refresh() {
Refresh(r)
}
// Resize on a rectangle updates the new size of this object.
// If it has a stroke width this will cause it to Refresh.
func (r *Rectangle) Resize(s fyne.Size) {
if s == r.Size() {
return
}
r.baseObject.Resize(s)
if r.StrokeWidth == 0 {
return
}
Refresh(r)
}
// NewRectangle returns a new Rectangle instance
func NewRectangle(color color.Color) *Rectangle {
return &Rectangle{
FillColor: color,
}
}