mirror of
https://github.com/TangentFoxy/Pop.Box.git
synced 2024-12-15 12:44:20 +00:00
fix bug w implementation of hovered callback
This commit is contained in:
parent
3ab37d3e6a
commit
ab232862cb
18
init.lua
18
init.lua
@ -229,11 +229,19 @@ pop.mousemoved = function(x, y, dx, dy, element)
|
||||
pop.mousemoved(x, y, dx, dy, element.child[i])
|
||||
end
|
||||
end
|
||||
if element == pop.screen and pop.hovered ~= previously_hovered then
|
||||
log(" pop.hovered: " .. tostring(pop.hovered) .. " (" .. tostring(pop.hovered.data.type) .. ")")
|
||||
end
|
||||
if pop.focused and pop.focused.mousemoved and element == pop.screen then
|
||||
return pop.focused:mousemoved(x - pop.focused.data.x, y - pop.focused.data.y, dx, dy)
|
||||
if element == pop.screen then
|
||||
if pop.hovered ~= previously_hovered then
|
||||
log(" pop.hovered: " .. tostring(pop.hovered) .. " (" .. tostring(pop.hovered.data.type) .. ")")
|
||||
if previously_hovered and previously_hovered.hovered then
|
||||
previously_hovered:hovered(false)
|
||||
end
|
||||
if pop.hovered.hovered then
|
||||
pop.hovered:hovered(true)
|
||||
end
|
||||
end
|
||||
if pop.focused and pop.focused.mousemoved then
|
||||
return pop.focused:mousemoved(x - pop.focused.data.x, y - pop.focused.data.y, dx, dy)
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
23
init.moon
23
init.moon
@ -269,7 +269,7 @@ pop.draw = (element=pop.screen) ->
|
||||
pop.mousemoved = (x, y, dx, dy, element=pop.screen) ->
|
||||
local previously_hovered
|
||||
if element == pop.screen
|
||||
previously_hovered = pop.hovered
|
||||
previously_hovered = pop.hovered -- we save it because the loop below will change it
|
||||
|
||||
-- first we find out if we're hovering over anything and set pop.hovered
|
||||
if element.data.draw and element.data.hoverable and (x >= element.data.x) and (x <= element.data.x + element.data.w) and (y >= element.data.y) and (y <= element.data.y + element.data.h)
|
||||
@ -279,17 +279,18 @@ pop.mousemoved = (x, y, dx, dy, element=pop.screen) ->
|
||||
for i = 1, #element.child
|
||||
pop.mousemoved x, y, dx, dy, element.child[i]
|
||||
|
||||
-- if we're hovering over something different, log it, and call handlers if relevant
|
||||
if element == pop.screen and pop.hovered != previously_hovered
|
||||
log " pop.hovered: #{pop.hovered} (#{pop.hovered.data.type})"
|
||||
if previously_hovered.hovered
|
||||
previously_hovered\hovered false
|
||||
if pop.hovered.hovered
|
||||
pop.hovered\hovered true
|
||||
-- check element == pop.screen so this is only called once at the end
|
||||
if element == pop.screen
|
||||
-- if we're hovering over something different, log it, and call handlers if relevant
|
||||
if pop.hovered != previously_hovered
|
||||
log " pop.hovered: #{pop.hovered} (#{pop.hovered.data.type})"
|
||||
if previously_hovered and previously_hovered.hovered -- previously_hovered can be a false boolean
|
||||
previously_hovered\hovered false
|
||||
if pop.hovered.hovered
|
||||
pop.hovered\hovered true
|
||||
|
||||
-- checks element == pop.screen so this only gets called once at the end of recursion
|
||||
if pop.focused and pop.focused.mousemoved and element == pop.screen
|
||||
return pop.focused\mousemoved x - pop.focused.data.x, y - pop.focused.data.y, dx, dy
|
||||
if pop.focused and pop.focused.mousemoved
|
||||
return pop.focused\mousemoved x - pop.focused.data.x, y - pop.focused.data.y, dx, dy
|
||||
|
||||
return false
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user