Кнопки + заголовок в imgui

NHacker1271

Известный
Автор темы
156
16
Версия MoonLoader
.026-beta
Как закрасить одну кнопку в отличии от остальных?
Это возможно?
А и ещё как центрировать заголовок?
 

Вложения

  • sa-mp-000.png
    sa-mp-000.png
    381.9 KB · Просмотры: 514
Решение
Как закрасить одну кнопку в отличии от остальных?
Lua:
function imgui.CustomButton(gg, color, colorHovered, colorActive, size)
    local clr = imgui.Col
    imgui.PushStyleColor(clr.Button, color)
    imgui.PushStyleColor(clr.ButtonHovered, colorHovered)
    imgui.PushStyleColor(clr.ButtonActive, colorActive)
    if not size then size = imgui.ImVec2(0, 0) end
    local result = imgui.Button(gg, size)
    imgui.PopStyleColor(3)
    return result
end



--OnDrawFrame
imgui.CustomButton(u8'КнопОчка', imgui.ImVec4(0.2,0.2,0.2,1), imgui.ImVec4(0.2,0.2,0.2,1), imgui.ImVec2(80,80))
А и ещё как центрировать заголовок?
Lua:
--В любую часть кода (ВНЕ ДРУГИХ ФУНКЦИЙ!!!)
function apply_custom_style()
    imgui.SwitchContext()...

CaJlaT

Овощ
Модератор
2,805
2,606
Как закрасить одну кнопку в отличии от остальных?
Lua:
function imgui.CustomButton(gg, color, colorHovered, colorActive, size)
    local clr = imgui.Col
    imgui.PushStyleColor(clr.Button, color)
    imgui.PushStyleColor(clr.ButtonHovered, colorHovered)
    imgui.PushStyleColor(clr.ButtonActive, colorActive)
    if not size then size = imgui.ImVec2(0, 0) end
    local result = imgui.Button(gg, size)
    imgui.PopStyleColor(3)
    return result
end



--OnDrawFrame
imgui.CustomButton(u8'КнопОчка', imgui.ImVec4(0.2,0.2,0.2,1), imgui.ImVec4(0.2,0.2,0.2,1), imgui.ImVec2(80,80))
А и ещё как центрировать заголовок?
Lua:
--В любую часть кода (ВНЕ ДРУГИХ ФУНКЦИЙ!!!)
function apply_custom_style()
    imgui.SwitchContext()
    local style = imgui.GetStyle()
    style.WindowTitleAlign = imgui.ImVec2(0.5, 0.5)
end
apply_custom_style()
 
  • Нравится
Реакции: NHacker1271

NHacker1271

Известный
Автор темы
156
16
Lua:
function imgui.CustomButton(gg, color, colorHovered, colorActive, size)
    local clr = imgui.Col
    imgui.PushStyleColor(clr.Button, color)
    imgui.PushStyleColor(clr.ButtonHovered, colorHovered)
    imgui.PushStyleColor(clr.ButtonActive, colorActive)
    if not size then size = imgui.ImVec2(0, 0) end
    local result = imgui.Button(gg, size)
    imgui.PopStyleColor(3)
    return result
end

--OnDrawFrame
imgui.CustomButton(u8'КнопОчка', imgui.ImVec4(0.2,0.2,0.2,1), imgui.ImVec4(0.2,0.2,0.2,1), imgui.ImVec2(80,80))
Тут такая проблемка..
[17:03:13.358547] (error) img.lua: C:\Games\GTA San Andreas MultiPlayer\moonloader\img.lua:72: sol: no matching function call takes this number of arguments and the specified types
stack traceback:
[C]: in function 'PushStyleColor'
C:\Games\GTA San Andreas MultiPlayer\moonloader\img.lua:72: in function 'CustomButton'
C:\Games\GTA San Andreas MultiPlayer\moonloader\img.lua:92: in function 'OnDrawFrame'
...mes\GTA San Andreas MultiPlayer\moonloader\lib\imgui.lua:1378: in function <...mes\GTA San Andreas MultiPlayer\moonloader\lib\imgui.lua:1367>
[17:03:13.358547] (error) img.lua: Script died due to an error. (25AD388C)
 

Cosmo

Известный
Друг
646
2,597
Есть ещё такой варик, через Hex задавать цвет кнопки, правда он немного костыльный
Lua:
function imgui.ButtonHex(lable, rgb, size)
    local r = bit.band(bit.rshift(rgb, 16), 0xFF) / 255
    local g = bit.band(bit.rshift(rgb, 8), 0xFF) / 255
    local b = bit.band(rgb, 0xFF) / 255

    imgui.PushStyleColor(imgui.Col.Button, imgui.ImVec4(r, g, b, 0.6))
    imgui.PushStyleColor(imgui.Col.ButtonHovered, imgui.ImVec4(r, g, b, 0.8))
    imgui.PushStyleColor(imgui.Col.ButtonActive, imgui.ImVec4(r, g, b, 1.0))
    local button = imgui.Button(lable, size)
    imgui.PopStyleColor(3) 
    return button
end
Lua:
imgui.ButtonHex(u8'Кнопка', 0xFF0000, imgui.ImVec2(-1, 20))
 
Последнее редактирование: