diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-10-04 18:36:31 +0200 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2025-10-04 18:36:31 +0200 |
| commit | cd827834f9ee329c27b82d987f0d1d48a854a954 (patch) | |
| tree | 3f2b63cc88f7d01ac6c55ff6c8cd5ff26dae55b5 /src/ui/helpers.cpp | |
| parent | 83cbf0e4a142ab2c57fd4fdfc056517b7149828b (diff) | |
namespace importer
Diffstat (limited to 'src/ui/helpers.cpp')
| -rw-r--r-- | src/ui/helpers.cpp | 125 |
1 files changed, 65 insertions, 60 deletions
diff --git a/src/ui/helpers.cpp b/src/ui/helpers.cpp index 19eeee3..476e780 100644 --- a/src/ui/helpers.cpp +++ b/src/ui/helpers.cpp @@ -14,82 +14,87 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include <tinyfiledialogs.h> - #include "ui.hpp" #include "imgui.h" -#include "locales.hpp" #include "strops.hpp" -ImFont* fontBold; -ImFont* fontBig; +#define STATUS_DURATION 4.0f +#define STATUS_FLASH_INTERVAL 0.1f +#define STATUS_MAX_FLASHES 2 + +namespace ui { + + ImFont* fontBold; + ImFont* fontBig; + + static status current_status; + + void ui::draw_status() + { + float region_width = ImGui::GetContentRegionAvail().x; + float text_width = ImGui::CalcTextSize(current_status.text).x; + + if (current_status.loading) + { + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + region_width - text_width - 20.0f); + ImGui::Text("%c", "|/-\\"[(int)(ImGui::GetTime() / 0.1f) & 3]); + return; + } + + 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(); + } -static ui_status current_status; + ImGuiIO& io = ImGui::GetIO(); + current_status.time += io.DeltaTime; -void ui_draw_status() -{ - float region_width = ImGui::GetContentRegionAvail().x; - float text_width = ImGui::CalcTextSize(current_status.text).x; - - if (current_status.loading) + 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; + } + } + + static void set_status_ex(const char* txt, int color) { - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + region_width - text_width - 20.0f); - ImGui::Text("%c", "|/-\\"[(int)(ImGui::GetTime() / 0.1f) & 3]); - return; + current_status.flash_count = 0; + current_status.visible = true; + current_status.time = 0.0f; + current_status.color = color; + current_status.loading = false; + strops::copy(current_status.text, txt, STATUS_TEXT_LEN); } - if (current_status.visible) + void ui::set_status_error(const char* txt) { - ImGui::SetCursorPosX(ImGui::GetCursorPosX() + region_width - text_width); - ImGui::PushStyleColor(ImGuiCol_Text, current_status.color); - ImGui::TextUnformatted(current_status.text); - ImGui::PopStyleColor(); + set_status_ex(txt, config::colors::COLOR_ERROR); } - ImGuiIO& io = ImGui::GetIO(); - current_status.time += io.DeltaTime; + void ui::set_status(const char* txt) + { + set_status_ex(txt, config::colors::COLOR_DEFAULT); + } - if (current_status.time >= STATUS_FLASH_INTERVAL && current_status.flash_count < STATUS_MAX_FLASHES) + void ui::set_status_loading(bool loading) { - current_status.visible = !current_status.visible; - if (current_status.visible) current_status.flash_count++; + current_status.visible = true; current_status.time = 0.0f; + current_status.loading = loading; } - if (current_status.time >= STATUS_DURATION) + status ui::get_status() { - current_status.text[0] = 0; + return current_status; } -} - -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; - current_status.loading = false; - 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); -} - -void ui_set_status_loading(bool loading) -{ - current_status.visible = true; - current_status.time = 0.0f; - current_status.loading = loading; -} - -ui_status ui_get_status() -{ - return current_status; -} + +}
\ No newline at end of file |
