#include "kpi_card.h" #include "sparkline.h" #include #include void kpi_card(const char* label, float value, float delta_percent, const float* history, int history_count, const char* format) { ImGui::BeginGroup(); // Label — small, muted ImGui::TextDisabled("%s", label); // Value — scaled up font ImGui::SetWindowFontScale(1.8f); char value_buf[64]; snprintf(value_buf, sizeof(value_buf), format, value); ImGui::Text("%s", value_buf); ImGui::SetWindowFontScale(1.0f); // Delta badge — green up arrow / red down arrow const bool positive = delta_percent >= 0.0f; const ImVec4 delta_color = positive ? ImVec4(0.20f, 0.80f, 0.35f, 1.0f) // green : ImVec4(0.90f, 0.25f, 0.25f, 1.0f); // red char delta_buf[32]; if (positive) { snprintf(delta_buf, sizeof(delta_buf), "\xe2\x96\xb2 +%.1f%%", delta_percent); } else { snprintf(delta_buf, sizeof(delta_buf), "\xe2\x96\xbc %.1f%%", delta_percent); } ImGui::PushStyleColor(ImGuiCol_Text, delta_color); ImGui::Text("%s", delta_buf); ImGui::PopStyleColor(); // Sparkline — matches delta color if (history != nullptr && history_count > 0) { sparkline(label, history, history_count, delta_color, 120.0f, 24.0f); } ImGui::EndGroup(); }