Center the small bullet point icons (#733)
* center the small bullet point icons * tweak comments * fix typo
This commit is contained in:
1 parent
58c47fca8a
commit
59a71e0cc3
2 files changed
+10
-4
No files matched your search
@@ -905,7 +905,7 @@ end
|
||||
|
||||
-- Searches thru the given string and replaces Iconplaceholders with icons.
|
||||
-- Returns 2 values. the string without the placeholders but with an accurate space between lines. and a table of all Inline Sprites
|
||||
function EID:filterIconMarkup(text)
|
||||
function EID:filterIconMarkup(text, renderBulletPointIcon)
|
||||
local spriteTable = {}
|
||||
for word in string.gmatch(text, "{{.-}}") do
|
||||
local textposition = string.find(text, word)
|
||||
@@ -916,6 +916,12 @@ function EID:filterIconMarkup(text)
|
||||
local lookup = EID:getIcon(word)
|
||||
local preceedingTextWidth = EID:getStrWidth(string.sub(text, 0, textposition - 1)) * EID.Scale
|
||||
|
||||
-- Center the small bullet point icons by adding an extra left offset to them.
|
||||
-- If the icon has a positive left offset, that means the offset is already included in the icon itself and we should not add it again
|
||||
if renderBulletPointIcon and lookup[3] < 11 and (#lookup < 5 or lookup[5] <= 0) then
|
||||
preceedingTextWidth = preceedingTextWidth + math.floor((12 - lookup[3]) / 2) * EID.Scale
|
||||
end
|
||||
|
||||
table.insert(spriteTable, {lookup, preceedingTextWidth, callback})
|
||||
text = string.gsub(text, word, EID:generatePlaceholderString(lookup[3]), 1)
|
||||
end
|
||||
@@ -1166,12 +1172,12 @@ end
|
||||
-- needs to be called in a render Callback
|
||||
-- args: string, Vector(int, int), Vector(float,float), KColor obj, bool
|
||||
-- Returns the last used KColor
|
||||
function EID:renderString(str, position, scale, kcolor)
|
||||
function EID:renderString(str, position, scale, kcolor, renderBulletPointIcon)
|
||||
str = EID:replaceShortMarkupStrings(str)
|
||||
local textPartsTable = EID:filterColorMarkup(str, kcolor)
|
||||
local offsetX = 0
|
||||
for _, textPart in ipairs(textPartsTable) do
|
||||
local strFiltered, spriteTable = EID:filterIconMarkup(textPart[1])
|
||||
local strFiltered, spriteTable = EID:filterIconMarkup(textPart[1], renderBulletPointIcon)
|
||||
EID:renderInlineIcons(spriteTable, position.X + offsetX, position.Y)
|
||||
if strFiltered then -- prevent possible crash when strFiltered is nil
|
||||
EID.font:DrawStringScaledUTF8(strFiltered, position.X + offsetX, position.Y, scale.X, scale.Y, textPart[2], 0, false)
|
||||
|
||||
Reference in new issue
Block a user