diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-08-06 18:02:44 +0200 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-08-20 15:57:35 +0200 |
| commit | 778487d25a79721539cea1e47331e3c2f985c8cc (patch) | |
| tree | 1762762f69895465e7d1a0c9844ed9dbb28b2a71 /go/ui/collection.go | |
| parent | 121016509135952eb1144abdaa8aeabe5bebe682 (diff) | |
| download | muhqs-game-778487d25a79721539cea1e47331e3c2f985c8cc.tar.gz muhqs-game-778487d25a79721539cea1e47331e3c2f985c8cc.zip | |
rework hover detection
Diffstat (limited to 'go/ui/collection.go')
| -rw-r--r-- | go/ui/collection.go | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/go/ui/collection.go b/go/ui/collection.go index 78944814..c5f59540 100644 --- a/go/ui/collection.go +++ b/go/ui/collection.go @@ -12,9 +12,9 @@ import ( // another Collection. type Collection struct { Width, Height int - hoverDetector hoverDetector widgets []Widget focused Widget + hovering Widget } type CollectionInterface interface { @@ -39,10 +39,6 @@ func (c *Collection) Clear() { c.widgets = []Widget{} } -func (c *Collection) ResetHover() { - c.hoverDetector.reset(0, 0) -} - func (c *Collection) AddWidget(w Widget) { if w == nil { log.Panicf("Adding nil widget to collection") @@ -191,6 +187,16 @@ func (c *Collection) Update() error { passInput(ev, txt) ConsumeInput(i) } + case HoverEnd: + if c.hovering != nil { + w.Hover(false, ev.X, ev.Y) + c.hovering = nil + } + case HoverStart: + if w.IsHoverable() { + w.Hover(true, ev.X, ev.Y) + c.hovering = w + } } // handle focused text input } else if ev.Kind == Text { @@ -201,10 +207,6 @@ func (c *Collection) Update() error { } } - x, y := ebiten.CursorPosition() - activeWidget := c.FindWidgetAt(x, y) - c.hoverDetector.update(c, x, y, activeWidget) - return nil } |
