optimize performance for fitTextToWidth
This commit is contained in:
1 parent
f7afbada19
commit
e0407f6355
1 file changed
+6
-6
+6
-6
@@ -723,7 +723,7 @@ end
|
|||||||
function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars)
|
function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars)
|
||||||
local formatedLines = {}
|
local formatedLines = {}
|
||||||
local curLength = 0
|
local curLength = 0
|
||||||
local text = ""
|
local text = {}
|
||||||
|
|
||||||
local cursor = 1
|
local cursor = 1
|
||||||
local word_begin_index = 1
|
local word_begin_index = 1
|
||||||
@@ -740,7 +740,7 @@ function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars)
|
|||||||
local can_break_after_cursor = false
|
local can_break_after_cursor = false
|
||||||
local cur, next = byte(str,cursor), byte(str,cursor+1)
|
local cur, next = byte(str,cursor), byte(str,cursor+1)
|
||||||
if
|
if
|
||||||
-- cond#1: we can break at the end of string
|
-- cond#1: we can break at the end of string
|
||||||
cursor == #str or
|
cursor == #str or
|
||||||
-- cond#2: we can break after space
|
-- cond#2: we can break after space
|
||||||
cur == byte_space or
|
cur == byte_space or
|
||||||
@@ -803,11 +803,11 @@ function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars)
|
|||||||
local wordLength = EID:getStrWidth(strFiltered)
|
local wordLength = EID:getStrWidth(strFiltered)
|
||||||
|
|
||||||
if curLength + wordLength <= textboxWidth or curLength < 12 then
|
if curLength + wordLength <= textboxWidth or curLength < 12 then
|
||||||
text = text .. word
|
table.insert(text, word)
|
||||||
curLength = curLength + wordLength
|
curLength = curLength + wordLength
|
||||||
else
|
else
|
||||||
table.insert(formatedLines, text)
|
table.insert(formatedLines, table.concat(text))
|
||||||
text = word
|
text = { word }
|
||||||
curLength = wordLength
|
curLength = wordLength
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -817,7 +817,7 @@ function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars)
|
|||||||
cursor = cursor + 1
|
cursor = cursor + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(formatedLines, text)
|
table.insert(formatedLines, table.concat(text))
|
||||||
return formatedLines
|
return formatedLines
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user