Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
How many bytes can enter? (use Event.KEY_CHAR) — Gideros Forum

How many bytes can enter? (use Event.KEY_CHAR)

luyimoonluyimoon Member
edited December 2021 in General questions


local input = editbox.new(TTFont.new("simhei.ttf",40,""),'')

editbox = Core.class(TextField)

function editbox:init(ttf,string)
self:addEventListener(Event.KEY_CHAR,self.key_char,self)
end

function editbox:key_char(e)--over five char(utf8 chinese) can't get it,and how to achieve it (over five char)
local str = self:getText()..e.text
self:setText(str)
stage:addChild(self)
end

Comments

  • MoKaLuxMoKaLux Member
    edited December 2021
    I can have over 5 characters this way but I don't have a chinese keyboard to check when typing other letters:
    editbox = Core.class(TextField)
     
    function editbox:init(xttf, xstring)
    	self:addEventListener(Event.KEY_CHAR, self.key_char, self)
    end
     
    function editbox:key_char(e)--over five char(utf8 chinese) can't get it,and how to achieve it (over five char)
    	local str = self:getText()..e.text
    	self:setText(str)
    	stage:addChild(self)
    end
     
    ----
     
    application:setBackgroundColor(0x555555)
    local text = "你好世界!, 你好世界!"
    local input = editbox.new(TTFont.new("fonts/simhei.ttf",40,""), text)
    input:setPosition(64, 64)
    stage:addChild(input)
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • luyimoonluyimoon Member
    edited December 2021
    MoKaLux said:

    I can have over 5 characters this way but I don't have a chinese keyboard to check when typing other letters:

    editbox = Core.class(TextField)
     
    function editbox:init(xttf, xstring)
    	self:addEventListener(Event.KEY_CHAR, self.key_char, self)
    end
     
    function editbox:key_char(e)--over five char(utf8 chinese) can't get it,and how to achieve it (over five char)
    	local str = self:getText()..e.text
    	self:setText(str)
    	stage:addChild(self)
    end
     
    ----
     
    application:setBackgroundColor(0x555555)
    local text = "你好世界!, 你好世界!"
    local input = editbox.new(TTFont.new("fonts/simhei.ttf",40,""), text)
    input:setPosition(64, 64)
    stage:addChild(input)
    emm...
    if use english keyboard ,every time when you input, "e.text" just 1 byte.

    and i seen "application:setTextInput()" ,but it can't work in win32.





  • MoKaLuxMoKaLux Member
    edited December 2021 Accepted Answer
    luyimoon I think you may need the harfbuzz plugin.


    It is not documented in the wiki but I believe you just need to add it to your project and the textfields will use it.
    https://forum.gideros.rocks/discussion/7954/textfield-rtl-text-coloring

    and when harfbuzz was added to gideros as a plugin:
    https://forum.gideros.rocks/discussion/7620/arabic


    For non latin language each letter will be 1 byte and for eastern languages 2 or more bytes.
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • hgy29hgy29 Maintainer
    Accepted Answer
    Key char event was supposed to report only one character at a time, I am surprised you can even get more than one already. On which os/platform is this happening ?
  • hgy29 said:

    Key char event was supposed to report only one character at a time, I am surprised you can even get more than one already. On which os/platform is this happening ?

    PC win8.1 QQ Pinyin Typewriting.
    and
    mobile phone,Xiaomi Redmi Note 8 Pro , android 10,MIUI, QQ Pinyin Typewriting.
  • MoKaLux said:

    luyimoon I think you may need the harfbuzz plugin.


    It is not documented in the wiki but I believe you just need to add it to your project and the textfields will use it.
    https://forum.gideros.rocks/discussion/7954/textfield-rtl-text-coloring

    and when harfbuzz was added to gideros as a plugin:
    https://forum.gideros.rocks/discussion/7620/arabic


    For non latin language each letter will be 1 byte and for eastern languages 2 or more bytes.

    ok, thanks
  • i want input all string every time.
    like this.

  • hgy29hgy29 Maintainer
    Accepted Answer
    Ok, I understand, your input engine buffers characters and supply a whole sentence to the system, instead of individual characters. Gideros buffer is limited to 16 bytes (here: https://github.com/gideros/gideros/blob/master/libgid/include/ginput.h#L144), because we assumed it was enough to old two or three UTF-8 characters resulting from a composition sequence.
    As a quick way to make it work for your case, I can enlarge the buffer, but what would be a reasonable size ? 1024 would allow more than 300 3-byte characters, is that enough ?
  • hgy29 said:

    Ok, I understand, your input engine buffers characters and supply a whole sentence to the system, instead of individual characters. Gideros buffer is limited to 16 bytes (here: https://github.com/gideros/gideros/blob/master/libgid/include/ginput.h#L144), because we assumed it was enough to old two or three UTF-8 characters resulting from a composition sequence.
    As a quick way to make it work for your case, I can enlarge the buffer, but what would be a reasonable size ? 1024 would allow more than 300 3-byte characters, is that enough ?

    i think 1024 is enough.
    :D
Sign In or Register to comment.