huge improvement to fitTextToWidth
This commit is contained in:
1 parent
081f10f9c3
commit
6cdd64b8e7
1 file changed
+15
-8
+15
-8
@@ -742,6 +742,19 @@ function EID:filterColorMarkup(text, baseKColor)
|
|||||||
return textPartsTable
|
return textPartsTable
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- A simple function to replace all markup {{ }} with placeholder strings, to use in fitTextToWidth
|
||||||
|
function EID:replaceAllMarkupWithSpaces(text)
|
||||||
|
for word in string.gmatch(text, "{{.-}}") do
|
||||||
|
local lookup = EID:getIcon(word)
|
||||||
|
if lookup[1] ~= "ERROR" then
|
||||||
|
text = string.gsub(text, word, EID:generatePlaceholderString(lookup[3]), 1)
|
||||||
|
else
|
||||||
|
text = string.gsub(text, word, "", 1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return text
|
||||||
|
end
|
||||||
|
|
||||||
-- Fits a given string to a specific width
|
-- Fits a given string to a specific width
|
||||||
-- returns the string as a table of lines
|
-- returns the string as a table of lines
|
||||||
function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars)
|
function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars)
|
||||||
@@ -815,14 +828,8 @@ function EID:fitTextToWidth(str, textboxWidth, breakUtf8Chars)
|
|||||||
|
|
||||||
-- we can break after str[cursor]
|
-- we can break after str[cursor]
|
||||||
local word = sub(str, word_begin_index, cursor)
|
local word = sub(str, word_begin_index, cursor)
|
||||||
|
local wordFiltered = EID:replaceAllMarkupWithSpaces(word)
|
||||||
local colorFiltered = EID:filterColorMarkup(word, EID:getTextColor())
|
local wordLength = EID:getStrWidth(wordFiltered)
|
||||||
local filteredWord = {}
|
|
||||||
for _, filtered in ipairs(colorFiltered) do
|
|
||||||
table.insert(filteredWord, filtered[1])
|
|
||||||
end
|
|
||||||
local strFiltered, spriteTable = EID:filterIconMarkup(table.concat(filteredWord), 0, 0)
|
|
||||||
local wordLength = EID:getStrWidth(strFiltered)
|
|
||||||
|
|
||||||
if curLength + wordLength <= textboxWidth or curLength < 17 then
|
if curLength + wordLength <= textboxWidth or curLength < 17 then
|
||||||
table.insert(text, word)
|
table.insert(text, word)
|
||||||
|
|||||||
Reference in new issue
Block a user