Input-widget only fires event when activated
This commit is contained in:
parent
7f0689d012
commit
2c24ba3ca0
1 changed files with 1 additions and 5 deletions
|
@ -42,18 +42,15 @@ return function(w)
|
||||||
keyboard.makeCyclable(id)
|
keyboard.makeCyclable(id)
|
||||||
if mouse.isActive(id) then keyboard.setFocus(id) end
|
if mouse.isActive(id) then keyboard.setFocus(id) end
|
||||||
|
|
||||||
local changed = false
|
|
||||||
if not keyboard.hasFocus(id) then
|
if not keyboard.hasFocus(id) then
|
||||||
--[[nothing]]
|
--[[nothing]]
|
||||||
-- editing
|
-- editing
|
||||||
elseif keyboard.key == 'backspace' then
|
elseif keyboard.key == 'backspace' then
|
||||||
w.info.text = w.info.text:sub(1,w.info.cursor-1) .. w.info.text:sub(w.info.cursor+1)
|
w.info.text = w.info.text:sub(1,w.info.cursor-1) .. w.info.text:sub(w.info.cursor+1)
|
||||||
w.info.cursor = math.max(0, w.info.cursor-1)
|
w.info.cursor = math.max(0, w.info.cursor-1)
|
||||||
changed = true
|
|
||||||
elseif keyboard.key == 'delete' then
|
elseif keyboard.key == 'delete' then
|
||||||
w.info.text = w.info.text:sub(1,w.info.cursor) .. w.info.text:sub(w.info.cursor+2)
|
w.info.text = w.info.text:sub(1,w.info.cursor) .. w.info.text:sub(w.info.cursor+2)
|
||||||
w.info.cursor = math.min(w.info.text:len(), w.info.cursor)
|
w.info.cursor = math.min(w.info.text:len(), w.info.cursor)
|
||||||
changed = true
|
|
||||||
-- movement
|
-- movement
|
||||||
elseif keyboard.key == 'left' then
|
elseif keyboard.key == 'left' then
|
||||||
w.info.cursor = math.max(0, w.info.cursor-1)
|
w.info.cursor = math.max(0, w.info.cursor-1)
|
||||||
|
@ -72,11 +69,10 @@ return function(w)
|
||||||
local right = w.info.text:sub(w.info.cursor+1)
|
local right = w.info.text:sub(w.info.cursor+1)
|
||||||
w.info.text = table.concat{left, string.char(keyboard.code), right}
|
w.info.text = table.concat{left, string.char(keyboard.code), right}
|
||||||
w.info.cursor = w.info.cursor + 1
|
w.info.cursor = w.info.cursor + 1
|
||||||
changed = true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
core.registerDraw(id, w.draw or core.style.Input,
|
core.registerDraw(id, w.draw or core.style.Input,
|
||||||
w.info.text, w.info.cursor, pos[1],pos[2], size[1],size[2])
|
w.info.text, w.info.cursor, pos[1],pos[2], size[1],size[2])
|
||||||
|
|
||||||
return changed
|
return mouse.releasedOn(id) or (keyboard.key == 'return' and keyboard.hasFocus(id))
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue