summaryrefslogtreecommitdiffstats
path: root/src/game/client/gui/imutils_button.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/client/gui/imutils_button.cc')
-rw-r--r--src/game/client/gui/imutils_button.cc95
1 files changed, 95 insertions, 0 deletions
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;
+}