diff options
Diffstat (limited to 'go/ui/hoverable.go')
| -rw-r--r-- | go/ui/hoverable.go | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/go/ui/hoverable.go b/go/ui/hoverable.go index 30415c8d..3f7e8def 100644 --- a/go/ui/hoverable.go +++ b/go/ui/hoverable.go @@ -5,63 +5,58 @@ import ( ) const ( - HOVER_THRESHOLD = 60 - HOVER_CARD_WIDTH = 500 HOVER_CARD_HEIGHT = 700 ) -type Hoverable interface { - onHover(ticks int, x, y int, c *Collection) bool - stopHover(ticks int, x, y int) bool -} - type hoverWidget struct { + c *Collection createHint func(x, y int) Widget reset func() xMax, yMax int } -func (h *hoverWidget) showHint(x, y int, c *Collection) { +func (h *hoverWidget) Hover(started bool, x, y int) { + if started { + h.onHover(x, y) + } else { + h.stopHover(x, y) + } +} + +func (h *hoverWidget) showHint(x, y int) { hint := h.createHint(x, y) if hint == nil { return } - c.AddWidget(hint) + h.c.AddWidget(hint) h.reset = func() { - c.RemoveWidget(hint) + h.c.RemoveWidget(hint) } } -func (h *hoverWidget) onHover(ticks int, x, y int, c *Collection) bool { +func (h *hoverWidget) onHover(x, y int) { if h.xMax == 0 || h.yMax == 0 { - width, height := c.Layout() + width, height := h.c.Layout() h.xMax = width h.yMax = height } - - if ticks == HOVER_THRESHOLD { - h.showHint(x, y, c) - return true - } - - return false + h.showHint(x, y) } -func (h *hoverWidget) stopHover(ticks int, x, y int) bool { - if h.reset != nil { - h.reset() - } - return true +func (h *hoverWidget) stopHover(x, y int) { + if h.reset != nil { h.reset() } } type hoverCardView struct { hoverWidget } -func (h *hoverCardView) init(w Widget) { +func (h *hoverCardView) init(w Widget, c *Collection) { + h.c = c h.createHint = func(x, y int) Widget { + obj := w.FindObjectAt(x, y) if obj == nil { return nil @@ -89,7 +84,8 @@ type hoverPermInfo struct { hoverWidget } -func (h *hoverPermInfo) init(w Widget) { +func (h *hoverPermInfo) init(w Widget, c *Collection) { + h.c = c h.createHint = func(x, y int) Widget { obj := w.FindObjectAt(x, y) if obj == nil { |
