package ui // A simple structure to detect if the cursor has not moved or started moving again. // hoverDetector.update must be called during each Update invocation to track the // frame and the current cursor position. type _hoverDetector struct { last_x, last_y int ticks int threshold int } var ( hoverDetector = _hoverDetector{threshold: 60} longtapHoverDetector = _longtapHoverDetector{} ) func (h *_hoverDetector) update(x, y int) (ev InputEvent, ch bool) { if x == h.last_x && y == h.last_y { h.ticks = h.ticks + 1 if h.ticks == h.threshold { return InputEvent{HoverStart, x, y, nil}, true } } else { if h.ticks > h.threshold { ev = InputEvent{HoverEnd, h.last_x, h.last_y, nil} ch = true } h.ticks = 0 h.last_x, h.last_y = x, y } return } type _longtapHoverDetector struct { active *longtap } func (h *_longtapHoverDetector) update(longtap *longtap) (ev InputEvent, ch bool) { if longtap != nil && h.active == nil { h.active = longtap return InputEvent{HoverStart, longtap.x, longtap.y, nil}, true } return InputEvent{}, false } func (h *_longtapHoverDetector) reset() (ev InputEvent, ch bool) { if h.active != nil { ev := InputEvent{HoverEnd, h.active.x, h.active.y, nil} h.active = nil return ev, true } return InputEvent{}, false }