fix 'Input widget will raise error when candidate_text field is not defined'
This commit is contained in:
parent
6b302f777c
commit
12610bfe8f
4 changed files with 12 additions and 3 deletions
|
@ -23,7 +23,7 @@ More info and code is over at [readthedocs](http://suit.readthedocs.org/en/lates
|
|||
local suit = require 'suit'
|
||||
|
||||
-- storage for text input
|
||||
local input = {text = "", candidate_text = {text="", start=0, length=0}}
|
||||
local input = {text = ""}
|
||||
|
||||
-- make love use font which support CJK text
|
||||
function love.load()
|
||||
|
@ -62,7 +62,7 @@ end
|
|||
|
||||
function love.textedited(text, start, length)
|
||||
-- for IME input
|
||||
input.candidate_text = {text = text, start= start, length = length}
|
||||
suit.textedited(text, start, length)
|
||||
end
|
||||
|
||||
function love.textinput(t)
|
||||
|
|
7
core.lua
7
core.lua
|
@ -13,6 +13,7 @@ function suit.new(theme)
|
|||
theme = theme or default_theme,
|
||||
mouse_x = 0, mouse_y = 0,
|
||||
mouse_button_down = false,
|
||||
candidate_text = {text="", start=0, length=0},
|
||||
|
||||
draw_queue = {n = 0},
|
||||
|
||||
|
@ -146,6 +147,12 @@ function suit:textinput(char)
|
|||
self.textchar = char
|
||||
end
|
||||
|
||||
function suit:textedited(text, start, length)
|
||||
self.candidate_text.text = text
|
||||
self.candidate_text.start = start
|
||||
self.candidate_text.length = length
|
||||
end
|
||||
|
||||
function suit:grabKeyboardFocus(id)
|
||||
if self:isActive(id) then
|
||||
if love.system.getOS() == "Android" or love.system.getOS() == "iOS" then
|
||||
|
|
1
init.lua
1
init.lua
|
@ -32,6 +32,7 @@ return setmetatable({
|
|||
getPressedKey = function(...) return instance:getPressedKey(...) end,
|
||||
keypressed = function(...) return instance:keypressed(...) end,
|
||||
textinput = function(...) return instance:textinput(...) end,
|
||||
textedited = function(...) return instance:textedited(...) end,
|
||||
grabKeyboardFocus = function(...) return instance:grabKeyboardFocus(...) end,
|
||||
hasKeyboardFocus = function(...) return instance:hasKeyboardFocus(...) end,
|
||||
keyPressedOn = function(...) return instance:keyPressedOn(...) end,
|
||||
|
|
|
@ -57,7 +57,7 @@ return function(core, input, ...)
|
|||
opt.state = core:registerHitbox(opt.id, x,y,w,h)
|
||||
opt.hasKeyboardFocus = core:grabKeyboardFocus(opt.id)
|
||||
|
||||
if (input.candidate_text.text == "") and opt.hasKeyboardFocus then
|
||||
if (core.candidate_text.text == "") and opt.hasKeyboardFocus then
|
||||
local keycode,char = core:getPressedKey()
|
||||
-- text input
|
||||
if char and char ~= "" then
|
||||
|
@ -102,6 +102,7 @@ return function(core, input, ...)
|
|||
end
|
||||
end
|
||||
|
||||
input.candidate_text = {text=core.candidate_text.text, start=core.candidate_text.start, length=core.candidate_text.length}
|
||||
core:registerDraw(opt.draw or core.theme.Input, input, opt, x,y,w,h)
|
||||
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue