summaryrefslogtreecommitdiff
path: root/src/ui/imgui_extensions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/imgui_extensions.cpp')
-rw-r--r--src/ui/imgui_extensions.cpp95
1 files changed, 94 insertions, 1 deletions
diff --git a/src/ui/imgui_extensions.cpp b/src/ui/imgui_extensions.cpp
index d1abc58..359fc17 100644
--- a/src/ui/imgui_extensions.cpp
+++ b/src/ui/imgui_extensions.cpp
@@ -4,11 +4,104 @@
#include "config.hpp"
#include "locales.hpp"
#include "countries.hpp"
-#include "administration.hpp"
#include "tinyfiledialogs.h"
+#include "administration.hpp"
+#include "administration_writer.hpp"
+
+namespace ui {
+ ImFont* fontBold;
+ ImFont* fontBig;
+}
namespace ImGui
{
+ bool CheckboxX(const char* label, bool* v, bool disabled, bool show_loading_indicator_while_disabled)
+ {
+ bool result = false;
+ if (disabled) ImGui::BeginDisabled();
+ if (!disabled || !show_loading_indicator_while_disabled)
+ {
+ result = ImGui::Checkbox(label, v);
+ }
+ else
+ {
+ bool tmp = false;
+ result = ImGui::Checkbox(label, &tmp);
+ if (result) *v = !(*v);
+
+ float radius = 10.0f;
+ ImVec2 p_min = ImGui::GetItemRectMin();
+ ImVec2 p_max = ImGui::GetItemRectMax();
+ ImVec2 center = ImVec2((p_min.x + p_max.x) * 0.5f - radius, (p_min.y + p_max.y) * 0.5f - radius);
+
+ ImGui::SetCursorScreenPos(ImVec2(center.x, center.y));
+
+ const ImVec4 col = ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered);
+ const ImVec4 bg = ImGui::GetStyleColorVec4(ImGuiCol_Button);
+ ImGui::LoadingIndicatorCircle("##loadingAnim", radius, bg, col, 6, 4.0f);
+ }
+
+ if (disabled) ImGui::EndDisabled();
+ return result;
+ }
+
+ static ImVec2 CalcButtonSize(const char* label)
+ {
+ ImGuiStyle& style = ImGui::GetStyle();
+ ImVec2 text_size = ImGui::CalcTextSize(label, nullptr, true);
+ ImVec2 button_size = ImVec2(
+ text_size.x + style.FramePadding.x * 2.0f,
+ text_size.y + style.FramePadding.y * 2.0f
+ );
+ return button_size;
+ }
+
+ bool Button(const char* label, bool block_while_writing_to_disk, bool show_loading_indicator_while_blocked)
+ {
+ if (block_while_writing_to_disk)
+ {
+ if (administration_writer::is_writing())
+ {
+ if (show_loading_indicator_while_blocked) {
+ ImGui::PushID(label);
+ ImGui::BeginDisabled();
+ bool result = ImGui::Button("", CalcButtonSize(label));
+
+ float radius = 10.0f;
+ ImVec2 p_min = ImGui::GetItemRectMin();
+ ImVec2 p_max = ImGui::GetItemRectMax();
+ ImVec2 center = ImVec2((p_min.x + p_max.x) * 0.5f - radius, (p_min.y + p_max.y) * 0.5f - radius);
+
+ ImGui::SetCursorScreenPos(ImVec2(center.x, center.y));
+
+ const ImVec4 col = ImGui::GetStyleColorVec4(ImGuiCol_ButtonHovered);
+ const ImVec4 bg = ImGui::GetStyleColorVec4(ImGuiCol_Button);
+ ImGui::LoadingIndicatorCircle("##loadingAnim", radius, bg, col, 6, 4.0f);
+
+ ImGui::EndDisabled();
+ ImGui::PopID();
+
+ return result;
+ }
+ else
+ {
+ ImGui::BeginDisabled();
+ bool result = ImGui::Button(label);
+ ImGui::EndDisabled();
+ return result;
+ }
+ }
+ else
+ {
+ return ImGui::Button(label);
+ }
+ }
+ else
+ {
+ return ImGui::Button(label);
+ }
+ }
+
void InputTextWithError(const char* text, char* buffer, size_t buf_size, bool has_error)
{
if (has_error) {