Подсветка кнопки при нажатии mimgui

KmAuArJo850

Новичок
Автор темы
20
2
Версия MoonLoader
Другое
Добрый день! Подскажите, пожалуйста, как можно сделать, чтобы кнопка в mimgui после нажатия становилась активной (Как будто её щас зажали(такой же цвет)), а после повторного нажатия становилась обычной, так сказать включатель/выключатель. Именно кнопка, а не чекбокс
 
  • Вау
  • Клоун
Реакции: Lance_Sterling и qdIbp
Решение
Lua:
function imgui.ToggleButton(text, isActive, size)
    local colors = imgui.GetStyle().Colors;
    imgui.PushStyleColor(imgui.Col.Button, colors[isActive and imgui.Col.ButtonActive or imgui.Col.Button]);
    local button = imgui.Button(text, size);
    imgui.PopStyleColor();
    return button;   
end

local enabled = false;

if (imgui.ToggleButton('Click here', enabled)) then
    enabled = not enabled;
    print(enabled and 'on' or 'off');
end

Lance_Sterling

Известный
801
284
Lua:
CheckBoxButton = setmetatable({}, {
    __call = function(self, text, size)
        if not self[text] then self[text] = false; end

        if self[text] then
            imgui.PushStyleColor(imgui.Col.Button, imgui.GetStyle().Colors[imgui.Col.ButtonActive])
            if imgui.Button(text, size) then self[text] = not self[text]; end;
            imgui.PopStyleColor()
        else
            if imgui.Button(text, size) then self[text] = not self[text]; end;
        end

        return self[text];
    end
})

-- \\ Использование:
if CheckBoxButton("test") then
   sampAddChatMessage('жопа хуй пизда', -1)
end
 
Последнее редактирование:
  • Клоун
Реакции: MLycoris и chapo

chapo

🫡 В армии с 17.10.2023. В ЛС НЕ ОТВЕЧАЮ
Друг
8,776
11,226
Lua:
function imgui.ToggleButton(text, isActive, size)
    local colors = imgui.GetStyle().Colors;
    imgui.PushStyleColor(imgui.Col.Button, colors[isActive and imgui.Col.ButtonActive or imgui.Col.Button]);
    local button = imgui.Button(text, size);
    imgui.PopStyleColor();
    return button;   
end

local enabled = false;

if (imgui.ToggleButton('Click here', enabled)) then
    enabled = not enabled;
    print(enabled and 'on' or 'off');
end
 
  • Нравится
  • Вау
Реакции: Sworikk и Lance_Sterling