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])
|
pop.mousemoved(x, y, dx, dy, element.child[i])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if element == pop.screen and pop.hovered ~= previously_hovered then
|
if element == pop.screen then
|
||||||
log(" pop.hovered: " .. tostring(pop.hovered) .. " (" .. tostring(pop.hovered.data.type) .. ")")
|
if pop.hovered ~= previously_hovered then
|
||||||
end
|
log(" pop.hovered: " .. tostring(pop.hovered) .. " (" .. tostring(pop.hovered.data.type) .. ")")
|
||||||
if pop.focused and pop.focused.mousemoved and element == pop.screen then
|
if previously_hovered and previously_hovered.hovered then
|
||||||
return pop.focused:mousemoved(x - pop.focused.data.x, y - pop.focused.data.y, dx, dy)
|
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
|
end
|
||||||
return false
|
return false
|
||||||
end
|
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) ->
|
pop.mousemoved = (x, y, dx, dy, element=pop.screen) ->
|
||||||
local previously_hovered
|
local previously_hovered
|
||||||
if element == pop.screen
|
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
|
-- 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)
|
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
|
for i = 1, #element.child
|
||||||
pop.mousemoved x, y, dx, dy, element.child[i]
|
pop.mousemoved x, y, dx, dy, element.child[i]
|
||||||
|
|
||||||
-- if we're hovering over something different, log it, and call handlers if relevant
|
-- check element == pop.screen so this is only called once at the end
|
||||||
if element == pop.screen and pop.hovered != previously_hovered
|
if element == pop.screen
|
||||||
log " pop.hovered: #{pop.hovered} (#{pop.hovered.data.type})"
|
-- if we're hovering over something different, log it, and call handlers if relevant
|
||||||
if previously_hovered.hovered
|
if pop.hovered != previously_hovered
|
||||||
previously_hovered\hovered false
|
log " pop.hovered: #{pop.hovered} (#{pop.hovered.data.type})"
|
||||||
if pop.hovered.hovered
|
if previously_hovered and previously_hovered.hovered -- previously_hovered can be a false boolean
|
||||||
pop.hovered\hovered true
|
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
|
||||||
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
|
||||||
return pop.focused\mousemoved x - pop.focused.data.x, y - pop.focused.data.y, dx, dy
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user