Input-widget only fires event when activated

This commit is contained in:
Matthias Richter 2013-02-06 13:28:23 +01:00
parent 7f0689d012
commit 2c24ba3ca0

View file

@ -42,18 +42,15 @@ return function(w)
keyboard.makeCyclable(id)
if mouse.isActive(id) then keyboard.setFocus(id) end
local changed = false
if not keyboard.hasFocus(id) then
--[[nothing]]
-- editing
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.cursor = math.max(0, w.info.cursor-1)
changed = true
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.cursor = math.min(w.info.text:len(), w.info.cursor)
changed = true
-- movement
elseif keyboard.key == 'left' then
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)
w.info.text = table.concat{left, string.char(keyboard.code), right}
w.info.cursor = w.info.cursor + 1
changed = true
end
core.registerDraw(id, w.draw or core.style.Input,
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