Skip to content

Commit

Permalink
Replaced some of the UI states with !Pressed rather than JustReleased
Browse files Browse the repository at this point in the history
  • Loading branch information
unitoftime committed Feb 5, 2024
1 parent ca7fd1c commit dbb9a90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions math.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ func (r Rect) WithCenter(v Vec2) Rect {
return R(v[0] - w, v[1] - h, v[0] + w, v[1] + h)
}

// TODO: Should I make a pointer version of this that handles the nil case too?
// Returns the smallest rect which contains both input rects
func (r Rect) Union(s Rect) Rect {
r = r.Norm()
Expand Down
14 changes: 9 additions & 5 deletions ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ type Group struct {
mousePos, mouseDownPos glitch.Vec2

// New Way
hotId, activeId eid
downId eid
hotId eid // The element id that you are hovering over or about to interact with
downId eid // The element id that you have selected or are holding down on
activeId eid // The element id that is active?
tmpHotId eid

idCounter eid
Expand Down Expand Up @@ -527,7 +528,8 @@ func (g *Group) button(label string, rect glitch.Rect, style Style) (pressed, he

if g.activeId == id {
held = true
if g.win.JustReleased(glitch.MouseButtonLeft) {
// if g.win.JustReleased(glitch.MouseButtonLeft) {
if !g.win.Pressed(glitch.MouseButtonLeft) {
g.activeId = invalidId
if g.hotId == id {
released = true
Expand Down Expand Up @@ -717,7 +719,8 @@ func (g *Group) DragAndDropItem(label string, style Style, rect glitch.Rect) (bo

dropSlot := false
if g.activeId == id {
if g.win.JustReleased(glitch.MouseButtonLeft) {
// if g.win.JustReleased(glitch.MouseButtonLeft) {
if !g.win.Pressed(glitch.MouseButtonLeft) {
g.activeId = invalidId
}
} else if g.downId == id {
Expand All @@ -726,7 +729,8 @@ func (g *Group) DragAndDropItem(label string, style Style, rect glitch.Rect) (bo
// fmt.Println("Drag:", elem)
g.activeId = id
g.downId = invalidId
} else if g.win.JustReleased(glitch.MouseButtonLeft) {
// } else if g.win.JustReleased(glitch.MouseButtonLeft) {
} else if !g.win.Pressed(glitch.MouseButtonLeft) {
// fmt.Println("Click:", elem)
buttonClick = true
g.downId = invalidId
Expand Down

0 comments on commit dbb9a90

Please sign in to comment.