Add support for mouse hover events
This commit is contained in:
parent
19dbc73968
commit
e126c01055
6
event.go
6
event.go
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
20
system.go
20
system.go
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user