Supports utf8 printing and input
Changes to be committed: modified: src/ltui/label.lua modified: src/ltui/textedit.lua
This commit is contained in:
@@ -127,8 +127,20 @@ function label:splitext(text, width)
|
|||||||
for idx = 1, #lines do
|
for idx = 1, #lines do
|
||||||
local line = lines[idx]
|
local line = lines[idx]
|
||||||
while #line > width do
|
while #line > width do
|
||||||
table.insert(result, line:sub(1, width))
|
local size = 0
|
||||||
line = line:sub(width + 1)
|
for i = 1, #line do
|
||||||
|
if line:byte(i) < 0x80 or line:byte(i) >= 0xc0 then
|
||||||
|
size = size + 1
|
||||||
|
if size > width then
|
||||||
|
table.insert(result, line:sub(1, i - 1))
|
||||||
|
line = line:sub(i)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if size <= width then
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
table.insert(result, line)
|
table.insert(result, line)
|
||||||
end
|
end
|
||||||
|
@@ -77,8 +77,8 @@ function textedit:on_event(e)
|
|||||||
|
|
||||||
-- update text
|
-- update text
|
||||||
if e.type == event.ev_keyboard then
|
if e.type == event.ev_keyboard then
|
||||||
if e.key_code > 0x1f and e.key_code < 0x7f then
|
if e.key_code > 0x1f and e.key_code < 0x100 then
|
||||||
self:text_set(self:text() .. e.key_name)
|
self:text_set(self:text() .. string.char(e.key_code))
|
||||||
return true
|
return true
|
||||||
elseif e.key_name == "Enter" and self:option("multiline") then
|
elseif e.key_name == "Enter" and self:option("multiline") then
|
||||||
self:text_set(self:text() .. '\n')
|
self:text_set(self:text() .. '\n')
|
||||||
@@ -86,7 +86,11 @@ function textedit:on_event(e)
|
|||||||
elseif e.key_name == "Backspace" then
|
elseif e.key_name == "Backspace" then
|
||||||
local text = self:text()
|
local text = self:text()
|
||||||
if #text > 0 then
|
if #text > 0 then
|
||||||
self:text_set(text:sub(1, #text - 1))
|
local ch_size = -1
|
||||||
|
while text:byte(ch_size) > 0x7f and text:byte(ch_size) < 0xc0 do
|
||||||
|
ch_size = ch_size - 1
|
||||||
|
end
|
||||||
|
self:text_set(text:sub(1, #text + ch_size))
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
elseif e.key_name == "CtrlV" then
|
elseif e.key_name == "CtrlV" then
|
||||||
|
Reference in New Issue
Block a user