You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See love's textedited event, which is totally undocumented. The attached code is probably the most complete example of its usage that exists. SDL backend will be exactly the same, since love's functions don't do much of anything extra.
Compose events are used for some other cases that aren't CJK as well, but I think only CJK languages use candidate lists.
Love 0.9.2 doesn't actually include everything needed for proper IME support unless you FFI in l.k.setTextInput with additional arguments and update SDL.
(the unabridged version of the following code is here. You may want to look at draw(), and you'll want to ensure that start_editing is called every time the contents change)
-- 0.9 compat. Only *really* works if you've updated SDL, though.-- function console.textedit(...)-- return console.textedited(...)-- end-- CJK IME's need to know where the cursor is in the window and the size of the-- text box in order to function properly.---- All code tested with Mozc on Windows and Linux.-- Pretend this is whatever code is needed to get the text cursor position in luigi instead of this console...localfunctionget_position()
localprefix=console.ps..""localx=console.x+console.margin+console.font:getWidth(prefix)
localy=console.y+console.h+ (console.lineHeight-console.fontSize) /2-1localh=console.font:getHeight()
localtext_l=utf8.sub(console.input, 1, console.cursor)
localtext_r=utf8.sub(console.input, console.cursor+1, -1)
localpos=x+console.font:getWidth(text_l)
localw=console.w-x-3returnpos, y, w, hendlocalfunctionstart_editing()
localx, y, w, h=get_position()
love.keyboard.setTextInput(console.visible, x, y, w, h)
love.keyboard.setKeyRepeat(true)
endlocalfunctionstop_editing()
console.editBuffer=nillove.keyboard.setTextInput(false)
love.keyboard.setKeyRepeat(false)
end-- alias so it's a little more clear why we're calling start() so much.localupdate_ime=start_editing-- You receive this event while a string is still being composed, so it's up to-- you to display it properly as this happens.-- "Properly" meaning you should draw a highlighted box with the contents of-- editbuffer wherever the text cursor is (so you'll need to do some measuring-- and temporarily insert characters into your display text)functionconsole.textedited(t, s, l)
ifnotconsole.visiblethenreturnendift=="" thenconsole.editBuffer=nilelseconsole.editBuffer= { text=t, sel=s }
endupdate_ime()
endfunctionconsole.focus(f)
ifnotconsole.visiblethenreturnendiffthen-- Work around for Windows' stupidity.stop_editing()
start_editing()
elsestop_editing()
endend-- Note: You only receive this event when the input has been finalized!functionconsole.textinput(t)
ift~=console._KEY_TOGGLEandconsole.visiblethenlocaltext_l=utf8.sub(console.input, 1, console.cursor)
localtext_r=utf8.sub(console.input, console.cursor+1, -1)
console.input=text_l..t..text_rconsole.cursor=console.cursor+utf8.len(t)
update_ime()
returntrueendreturnfalseend
The text was updated successfully, but these errors were encountered:
I'd probably accept a pull request for this, but I really have no experience with IME and wouldn't even know how to test if it's working properly.
I'd probably lean toward leaving the functionality out for 0.9.2 rather than hacking it in; so far the Love stuff is "pure" and doesn't rely on any FFI/SDL.
See love's textedited event, which is totally undocumented. The attached code is probably the most complete example of its usage that exists. SDL backend will be exactly the same, since love's functions don't do much of anything extra.
Compose events are used for some other cases that aren't CJK as well, but I think only CJK languages use candidate lists.
Love 0.9.2 doesn't actually include everything needed for proper IME support unless you FFI in l.k.setTextInput with additional arguments and update SDL.
(the unabridged version of the following code is here. You may want to look at draw(), and you'll want to ensure that start_editing is called every time the contents change)
The text was updated successfully, but these errors were encountered: