--TEXT COLOR RGB local explode_argb function argb local bit band bit r

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
--TEXT COLOR RGB
local explode_argb = function(argb)
local a = bit.band(bit.rshift(argb, 24), 0xFF)
local r = bit.band(bit.rshift(argb, 16), 0xFF)
local g = bit.band(bit.rshift(argb, 8), 0xFF)
local b = bit.band(argb, 0xFF)
return a, r, g, b
end
local convertHexColorToImVec = function(color)
if color:sub(1, 6):upper() == 'SSSSSS' then
return imgui.GetStyle().Colors[imgui.Col.Text]
end
local color = type(color) == 'string' and tonumber(color, 16) or color
if type(color) ~= 'number' then return end
local r, g, b, a = explode_argb(color)
return imgui.ImVec4(r / 255, g / 255, b / 255, a / 255)
end
function imgui.TextColoredRGB(text, mode, max_float, wrap)
max_float = max_float or imgui.GetWindowWidth()
wrap = wrap or 0
local function render_text(text)
for w in text:gmatch('[^\r\n]+') do
local text, colors = {}, {}
local m = 1
w = w:gsub('{(......)}', '{%1FF}')
while w:find('{........}') do
local n, k = w:find('{........}')
local color = convertHexColorToImVec(w:sub(n + 1, k - 1))
if color then
text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
table.insert(colors, color)
m = n
end
w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
end
local length = imgui.CalcTextSize(w)
if mode == 2 then
imgui.NewLine()
imgui.SameLine(max_float / 2 - ( length.x / 2 ))
elseif mode == 3 then
imgui.NewLine()
imgui.SameLine(max_float - length.x - 5 )
end
if text[0] then
for i, k in pairs(text) do
imgui.TextColored(colors[i] or imgui.GetStyle().Colors[imgui.Col.Text], k)
imgui.SameLine(nil, 0)
end
imgui.NewLine()
else
imgui.Text(w)
end
end
end
imgui.PushTextWrapPos(wrap)
render_text(text)
imgui.PopTextWrapPos()
end
--TEXT COLOR RGB