Skip to content

Commit

Permalink
Improve gid fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
t-geindre committed Jan 11, 2024
1 parent 47c71b8 commit a1db9c6
Showing 1 changed file with 13 additions and 20 deletions.
33 changes: 13 additions & 20 deletions gui/widget/grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,34 +86,27 @@ func (r *Grid) onChildDrag(c component.IComponent, e event.IEvent) {

func (r *Grid) setComponentPosition(c component.IComponent) {
l := c.GetLayout()
w, _ := l.GetSize()

x, y := r.GetLayout().GetAbsolutePosition()
mx, my := ebiten.CursorPosition()
x, y = x+float64(mx), y+float64(my)

shiftX := float64(int(r.shiftX) % int(r.cellW))
shiftY := float64(int(r.shiftY) % int(r.cellH))

// Compute cell position where the mouse is inside
cx := float64(int(x/r.cellW))*r.cellW + shiftX - w + r.cellW
cy := float64(int(y/r.cellH))*r.cellH + shiftY

if x < cx {
cx -= r.cellW
x, y := l.GetPosition()
if x < 0 {
x -= r.cellW / 2
} else {
x += r.cellW / 2
}

if y < cy {
cy -= r.cellH
if y < 0 {
y -= r.cellH / 2
} else {
y += r.cellH / 2
}

if y > cy+r.cellH {
cy += r.cellH
}
x -= shiftX
y -= shiftY

if x > cx+r.cellW {
cx += r.cellW
}
cx := float64(int(x/r.cellW))*r.cellW + shiftX
cy := float64(int(y/r.cellH))*r.cellH + shiftY

l.SetPosition(cx, cy)
}

0 comments on commit a1db9c6

Please sign in to comment.