From b3c7263bc42623a65bc9ef8c031415d33fda5930 Mon Sep 17 00:00:00 2001 From: Mikayla Fischler Date: Sat, 29 Jul 2023 00:25:20 -0400 Subject: [PATCH] #299 fixed mouse events passing to hidden elements --- graphics/core.lua | 2 +- graphics/element.lua | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/graphics/core.lua b/graphics/core.lua index 534d4e2..5abc28d 100644 --- a/graphics/core.lua +++ b/graphics/core.lua @@ -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 diff --git a/graphics/element.lua b/graphics/element.lua index 145ee0c..5bfb7cd 100644 --- a/graphics/element.lua +++ b/graphics/element.lua @@ -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