button hotkey support
This commit is contained in:
parent
4eadfee6f4
commit
5bc3f63440
2 changed files with 7 additions and 2 deletions
|
@ -30,7 +30,7 @@ local mouse = require(BASE .. 'mouse')
|
|||
local keyboard = require(BASE .. 'keyboard')
|
||||
|
||||
-- the widget
|
||||
-- {text = text, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw}
|
||||
-- {text = text, hotkey="key", pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw}
|
||||
return function(w)
|
||||
assert(type(w) == "table" and w.text, "Invalid argument")
|
||||
|
||||
|
@ -72,6 +72,6 @@ return function(w)
|
|||
core.registerDraw(id, w.draw or core.style.Button,
|
||||
w.text, pos[1],pos[2], size[1],size[2])
|
||||
|
||||
return mouse.releasedOn(id) or keyboard.pressedOn(id, 'return')
|
||||
return mouse.releasedOn(id) or keyboard.pressedOn(id, 'return') or keyboard.pressedHotkey(w.hotkey)
|
||||
end
|
||||
|
||||
|
|
|
@ -79,6 +79,10 @@ local function pressedOn(id, k)
|
|||
return (k or 'return') == key and hasFocus(id) and k
|
||||
end
|
||||
|
||||
local function pressedHotkey(hotkey)
|
||||
return hotkey and ( key == hotkey )
|
||||
end
|
||||
|
||||
local function beginFrame()
|
||||
-- for future use?
|
||||
end
|
||||
|
@ -99,6 +103,7 @@ return setmetatable({
|
|||
hasFocus = hasFocus,
|
||||
makeCyclable = makeCyclable,
|
||||
pressedOn = pressedOn,
|
||||
pressedHotkey = pressedHotkey,
|
||||
|
||||
disable = disable,
|
||||
enable = clearFocus,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue