Как сделать нормальный текст в chiled imgui

Статус
В этой теме нельзя размещать новые ответы.

#SameLine

Активный
Автор темы
417
37
Версия MoonLoader
.026-beta

Есть у меня chiled, в котором хочется сделать цветной текст с нормальным шрифтом, а выходит вот такое чудо, как сделать норм шрифт + цветной текст, именно imgui​

 

Вложения

  • sa-mp-000.png
    sa-mp-000.png
    15.8 KB · Просмотры: 76
Последнее редактирование:
Решение
Lua:
  function imgui.TextColoredRGB(text)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    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 getcolor = function(color)
        if color:sub(1, 6):upper() == 'SSSSSS' then
            local r, g, b = colors[1].x, colors[1].y, colors[1].z
            local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
            return ImVec4(r, g, b, a / 255)
        end
        local color = type(color) ==...

PanSeek

t.me/dailypanseek
Всефорумный модератор
899
1,745
Lua:
imgui.TextColored(color, text)
либо так:
Lua:
function imgui.TextColoredRGB(text, shadow, wrapped)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local designText = function(text)
        local pos = imgui.GetCursorPos()
        for i = 1, 1 do
            imgui.SetCursorPos(imgui.ImVec2(pos.x + i, pos.y))
            imgui.TextColored(imgui.ImVec4(0, 0, 0, 1), text)
            imgui.SetCursorPos(imgui.ImVec2(pos.x - i, pos.y))
            imgui.TextColored(imgui.ImVec4(0, 0, 0, 1), text)
            imgui.SetCursorPos(imgui.ImVec2(pos.x, pos.y + i))
            imgui.TextColored(imgui.ImVec4(0, 0, 0, 1), text)
            imgui.SetCursorPos(imgui.ImVec2(pos.x, pos.y - i))
            imgui.TextColored(imgui.ImVec4(0, 0, 0, 1), text)
        end
        imgui.SetCursorPos(pos)
    end
    text = text:gsub('{(%x%x%x%x%x%x)}', '{%1FF}')
    local render_func = wrapped and imgui_text_wrapped or function(clr, text)
        if clr then imgui.PushStyleColor(ffi.C.ImGuiCol_Text, clr) end
        if shadow then designText(text) end
        imgui.TextUnformatted(text)
        if clr then imgui.PopStyleColor() end
    end
    local split = function(str, delim, plain)
        local tokens, pos, i, plain = {}, 1, 1, not (plain == false)
        repeat
            local npos, epos = string.find(str, delim, pos, plain)
            tokens[i] = string.sub(str, pos, npos and npos - 1)
            pos = epos and epos + 1
            i = i + 1
        until not pos
        return tokens
    end
    local color = colors[ffi.C.ImGuiCol_Text]
    for _, w in ipairs(split(text, '\n')) do
        local start = 1
        local a, b = w:find('{........}', start)
        while a do
            local t = w:sub(start, a - 1)
            if #t > 0 then
                render_func(color, t)
                imgui.SameLine(nil, 0)
            end
            local clr = w:sub(a + 1, b - 1)
            if clr:upper() == 'STANDART' then color = colors[ffi.C.ImGuiCol_Text]
            else
                clr = tonumber(clr, 16)
                if clr then
                    local r = bit.band(bit.rshift(clr, 24), 0xFF)
                    local g = bit.band(bit.rshift(clr, 16), 0xFF)
                    local b = bit.band(bit.rshift(clr, 8), 0xFF)
                    local a = bit.band(clr, 0xFF)
                    color = imgui.ImVec4(r / 255, g / 255, b / 255, a / 255)
                end
            end
            start = b + 1
            a, b = w:find('{........}', start)
        end
        imgui.NewLine()
        if #w >= start then
            imgui.SameLine(nil, 0)
            render_func(color, w:sub(start))
        end
    end
end
 

#SameLine

Активный
Автор темы
417
37
Lua:
imgui.TextColored(color, text)
либо так:
Lua:
function imgui.TextColoredRGB(text, shadow, wrapped)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local designText = function(text)
        local pos = imgui.GetCursorPos()
        for i = 1, 1 do
            imgui.SetCursorPos(imgui.ImVec2(pos.x + i, pos.y))
            imgui.TextColored(imgui.ImVec4(0, 0, 0, 1), text)
            imgui.SetCursorPos(imgui.ImVec2(pos.x - i, pos.y))
            imgui.TextColored(imgui.ImVec4(0, 0, 0, 1), text)
            imgui.SetCursorPos(imgui.ImVec2(pos.x, pos.y + i))
            imgui.TextColored(imgui.ImVec4(0, 0, 0, 1), text)
            imgui.SetCursorPos(imgui.ImVec2(pos.x, pos.y - i))
            imgui.TextColored(imgui.ImVec4(0, 0, 0, 1), text)
        end
        imgui.SetCursorPos(pos)
    end
    text = text:gsub('{(%x%x%x%x%x%x)}', '{%1FF}')
    local render_func = wrapped and imgui_text_wrapped or function(clr, text)
        if clr then imgui.PushStyleColor(ffi.C.ImGuiCol_Text, clr) end
        if shadow then designText(text) end
        imgui.TextUnformatted(text)
        if clr then imgui.PopStyleColor() end
    end
    local split = function(str, delim, plain)
        local tokens, pos, i, plain = {}, 1, 1, not (plain == false)
        repeat
            local npos, epos = string.find(str, delim, pos, plain)
            tokens[i] = string.sub(str, pos, npos and npos - 1)
            pos = epos and epos + 1
            i = i + 1
        until not pos
        return tokens
    end
    local color = colors[ffi.C.ImGuiCol_Text]
    for _, w in ipairs(split(text, '\n')) do
        local start = 1
        local a, b = w:find('{........}', start)
        while a do
            local t = w:sub(start, a - 1)
            if #t > 0 then
                render_func(color, t)
                imgui.SameLine(nil, 0)
            end
            local clr = w:sub(a + 1, b - 1)
            if clr:upper() == 'STANDART' then color = colors[ffi.C.ImGuiCol_Text]
            else
                clr = tonumber(clr, 16)
                if clr then
                    local r = bit.band(bit.rshift(clr, 24), 0xFF)
                    local g = bit.band(bit.rshift(clr, 16), 0xFF)
                    local b = bit.band(bit.rshift(clr, 8), 0xFF)
                    local a = bit.band(clr, 0xFF)
                    color = imgui.ImVec4(r / 255, g / 255, b / 255, a / 255)
                end
            end
            start = b + 1
            a, b = w:find('{........}', start)
        end
        imgui.NewLine()
        if #w >= start then
            imgui.SameLine(nil, 0)
            render_func(color, w:sub(start))
        end
    end
end

Опять mimgui код или что?​

 

PanSeek

t.me/dailypanseek
Всефорумный модератор
899
1,745

leekyrave

Известный
420
223
Lua:
  function imgui.TextColoredRGB(text)
    local style = imgui.GetStyle()
    local colors = style.Colors
    local ImVec4 = imgui.ImVec4

    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 getcolor = function(color)
        if color:sub(1, 6):upper() == 'SSSSSS' then
            local r, g, b = colors[1].x, colors[1].y, colors[1].z
            local a = tonumber(color:sub(7, 8), 16) or colors[1].w * 255
            return ImVec4(r, g, b, a / 255)
        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.ImColor(r, g, b, a):GetVec4()
    end

    local render_text = function(text_)
        for w in text_:gmatch('[^\r\n]+') do
            local text, colors_, m = {}, {}, 1
            w = w:gsub('{(......)}', '{%1FF}')
            while w:find('{........}') do
                local n, k = w:find('{........}')
                local color = getcolor(w:sub(n + 1, k - 1))
                if color then
                    text[#text], text[#text + 1] = w:sub(m, n - 1), w:sub(k + 1, #w)
                    colors_[#colors_ + 1] = color
                    m = n
                end
                w = w:sub(1, n - 1) .. w:sub(k + 1, #w)
            end
            if text[0] then
                for i = 0, #text do
                    imgui.TextColored(colors_[i] or colors[1], (text[i]))
                    imgui.SameLine(nil, 0)
                end
                imgui.NewLine()
            else imgui.Text(w) end
        end
    end

    render_text(text)
end
Использование:
imgui.TextColoreRGB(u8('{FFFFFF}Abobus'))
 
  • Нравится
Реакции: #SameLine
Статус
В этой теме нельзя размещать новые ответы.