feat(shaders_lab): add gl_loader + Windows cross-compile
- cpp/functions/gfx/gl_loader.{h,cpp,md}: mini loader para OpenGL 2.0+
(Linux no-op via GL_GLEXT_PROTOTYPES, Windows wglGetProcAddress)
- Portar gl_shader/gl_framebuffer/fullscreen_quad/shader_canvas al loader
- CMakeLists: WIN32_EXECUTABLE para lanzar sin consola en Windows
- apps/shaders_lab/shaders_lab.exe: binario PE32+ precompilado
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,44 +1,72 @@
|
||||
#include "kpi_card.h"
|
||||
#include "sparkline.h"
|
||||
#include "core/tokens.h"
|
||||
#include <imgui.h>
|
||||
#include <cstdio>
|
||||
|
||||
void kpi_card(const char* label, float value, float delta_percent,
|
||||
const float* history, int history_count,
|
||||
const char* format) {
|
||||
ImGui::BeginGroup();
|
||||
using namespace fn_tokens;
|
||||
|
||||
// Label — small, muted
|
||||
ImGui::TextDisabled("%s", label);
|
||||
// Card container — surface bg, border, rounded, padding.
|
||||
// Mirrors Mantine <Paper withBorder shadow="xs" radius="md" p="md" /> used in
|
||||
// @fn_library/kpi_card.tsx, adapted for ImGui dark theme.
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, colors::surface);
|
||||
ImGui::PushStyleColor(ImGuiCol_Border, colors::border);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, radius::md);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ChildBorderSize, 1.0f);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(spacing::md, spacing::md));
|
||||
|
||||
// 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);
|
||||
// Unique child id per label so multiple cards in the same window don't collide.
|
||||
char child_id[96];
|
||||
std::snprintf(child_id, sizeof(child_id), "##kpi_%s", label);
|
||||
|
||||
// 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
|
||||
float width = ImGui::GetContentRegionAvail().x;
|
||||
if (width < 1.0f) width = 1.0f;
|
||||
|
||||
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::BeginChild(child_id, ImVec2(width, 0),
|
||||
ImGuiChildFlags_Borders | ImGuiChildFlags_AutoResizeY);
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, delta_color);
|
||||
ImGui::Text("%s", delta_buf);
|
||||
// Label — muted (Mantine "dimmed" text)
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, colors::text_muted);
|
||||
ImGui::TextUnformatted(label);
|
||||
ImGui::PopStyleColor();
|
||||
|
||||
// Sparkline — matches delta color
|
||||
if (history != nullptr && history_count > 0) {
|
||||
sparkline(label, history, history_count, delta_color, 120.0f, 24.0f);
|
||||
// Value — scaled up (Mantine fw={700} fontSize=1.875rem)
|
||||
ImGui::SetWindowFontScale(1.8f);
|
||||
char value_buf[64];
|
||||
std::snprintf(value_buf, sizeof(value_buf), format, value);
|
||||
ImGui::TextUnformatted(value_buf);
|
||||
ImGui::SetWindowFontScale(1.0f);
|
||||
|
||||
// Delta badge — only render when meaningful
|
||||
const bool has_delta = delta_percent != 0.0f;
|
||||
const bool has_history = history != nullptr && history_count > 0;
|
||||
|
||||
if (has_delta || has_history) {
|
||||
const bool positive = delta_percent >= 0.0f;
|
||||
const ImVec4 delta_color = positive ? colors::success : colors::error;
|
||||
|
||||
if (has_delta) {
|
||||
char delta_buf[32];
|
||||
if (positive) {
|
||||
std::snprintf(delta_buf, sizeof(delta_buf), "\xe2\x96\xb2 +%.1f%%", delta_percent);
|
||||
} else {
|
||||
std::snprintf(delta_buf, sizeof(delta_buf), "\xe2\x96\xbc %.1f%%", delta_percent);
|
||||
}
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, delta_color);
|
||||
ImGui::TextUnformatted(delta_buf);
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
|
||||
if (has_history) {
|
||||
sparkline(label, history, history_count, delta_color, 120.0f, 24.0f);
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::EndGroup();
|
||||
ImGui::EndChild();
|
||||
|
||||
ImGui::PopStyleVar(3);
|
||||
ImGui::PopStyleColor(2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user