Skip to content

Commit

Permalink
avoid unneccesary refresh on primitive resize
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed May 13, 2021
1 parent 7af0d98 commit f96350f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions canvas/circle.go
Expand Up @@ -28,11 +28,12 @@ func (l *Circle) Size() fyne.Size {
// Resize sets a new bottom-right position for the circle object
// If it has a stroke width this will cause it to Refresh.
func (l *Circle) Resize(size fyne.Size) {
l.Position2 = fyne.NewPos(l.Position1.X+size.Width, l.Position1.Y+size.Height)
if l.StrokeWidth == 0 {
if size == l.Size() {
return
}

l.Position2 = fyne.NewPos(l.Position1.X+size.Width, l.Position1.Y+size.Height)

Refresh(l)
}

Expand Down
4 changes: 4 additions & 0 deletions canvas/line.go
Expand Up @@ -30,6 +30,10 @@ func (l *Line) Size() fyne.Size {

// Resize sets a new bottom-right position for the line object and it will then be refreshed.
func (l *Line) Resize(size fyne.Size) {
if size == l.Size() {
return
}

l.Position2 = fyne.NewPos(l.Position1.X+size.Width, l.Position1.Y+size.Height)
Refresh(l)
}
Expand Down
4 changes: 4 additions & 0 deletions canvas/rectangle.go
Expand Up @@ -26,6 +26,10 @@ func (r *Rectangle) Refresh() {
// 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
Expand Down

0 comments on commit f96350f

Please sign in to comment.