From 778487d25a79721539cea1e47331e3c2f985c8cc Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 6 Aug 2025 18:02:44 +0200 Subject: rework hover detection --- go/ui/collection.go | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'go/ui/collection.go') 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 } -- cgit v1.2.3