Add support for mouse hover events

This commit is contained in:
Sasha Koshka 2023-08-12 12:10:47 -04:00
parent 19dbc73968
commit e126c01055
3 changed files with 24 additions and 3 deletions

View File

@ -293,6 +293,7 @@ func (window *window) handleButtonRelease (
window.updateModifiers(buttonEvent.State)
window.updateMousePosition(buttonEvent.EventX, buttonEvent.EventY)
dragging := window.drags[buttonEvent.Detail]
window.drags[buttonEvent.Detail] = nil
if dragging != nil {
dragging.handleMouseUp(input.Button(buttonEvent.Detail))
@ -314,11 +315,14 @@ func (window *window) handleMotionNotify (
for _, child := range window.drags {
if child == nil { continue }
child.handleMouseMove()
window.hover(child)
handled = true
}
if !handled {
window.boxUnder(image.Pt(x, y)).handleMouseMove()
underneath := window.boxUnder(image.Pt(x, y))
underneath.handleMouseMove()
window.hover(underneath)
}
}

View File

@ -56,8 +56,8 @@ type anyBox interface {
// handleDndEnter ()
// handleDndLeave ()
// handleDndDrop (data.Data)
// handleMouseEnter ()
// handleMouseLeave ()
handleMouseEnter ()
handleMouseLeave ()
handleMouseMove ()
handleMouseDown (input.Button)
handleMouseUp (input.Button)
@ -119,15 +119,31 @@ func (window *window) focus (box anyBox) {
window.focused = box
if previous != nil {
// FIXME why are we invalidating draw here
window.invalidateDraw(previous)
previous.handleFocusLeave()
}
if box != nil && box.canBeFocused() {
// FIXME why are we invalidating draw here
window.invalidateDraw(box)
box.handleFocusEnter()
}
}
func (window *window) hover (box anyBox) {
if window.hovered == box { return }
previous := window.hovered
window.hovered = box
if previous != nil {
previous.handleMouseLeave()
}
if box != nil {
box.handleMouseEnter()
}
}
func (window *window) anyFocused () bool {
return window.focused != nil
}

View File

@ -44,6 +44,7 @@ type window struct {
root anyBox
focused anyBox
hovered anyBox
needDraw boxSet
needLayout boxSet