mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
#406 bounds check all controls
This commit is contained in:
parent
6ef049baa1
commit
dbc1f41c5d
@ -7,7 +7,7 @@ local flasher = require("graphics.flasher")
|
|||||||
|
|
||||||
local core = {}
|
local core = {}
|
||||||
|
|
||||||
core.version = "2.2.0"
|
core.version = "2.2.1"
|
||||||
|
|
||||||
core.flasher = flasher
|
core.flasher = flasher
|
||||||
core.events = events
|
core.events = events
|
||||||
|
@ -138,8 +138,7 @@ local function hazard_button(args)
|
|||||||
-- handle mouse interaction
|
-- handle mouse interaction
|
||||||
---@param event mouse_interaction mouse event
|
---@param event mouse_interaction mouse event
|
||||||
function e.handle_mouse(event)
|
function e.handle_mouse(event)
|
||||||
if e.enabled then
|
if e.enabled and core.events.was_clicked(event.type) and e.in_frame_bounds(event.current.x, event.current.y) then
|
||||||
if core.events.was_clicked(event.type) then
|
|
||||||
-- change text color to indicate clicked
|
-- change text color to indicate clicked
|
||||||
e.w_set_fgd(args.accent)
|
e.w_set_fgd(args.accent)
|
||||||
e.w_set_cur(3, 2)
|
e.w_set_cur(3, 2)
|
||||||
@ -156,7 +155,6 @@ local function hazard_button(args)
|
|||||||
args.callback()
|
args.callback()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
-- callback on request response
|
-- callback on request response
|
||||||
---@param result boolean true for success, false for failure
|
---@param result boolean true for success, false for failure
|
||||||
|
@ -90,7 +90,8 @@ local function radio_button(args)
|
|||||||
-- handle mouse interaction
|
-- handle mouse interaction
|
||||||
---@param event mouse_interaction mouse event
|
---@param event mouse_interaction mouse event
|
||||||
function e.handle_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
|
-- determine what was pressed
|
||||||
if args.options[event.current.y] ~= nil then
|
if args.options[event.current.y] ~= nil then
|
||||||
e.value = event.current.y
|
e.value = event.current.y
|
||||||
|
@ -127,9 +127,9 @@ local function spinbox(args)
|
|||||||
---@param event mouse_interaction mouse event
|
---@param event mouse_interaction mouse event
|
||||||
function e.handle_mouse(event)
|
function e.handle_mouse(event)
|
||||||
-- only handle if on an increment or decrement arrow
|
-- only handle if on an increment or decrement arrow
|
||||||
if e.enabled and core.events.was_clicked(event.type) and
|
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) then
|
(event.current.x ~= dec_point_x) and (event.current.y ~= 2) and
|
||||||
if event.current.x == event.initial.x and event.current.y == event.initial.y then
|
(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)
|
local idx = util.trinary(event.current.x > dec_point_x, event.current.x - 1, event.current.x)
|
||||||
if digits[idx] ~= nil then
|
if digits[idx] ~= nil then
|
||||||
if event.current.y == 1 then
|
if event.current.y == 1 then
|
||||||
@ -143,7 +143,6 @@ local function spinbox(args)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
-- set the value
|
-- set the value
|
||||||
---@param val number number to show
|
---@param val number number to show
|
||||||
|
@ -58,7 +58,7 @@ local function switch_button(args)
|
|||||||
-- handle mouse interaction
|
-- handle mouse interaction
|
||||||
---@param event mouse_interaction mouse event
|
---@param event mouse_interaction mouse event
|
||||||
function e.handle_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.value = not e.value
|
||||||
e.redraw()
|
e.redraw()
|
||||||
args.callback(e.value)
|
args.callback(e.value)
|
||||||
|
@ -98,7 +98,7 @@ local function tabbar(args)
|
|||||||
---@param event mouse_interaction mouse event
|
---@param event mouse_interaction mouse event
|
||||||
function e.handle_mouse(event)
|
function e.handle_mouse(event)
|
||||||
-- determine what was pressed
|
-- 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?
|
-- a button may have been pressed, which one was it?
|
||||||
local tab_ini = which_tab(event.initial.x)
|
local tab_ini = which_tab(event.initial.x)
|
||||||
local tab_cur = which_tab(event.current.x)
|
local tab_cur = which_tab(event.current.x)
|
||||||
|
@ -53,11 +53,11 @@ local function number_field(args)
|
|||||||
---@param event mouse_interaction mouse event
|
---@param event mouse_interaction mouse event
|
||||||
function e.handle_mouse(event)
|
function e.handle_mouse(event)
|
||||||
-- only handle if on an increment or decrement arrow
|
-- 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
|
if core.events.was_clicked(event.type) then
|
||||||
e.take_focus()
|
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)
|
ifield.move_cursor(event.current.x)
|
||||||
end
|
end
|
||||||
elseif event.type == MOUSE_CLICK.DOUBLE_CLICK then
|
elseif event.type == MOUSE_CLICK.DOUBLE_CLICK then
|
||||||
|
@ -41,11 +41,11 @@ local function text_field(args)
|
|||||||
---@param event mouse_interaction mouse event
|
---@param event mouse_interaction mouse event
|
||||||
function e.handle_mouse(event)
|
function e.handle_mouse(event)
|
||||||
-- only handle if on an increment or decrement arrow
|
-- 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
|
if core.events.was_clicked(event.type) then
|
||||||
e.take_focus()
|
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)
|
ifield.move_cursor(event.current.x)
|
||||||
end
|
end
|
||||||
elseif event.type == MOUSE_CLICK.DOUBLE_CLICK then
|
elseif event.type == MOUSE_CLICK.DOUBLE_CLICK then
|
||||||
|
Loading…
Reference in New Issue
Block a user