diff options
| author | Aldrik Ramaekers <aldrik@mailbox.org> | 2026-01-01 17:20:05 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrik@mailbox.org> | 2026-01-01 17:20:05 +0100 |
| commit | 3088c3e904c1b4d9cb1ea3ba24f851356f6a2ab9 (patch) | |
| tree | 160a3412ff1486f953dc050ded09f5374e8d7fcd /src/ui/imgui_extensions.cpp | |
| parent | a1d639e963eaad1f8d24d47cd004c22052166978 (diff) | |
feedback on buttons that write to disk
Diffstat (limited to 'src/ui/imgui_extensions.cpp')
| -rw-r--r-- | src/ui/imgui_extensions.cpp | 65 |
1 files changed, 61 insertions, 4 deletions
diff --git a/src/ui/imgui_extensions.cpp b/src/ui/imgui_extensions.cpp index 05eeb7b..8673f53 100644 --- a/src/ui/imgui_extensions.cpp +++ b/src/ui/imgui_extensions.cpp @@ -60,12 +60,19 @@ namespace ImGui bool Button(const char* label, bool block_while_writing_to_disk, bool show_loading_indicator_while_blocked) { + ImGui::PushID(label); + + ImGuiID id = ImGui::GetID(label); + static ImGuiID active_id = -1; + static bool show_status = false; + static double status_time; + if (block_while_writing_to_disk) { if (administration_writer::is_writing()) { - if (show_loading_indicator_while_blocked) { - ImGui::PushID(label); + // Only show indicator on activated button. + if (show_loading_indicator_while_blocked && active_id == id) { ImGui::BeginDisabled(); bool result = ImGui::Button("", CalcButtonSize(label)); @@ -82,12 +89,12 @@ namespace ImGui const ImVec4 bg = ImGui::GetStyleColorVec4(ImGuiCol_Button); ImGui::LoadingIndicatorCircle(radius, bg, col, 6, 4.0f); ImGui::EndDisabled(); - ImGui::PopID(); ImGui::SetCursorScreenPos(oldPos); ImGui::SameLine(); ImGui::Dummy(ImVec2(0, 0)); + ImGui::PopID(); return result; } else @@ -95,16 +102,66 @@ namespace ImGui ImGui::BeginDisabled(); bool result = ImGui::Button(label); ImGui::EndDisabled(); + ImGui::PopID(); return result; } } else { - return ImGui::Button(label); + bool result = false; + + if (active_id == id && !show_status) { + show_status = true; + status_time = ImGui::GetTime(); + } + + if (active_id == id && show_status) { + ImGui::BeginDisabled(); + + ImGuiStyle& style = ImGui::GetStyle(); + ImVec2 framePadding = style.FramePadding; + ImVec2 textSize = ImGui::CalcTextSize(label, 0, true); + float padding = framePadding.x; // Adjust based on your design + float buttonWidth = textSize.x + 2 * padding; + + if (administration_writer::last_write_result()) + { + ImGui::PushStyleColor(ImGuiCol_Text, config::colors::COLOR_SUCCESS); + result = ImGui::Button("√", ImVec2(buttonWidth, 0)); + ImGui::PopStyleColor(); + } + else + { + ImGui::PushStyleColor(ImGuiCol_Text, config::colors::COLOR_ERROR); + result = ImGui::Button("X", ImVec2(buttonWidth, 0)); + ImGui::PopStyleColor(); + } + + + ImGui::EndDisabled(); + ImGui::PopID(); + + if (ImGui::GetTime() - status_time > 1.0) { + show_status = false; + active_id = -1; + } + + return result; + } + else { + bool result = ImGui::Button(label); + if (result) { + active_id = id; + show_status = false; + } + ImGui::PopID(); + return result; + } } } else { + ImGui::PopID(); return ImGui::Button(label); } } |
