Skip to content

Commit

Permalink
Fix issue with line resize
Browse files Browse the repository at this point in the history
Fixes #2208
  • Loading branch information
andydotxyz committed May 19, 2021
1 parent a428d4c commit 8a09b93
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 6 additions & 3 deletions canvas/line.go
Expand Up @@ -45,9 +45,12 @@ func (l *Line) Position() fyne.Position {

// Move the line object to a new position, relative to its parent / canvas
func (l *Line) Move(pos fyne.Position) {
size := l.Size()
l.Position1 = pos
l.Position2 = fyne.NewPos(l.Position1.X+size.Width, l.Position1.Y+size.Height)
oldPos := l.Position()
deltaX := pos.X - oldPos.X
deltaY := pos.Y - oldPos.Y

l.Position1 = l.Position1.Add(fyne.NewPos(deltaX, deltaY))
l.Position2 = l.Position2.Add(fyne.NewPos(deltaX, deltaY))
}

// MinSize for a Line simply returns Size{1, 1} as there is no
Expand Down
19 changes: 19 additions & 0 deletions canvas/line_test.go
Expand Up @@ -18,6 +18,25 @@ func TestLine_MinSize(t *testing.T) {
assert.True(t, min.Height > 0)
}

func TestLine_Move(t *testing.T) {
line := canvas.NewLine(color.Black)

line.Resize(fyne.NewSize(10, 10))
assert.Equal(t, fyne.NewPos(0, 0), line.Position1)
assert.Equal(t, fyne.NewPos(10, 10), line.Position2)

line.Move(fyne.NewPos(5, 5))
assert.Equal(t, fyne.NewPos(5, 5), line.Position1)
assert.Equal(t, fyne.NewPos(15, 15), line.Position2)

// rotate
line.Position1 = fyne.NewPos(0, 10)
line.Position2 = fyne.NewPos(10, 0)
line.Move(fyne.NewPos(10, 10))
assert.Equal(t, fyne.NewPos(10, 20), line.Position1)
assert.Equal(t, fyne.NewPos(20, 10), line.Position2)
}

func TestLine_Resize(t *testing.T) {
line := canvas.NewLine(color.Black)

Expand Down

0 comments on commit 8a09b93

Please sign in to comment.