diff options
author | Matthias Richter <matthias.richter@iosb.fraunhofer.de> | 2013-12-11 15:19:04 +0100 |
---|---|---|
committer | Matthias Richter <matthias.richter@iosb.fraunhofer.de> | 2013-12-11 15:25:06 +0100 |
commit | 66a089a07f4d24557cb8e06f78eefb07a344ea32 (patch) | |
tree | 9e9fbaa80393cb50d5fa05b94098a1a99717d5ec /keyboard.lua | |
parent | ffd187dc177f4a15fa2e87579b9cbabee38b8245 (diff) | |
download | Quickie-66a089a07f4d24557cb8e06f78eefb07a344ea32.tar.gz Quickie-66a089a07f4d24557cb8e06f78eefb07a344ea32.tar.bz2 Quickie-66a089a07f4d24557cb8e06f78eefb07a344ea32.tar.xz Quickie-66a089a07f4d24557cb8e06f78eefb07a344ea32.zip |
Fix bug in input.lua, make 0.9-ready, add utf8 editing
1) [input.lua] Pressing backspace while the cursor was at the beggining
of the text removed the first character. Fixed thanks to riidom.
2) [LÖVE 0.9] Use setLine(Width|Style) instead of setLine. Split
keyboard.pressed() into keyboard.pressed() and keyboard.textinput().
(see readme)
3) [utf8.lua] Add support for UTF-8 text editing. May still fail
spectacurlarly with invalid UTF-8 strings.
Diffstat (limited to 'keyboard.lua')
-rw-r--r-- | keyboard.lua | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/keyboard.lua b/keyboard.lua index 4850df3..0e52eb3 100644 --- a/keyboard.lua +++ b/keyboard.lua @@ -24,7 +24,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]]-- -local key,code = nil, -1 +local key,str = nil, nil local focus, lastwidget local NO_WIDGET = {} @@ -34,11 +34,16 @@ local cycle = { next = {key = 'tab'}, } -local function pressed(...) - key, code = ... - assert(type(key) == 'string', 'Invalid argument `key`. Expected string, got ' .. type(key)) - assert(type(code) == 'number', 'Invalid argument `code`. Expected number, got ' .. type(code)) +local function pressed(k) + assert(type(k) == 'string', 'Invalid argument `key`. Expected string, got ' .. type(k)) + key = k end + +local function textinput(s) + assert(type(s) == 'string', 'Invalid argument `key`. Expected string, got ' .. type(s)) + str = s +end + local function setFocus(id) focus = id end local function disable() focus = NO_WIDGET end local function clearFocus() focus = nil end @@ -79,12 +84,13 @@ local function beginFrame() end local function endFrame() - key, code = nil, -1 + key, str = nil, nil end return setmetatable({ cycle = cycle, pressed = pressed, + textinput = textinput, tryGrab = tryGrab, isBindingDown = isBindingDown, setFocus = setFocus, @@ -99,4 +105,4 @@ return setmetatable({ beginFrame = beginFrame, endFrame = endFrame, -}, {__index = function(_,k) return ({key = key, code = code})[k] end}) +}, {__index = function(_,k) return ({key = key, str = str})[k] end}) |