summaryrefslogtreecommitdiff
path: root/src/ui/helpers.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/helpers.cpp')
-rw-r--r--src/ui/helpers.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/ui/helpers.cpp b/src/ui/helpers.cpp
index 6ca1bd2..c15528e 100644
--- a/src/ui/helpers.cpp
+++ b/src/ui/helpers.cpp
@@ -1,8 +1,66 @@
+#include <tinyfiledialogs.h>
+
#include "ui.hpp"
#include "imgui.h"
#include "locales.hpp"
#include "strops.hpp"
+static ui_status current_status;
+
+void ui_draw_status()
+{
+ float region_width = ImGui::GetContentRegionAvail().x;
+ float text_width = ImGui::CalcTextSize(current_status.text).x;
+
+ // Move cursor so that the text ends at the right edge
+ if (current_status.visible)
+ {
+ ImGui::SetCursorPosX(ImGui::GetCursorPosX() + region_width - text_width);
+ ImGui::PushStyleColor(ImGuiCol_Text, current_status.color);
+ ImGui::TextUnformatted(current_status.text);
+ ImGui::PopStyleColor();
+ }
+
+ ImGuiIO& io = ImGui::GetIO();
+ current_status.time += io.DeltaTime;
+
+ if (current_status.time >= STATUS_FLASH_INTERVAL && current_status.flash_count < STATUS_MAX_FLASHES)
+ {
+ current_status.visible = !current_status.visible;
+ if (current_status.visible) current_status.flash_count++;
+ current_status.time = 0.0f;
+ }
+
+ if (current_status.time >= STATUS_DURATION)
+ {
+ current_status.text[0] = 0;
+ }
+}
+
+void ui_set_status_ex(const char* txt, int color)
+{
+ current_status.flash_count = 0;
+ current_status.visible = true;
+ current_status.time = 0.0f;
+ current_status.color = color;
+ strops_copy(current_status.text, txt, STATUS_TEXT_LEN);
+}
+
+void ui_set_status_error(const char* txt)
+{
+ ui_set_status_ex(txt, COLOR_ERROR);
+}
+
+void ui_set_status(const char* txt)
+{
+ ui_set_status_ex(txt, COLOR_DEFAULT);
+}
+
+ui_status ui_get_status()
+{
+ return current_status;
+}
+
void ui_helper_draw_required_tag()
{
ImDrawList* draw_list = ImGui::GetWindowDrawList();