Skip to content

Commit

Permalink
Small refactor, we should use fyne.Position for canvas positions
Browse files Browse the repository at this point in the history
  • Loading branch information
andydotxyz committed Sep 27, 2019
1 parent 2f02567 commit 17b62a1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions internal/driver/glfw/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func (w *window) refresh(viewport *glfw.Window) {
}

func (w *window) findObjectAtPositionMatching(canvas *glCanvas, mouse fyne.Position,
matches func(object fyne.CanvasObject) bool) (fyne.CanvasObject, int, int) {
matches func(object fyne.CanvasObject) bool) (fyne.CanvasObject, fyne.Position) {
roots := []fyne.CanvasObject{canvas.content}

if canvas.menu != nil {
Expand All @@ -483,7 +483,7 @@ func (w *window) mouseMoved(viewport *glfw.Window, xpos float64, ypos float64) {
w.mousePos = fyne.NewPos(internal.UnscaleInt(w.canvas, int(xpos)), internal.UnscaleInt(w.canvas, int(ypos)))

cursor := defaultCursor
obj, x, y := w.findObjectAtPositionMatching(w.canvas, w.mousePos, func(object fyne.CanvasObject) bool {
obj, pos := w.findObjectAtPositionMatching(w.canvas, w.mousePos, func(object fyne.CanvasObject) bool {
if wid, ok := object.(*widget.Entry); ok {
if !wid.ReadOnly {
cursor = entryCursor
Expand All @@ -499,7 +499,7 @@ func (w *window) mouseMoved(viewport *glfw.Window, xpos float64, ypos float64) {
viewport.SetCursor(cursor)
if obj != nil && !w.objIsDragged(obj) {
ev := new(desktop.MouseEvent)
ev.Position = fyne.NewPos(x, y)
ev.Position = pos
ev.Button = w.mouseButton

if hovered, ok := obj.(desktop.Hoverable); ok {
Expand Down Expand Up @@ -556,7 +556,7 @@ func (w *window) mouseOut() {
}

func (w *window) mouseClicked(viewport *glfw.Window, button glfw.MouseButton, action glfw.Action, mods glfw.ModifierKey) {
co, x, y := w.findObjectAtPositionMatching(w.canvas, w.mousePos, func(object fyne.CanvasObject) bool {
co, pos := w.findObjectAtPositionMatching(w.canvas, w.mousePos, func(object fyne.CanvasObject) bool {
if _, ok := object.(fyne.Tappable); ok {
return true
} else if _, ok := object.(fyne.Focusable); ok {
Expand All @@ -572,7 +572,7 @@ func (w *window) mouseClicked(viewport *glfw.Window, button glfw.MouseButton, ac
return false
})
ev := new(fyne.PointEvent)
ev.Position = fyne.NewPos(x, y)
ev.Position = pos

coMouse := co
// Switch the mouse target to the dragging object if one is set
Expand Down Expand Up @@ -663,7 +663,7 @@ func (w *window) mouseClicked(viewport *glfw.Window, button glfw.MouseButton, ac
}

func (w *window) mouseScrolled(viewport *glfw.Window, xoff float64, yoff float64) {
co, _, _ := w.findObjectAtPositionMatching(w.canvas, w.mousePos, func(object fyne.CanvasObject) bool {
co, _ := w.findObjectAtPositionMatching(w.canvas, w.mousePos, func(object fyne.CanvasObject) bool {
_, ok := object.(fyne.Scrollable)
return ok
})
Expand Down
4 changes: 2 additions & 2 deletions internal/driver/gomobile/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (c *canvas) tapUp(pos fyne.Position,
tapAltCallback func(fyne.Tappable, *fyne.PointEvent)) {
duration := time.Now().UnixNano() - c.lastTapDown

co, objX, objY := driver.FindObjectAtPositionMatching(pos, func(object fyne.CanvasObject) bool {
co, objPos := driver.FindObjectAtPositionMatching(pos, func(object fyne.CanvasObject) bool {
if _, ok := object.(fyne.Tappable); ok {
return true
} else if _, ok := object.(fyne.Focusable); ok {
Expand All @@ -188,7 +188,7 @@ func (c *canvas) tapUp(pos fyne.Position,
}, c.overlay, c.content)

ev := new(fyne.PointEvent)
ev.Position = fyne.NewPos(objX, objY)
ev.Position = objPos

if wid, ok := co.(fyne.Tappable); ok {
// TODO move event queue to common code w.queueEvent(func() { wid.Tapped(ev) })
Expand Down
8 changes: 4 additions & 4 deletions internal/driver/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ func walkObjectTree(
// The matches function determines of the type of object that is found at this position is of a suitable type.
// The various canvas roots and overlays that can be searched are also passed in.
func FindObjectAtPositionMatching(mouse fyne.Position, matches func(object fyne.CanvasObject) bool,
overlay fyne.CanvasObject, roots ...fyne.CanvasObject) (fyne.CanvasObject, int, int) {
overlay fyne.CanvasObject, roots ...fyne.CanvasObject) (fyne.CanvasObject, fyne.Position) {
var found fyne.CanvasObject
foundX, foundY := 0, 0
var foundPos fyne.Position

findFunc := func(walked fyne.CanvasObject, pos fyne.Position, clipPos fyne.Position, clipSize fyne.Size) bool {
if !walked.Visible() {
Expand All @@ -121,7 +121,7 @@ func FindObjectAtPositionMatching(mouse fyne.Position, matches func(object fyne.

if matches(walked) {
found = walked
foundX, foundY = mouse.X-pos.X, mouse.Y-pos.Y
foundPos = fyne.NewPos(mouse.X-pos.X, mouse.Y-pos.Y)
}
return false
}
Expand All @@ -137,5 +137,5 @@ func FindObjectAtPositionMatching(mouse fyne.Position, matches func(object fyne.
}
}

return found, foundX, foundY
return found, foundPos
}

0 comments on commit 17b62a1

Please sign in to comment.