#299 fixed mouse events passing to hidden elements

This commit is contained in:
Mikayla Fischler 2023-07-29 00:25:20 -04:00
parent 9f8732830c
commit b3c7263bc4
2 changed files with 12 additions and 9 deletions

View File

@ -7,7 +7,7 @@ local flasher = require("graphics.flasher")
local core = {}
core.version = "1.0.2"
core.version = "1.0.3"
core.flasher = flasher
core.events = events

View File

@ -20,6 +20,7 @@ local element = {}
---@alias graphics_args graphics_args_generic
---|waiting_args
---|app_button_args
---|checkbox_args
---|hazard_button_args
---|multi_button_args
@ -515,19 +516,21 @@ function element.new(args, child_offset_x, child_offset_y)
-- FUNCTION CALLBACKS --
-- handle a monitor touch or mouse click
-- handle a monitor touch or mouse click if this element is visible
---@param event mouse_interaction mouse interaction event
function public.handle_mouse(event)
local x_ini, y_ini = event.initial.x, event.initial.y
if protected.window.isVisible() then
local x_ini, y_ini = event.initial.x, event.initial.y
local ini_in = protected.in_window_bounds(x_ini, y_ini)
local ini_in = protected.in_window_bounds(x_ini, y_ini)
if ini_in then
local event_T = core.events.mouse_transposed(event, self.position.x, self.position.y)
if ini_in then
local event_T = core.events.mouse_transposed(event, self.position.x, self.position.y)
-- handle the mouse event then pass to children
protected.handle_mouse(event_T)
for _, child in pairs(protected.children) do child.handle_mouse(event_T) end
-- handle the mouse event then pass to children
protected.handle_mouse(event_T)
for _, child in pairs(protected.children) do child.handle_mouse(event_T) end
end
end
end