#226 bugfixes and pocket mouse events

This commit is contained in:
Mikayla Fischler
2023-05-11 19:55:02 -04:00
parent 676dfc8c22
commit 0783c4c01f
6 changed files with 27 additions and 18 deletions

View File

@ -105,7 +105,7 @@ local function multi_button(args)
---@param event mouse_interaction mouse event
function e.handle_mouse(event)
-- if enabled and the button row was pressed...
if e.enabled and core.events.was_clicked(event.type) and (event.initial.y == 1) and (event.current.y == 1) then
if e.enabled and core.events.was_clicked(event.type) then
-- a button may have been pressed, which one was it?
local button_ini = which_button(event.initial.x)
local button_cur = which_button(event.current.x)

View File

@ -26,6 +26,8 @@ local CLICK_TYPE = core.events.CLICK_TYPE
local function push_button(args)
assert(type(args.text) == "string", "graphics.elements.controls.push_button: text is a required field")
assert(type(args.callback) == "function", "graphics.elements.controls.push_button: callback is a required field")
assert(type(args.min_width) == "nil" or (type(args.min_width) == "number" and args.min_width > 0),
"graphics.elements.controls.push_button: min_width must be nil or a number > 0")
local text_width = string.len(args.text)

View File

@ -23,13 +23,15 @@ local function switch_button(args)
assert(type(args.text) == "string", "graphics.elements.controls.switch_button: text is a required field")
assert(type(args.callback) == "function", "graphics.elements.controls.switch_button: callback is a required field")
assert(type(args.active_fg_bg) == "table", "graphics.elements.controls.switch_button: active_fg_bg is a required field")
assert(type(args.min_width) == "nil" or (type(args.min_width) == "number" and args.min_width > 0),
"graphics.elements.controls.switch_button: min_width must be nil or a number > 0")
-- single line
args.height = 1
-- determine widths
local text_width = string.len(args.text)
args.width = math.max(text_width + 2, args.min_width)
-- single line height, calculate width
args.height = 1
args.min_width = args.min_width or 0
args.width = math.max(text_width, args.min_width)
-- create new graphics element base object
local e = element.new(args)