diff --git a/graphics/core.lua b/graphics/core.lua index d601bb3..e2587fc 100644 --- a/graphics/core.lua +++ b/graphics/core.lua @@ -7,7 +7,7 @@ local flasher = require("graphics.flasher") local core = {} -core.version = "2.2.0" +core.version = "2.2.1" core.flasher = flasher core.events = events diff --git a/graphics/elements/controls/hazard_button.lua b/graphics/elements/controls/hazard_button.lua index 9a0e621..7c2306f 100644 --- a/graphics/elements/controls/hazard_button.lua +++ b/graphics/elements/controls/hazard_button.lua @@ -138,23 +138,21 @@ local function hazard_button(args) -- handle mouse interaction ---@param event mouse_interaction mouse event function e.handle_mouse(event) - if e.enabled then - if core.events.was_clicked(event.type) then - -- change text color to indicate clicked - e.w_set_fgd(args.accent) - e.w_set_cur(3, 2) - e.w_write(args.text) + if e.enabled and core.events.was_clicked(event.type) and e.in_frame_bounds(event.current.x, event.current.y) then + -- change text color to indicate clicked + e.w_set_fgd(args.accent) + e.w_set_cur(3, 2) + e.w_write(args.text) - -- abort any other callbacks - tcd.abort(on_timeout) - tcd.abort(on_success) - tcd.abort(on_failure) + -- abort any other callbacks + tcd.abort(on_timeout) + tcd.abort(on_success) + tcd.abort(on_failure) - -- 1.5 second timeout - tcd.dispatch(1.5, on_timeout) + -- 1.5 second timeout + tcd.dispatch(1.5, on_timeout) - args.callback() - end + args.callback() end end diff --git a/graphics/elements/controls/radio_button.lua b/graphics/elements/controls/radio_button.lua index aee7060..be9b1ee 100644 --- a/graphics/elements/controls/radio_button.lua +++ b/graphics/elements/controls/radio_button.lua @@ -90,7 +90,8 @@ local function radio_button(args) -- handle mouse interaction ---@param event mouse_interaction mouse event function e.handle_mouse(event) - if e.enabled and core.events.was_clicked(event.type) and (event.initial.y == event.current.y) then + if e.enabled and core.events.was_clicked(event.type) and + (event.initial.y == event.current.y) and e.in_frame_bounds(event.current.x, event.current.y) then -- determine what was pressed if args.options[event.current.y] ~= nil then e.value = event.current.y diff --git a/graphics/elements/controls/spinbox_numeric.lua b/graphics/elements/controls/spinbox_numeric.lua index 90edf18..e114c6a 100644 --- a/graphics/elements/controls/spinbox_numeric.lua +++ b/graphics/elements/controls/spinbox_numeric.lua @@ -127,20 +127,19 @@ local function spinbox(args) ---@param event mouse_interaction mouse event function e.handle_mouse(event) -- only handle if on an increment or decrement arrow - if e.enabled and core.events.was_clicked(event.type) and - (event.current.x ~= dec_point_x) and (event.current.y ~= 2) then - if event.current.x == event.initial.x and event.current.y == event.initial.y then - local idx = util.trinary(event.current.x > dec_point_x, event.current.x - 1, event.current.x) - if digits[idx] ~= nil then - if event.current.y == 1 then - digits[idx] = digits[idx] + 1 - elseif event.current.y == 3 then - digits[idx] = digits[idx] - 1 - end - - update_value() - show_num() + if e.enabled and core.events.was_clicked(event.type) and e.in_frame_bounds(event.current.x, event.current.y) and + (event.current.x ~= dec_point_x) and (event.current.y ~= 2) and + (event.current.x == event.initial.x) and (event.current.y == event.initial.y) then + local idx = util.trinary(event.current.x > dec_point_x, event.current.x - 1, event.current.x) + if digits[idx] ~= nil then + if event.current.y == 1 then + digits[idx] = digits[idx] + 1 + elseif event.current.y == 3 then + digits[idx] = digits[idx] - 1 end + + update_value() + show_num() end end end diff --git a/graphics/elements/controls/switch_button.lua b/graphics/elements/controls/switch_button.lua index f649b10..ac44ca6 100644 --- a/graphics/elements/controls/switch_button.lua +++ b/graphics/elements/controls/switch_button.lua @@ -58,7 +58,7 @@ local function switch_button(args) -- handle mouse interaction ---@param event mouse_interaction mouse event function e.handle_mouse(event) - if e.enabled and core.events.was_clicked(event.type) then + if e.enabled and core.events.was_clicked(event.type) and e.in_frame_bounds(event.current.x, event.current.y) then e.value = not e.value e.redraw() args.callback(e.value) diff --git a/graphics/elements/controls/tabbar.lua b/graphics/elements/controls/tabbar.lua index 9b604e1..c76781b 100644 --- a/graphics/elements/controls/tabbar.lua +++ b/graphics/elements/controls/tabbar.lua @@ -98,7 +98,7 @@ local function tabbar(args) ---@param event mouse_interaction mouse event function e.handle_mouse(event) -- determine what was pressed - if e.enabled and core.events.was_clicked(event.type) then + if e.enabled and core.events.was_clicked(event.type) and e.in_frame_bounds(event.current.x, event.current.y) then -- a button may have been pressed, which one was it? local tab_ini = which_tab(event.initial.x) local tab_cur = which_tab(event.current.x) diff --git a/graphics/elements/form/number_field.lua b/graphics/elements/form/number_field.lua index 66731ad..ef383ce 100644 --- a/graphics/elements/form/number_field.lua +++ b/graphics/elements/form/number_field.lua @@ -53,11 +53,11 @@ local function number_field(args) ---@param event mouse_interaction mouse event function e.handle_mouse(event) -- only handle if on an increment or decrement arrow - if e.enabled then + if e.enabled and e.in_frame_bounds(event.current.x, event.current.y) then if core.events.was_clicked(event.type) then e.take_focus() - if event.type == MOUSE_CLICK.UP and e.in_frame_bounds(event.current.x, event.current.y) then + if event.type == MOUSE_CLICK.UP then ifield.move_cursor(event.current.x) end elseif event.type == MOUSE_CLICK.DOUBLE_CLICK then diff --git a/graphics/elements/form/text_field.lua b/graphics/elements/form/text_field.lua index 843ec24..f912b9e 100644 --- a/graphics/elements/form/text_field.lua +++ b/graphics/elements/form/text_field.lua @@ -41,11 +41,11 @@ local function text_field(args) ---@param event mouse_interaction mouse event function e.handle_mouse(event) -- only handle if on an increment or decrement arrow - if e.enabled then + if e.enabled and e.in_frame_bounds(event.current.x, event.current.y) then if core.events.was_clicked(event.type) then e.take_focus() - if event.type == MOUSE_CLICK.UP and e.in_frame_bounds(event.current.x, event.current.y) then + if event.type == MOUSE_CLICK.UP then ifield.move_cursor(event.current.x) end elseif event.type == MOUSE_CLICK.DOUBLE_CLICK then