Skip to content

Commit

Permalink
Merge pull request #61 from endlesstravel/master
Browse files Browse the repository at this point in the history
try fix 'Input widget will raise error when candidate_text field is not defined. ' bug
  • Loading branch information
vrld committed Oct 31, 2017
2 parents 6b302f7 + 12610bf commit 5d48cf9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions core.lua
Expand Up @@ -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},

Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions init.lua
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion input.lua
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5d48cf9

Please sign in to comment.