Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behaviour of canvas.Line.Move() #2208

Closed
pwiecz opened this issue Apr 30, 2021 · 1 comment
Closed

Weird behaviour of canvas.Line.Move() #2208

pwiecz opened this issue Apr 30, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@pwiecz
Copy link
Contributor

pwiecz commented Apr 30, 2021

Describe the bug:

Calling Move(pos) on canvas.Line can make the line rotate.
In the implementation of Move(pos) Size() is used to preserve relative positions of Position1 and Position2, but Size() calls math.Abs on the difference of coordinates, so it does not really represent correct relative positions of Position1 and Position2.

To Reproduce:

Steps to reproduce the behaviour:

  1. Create a widget with a line, where line.Position1.x > line.Position2.x or line.Position1.y > line.Position2.y
  2. Call Move() on the line in response to some event
  3. Call Refresh() on the line to rasterize it again
  4. See that the line flips its orientation

Example code:

package main

import (
	"image/color"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/widget"
)

type testWidget struct {
	widget.BaseWidget
	background     *canvas.Rectangle
	lineX0, lineY0 float32
	line           *canvas.Line
	objects        []fyne.CanvasObject
}

func NewTestWidget() *testWidget {
	w := &testWidget{}
	w.ExtendBaseWidget(w)
	w.background = canvas.NewRectangle(color.White)
	w.line = canvas.NewLine(color.NRGBA{0, 0, 255, 255})
	w.lineX0 = 10
	w.lineY0 = 10
	w.line.Position1 = fyne.Position{10, 50}
	w.line.Position2 = fyne.Position{50, 10}
	w.objects = []fyne.CanvasObject{w.background, w.line}
	return w
}
func (w *testWidget) CreateRenderer() fyne.WidgetRenderer { return w }
func (w *testWidget) Layout(size fyne.Size)               { w.background.Resize(size) }
func (w *testWidget) MinSize() fyne.Size                  { return fyne.Size{640, 480} }
func (w *testWidget) Refresh()                            {}
func (w *testWidget) Objects() []fyne.CanvasObject        { return w.objects }
func (w *testWidget) Destroy()                            {}
func (w *testWidget) Dragged(event *fyne.DragEvent) {
	dx, dy := event.Dragged.DX, event.Dragged.DY
	w.lineX0 += dx
	w.lineY0 += dy
	w.line.Move(fyne.Position{w.lineX0, w.lineY0})
	w.line.Refresh()
}
func (w *testWidget) DragEnd() {}

func main() {
	a := app.New()
	w := a.NewWindow("Test line")
	w.SetContent(NewTestWidget())
	w.ShowAndRun()
}

Device (please complete the following information):

  • OS: Linux
  • Version: 5.4.10-72 Ubuntu
  • Go version: 1.16.2
  • Fyne version: 2.0.2
@pwiecz pwiecz added the bug Something isn't working label Apr 30, 2021
andydotxyz added a commit to andydotxyz/fyne that referenced this issue May 13, 2021
@andydotxyz
Copy link
Member

Thanks for the report, #2240 should fix it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants