From 6c2abde5c99a236453b795abaa6d7d70105e31f7 Mon Sep 17 00:00:00 2001 From: untodesu Date: Fri, 26 Dec 2025 14:50:33 +0500 Subject: Just a big Ctrl+H refactoring --- src/game/client/gui/imutils_button.cc | 95 +++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/game/client/gui/imutils_button.cc (limited to 'src/game/client/gui/imutils_button.cc') diff --git a/src/game/client/gui/imutils_button.cc b/src/game/client/gui/imutils_button.cc new file mode 100644 index 0000000..2017e33 --- /dev/null +++ b/src/game/client/gui/imutils_button.cc @@ -0,0 +1,95 @@ +#include "client/pch.hh" + +#include "client/gui/imutils_button.hh" + +void imutils::button(const char* title, const ImVec2& size, void (*callback)(void)) +{ + assert(title); + assert(callback); + + if(ImGui::Button(title, size)) { + callback(); + } +} + +void imutils::button(const char* title, void (*callback)(void)) +{ + assert(title); + assert(callback); + + if(ImGui::Button(title)) { + callback(); + } +} + +bool imutils::selectable_button(const char* label, const ImVec2& size, bool value) +{ + assert(label); + + auto value_changed = false; + + if(value) { + ImVec4 button_color(0.750f, 0.750f, 0.750f, 1.000f); + ImGui::PushStyleColor(ImGuiCol_Button, button_color); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, button_color); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, button_color); + ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg)); + } + else { + ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg)); + } + + if(ImGui::Button(label, size)) { + value_changed = true; + } + + ImGui::PopStyleColor(value ? 4 : 1); + + return value_changed; +} + +bool imutils::toggle_button(const char* label, const ImVec2& size, bool& value) +{ + assert(label); + + auto use_custom_color = !value; + auto value_changed = false; + + if(use_custom_color) { + ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg)); + } + + if(ImGui::Button(label, size)) { + value_changed = true; + value = !value; + } + + if(use_custom_color) { + ImGui::PopStyleColor(); + } + + return value_changed; +} + +bool imutils::toggle_button(const char* label, bool& value) +{ + assert(label); + + auto use_custom_color = !value; + auto value_changed = false; + + if(use_custom_color) { + ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_WindowBg)); + } + + if(ImGui::Button(label)) { + value_changed = true; + value = !value; + } + + if(use_custom_color) { + ImGui::PopStyleColor(); + } + + return value_changed; +} -- cgit