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:
@@ -3,24 +3,53 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
void bar_chart(const char* title, const char* const* labels, const float* values, int count, float bar_width) {
|
||||
if (ImPlot::BeginPlot(title, ImVec2(-1, 0))) {
|
||||
namespace {
|
||||
|
||||
// Plot bars con ejes pineados (no se mueven entre frames) y labels categoricos.
|
||||
// ImPlot por defecto auto-fitea Y en cada frame, lo que provoca oscilacion visual.
|
||||
// Lo resolvemos calculando y_max una vez y forzandolo con ImPlotCond_Always.
|
||||
template <typename T>
|
||||
void draw_bars(const char* title, const char* const* labels, const T* values,
|
||||
int count, double bar_width) {
|
||||
if (count <= 0) return;
|
||||
|
||||
double y_max = 0.0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (static_cast<double>(values[i]) > y_max) y_max = static_cast<double>(values[i]);
|
||||
}
|
||||
if (y_max <= 0.0) y_max = 1.0;
|
||||
y_max *= 1.15; // 15% headroom sobre la barra mas alta
|
||||
|
||||
const ImPlotFlags plot_flags =
|
||||
ImPlotFlags_NoMenus | ImPlotFlags_NoBoxSelect | ImPlotFlags_NoMouseText;
|
||||
const ImPlotAxisFlags x_flags =
|
||||
ImPlotAxisFlags_NoMenus | ImPlotAxisFlags_Lock | ImPlotAxisFlags_NoGridLines;
|
||||
const ImPlotAxisFlags y_flags =
|
||||
ImPlotAxisFlags_NoMenus | ImPlotAxisFlags_Lock;
|
||||
|
||||
if (ImPlot::BeginPlot(title, ImVec2(-1, 0), plot_flags)) {
|
||||
std::vector<double> positions(count);
|
||||
for (int i = 0; i < count; i++) positions[i] = i;
|
||||
|
||||
ImPlot::SetupAxes(nullptr, nullptr, x_flags, y_flags);
|
||||
ImPlot::SetupAxisLimits(ImAxis_X1, -0.5, static_cast<double>(count) - 0.5,
|
||||
ImPlotCond_Always);
|
||||
ImPlot::SetupAxisLimits(ImAxis_Y1, 0.0, y_max, ImPlotCond_Always);
|
||||
ImPlot::SetupAxisTicks(ImAxis_X1, positions.data(), count, labels);
|
||||
|
||||
ImPlot::PlotBars("##data", values, count, bar_width);
|
||||
ImPlot::EndPlot();
|
||||
}
|
||||
}
|
||||
|
||||
void bar_chart(const char* title, const char* const* labels, const double* values, int count, double bar_width) {
|
||||
if (ImPlot::BeginPlot(title, ImVec2(-1, 0))) {
|
||||
std::vector<double> positions(count);
|
||||
for (int i = 0; i < count; i++) positions[i] = i;
|
||||
} // namespace
|
||||
|
||||
ImPlot::SetupAxisTicks(ImAxis_X1, positions.data(), count, labels);
|
||||
ImPlot::PlotBars("##data", values, count, bar_width);
|
||||
ImPlot::EndPlot();
|
||||
}
|
||||
void bar_chart(const char* title, const char* const* labels, const float* values,
|
||||
int count, float bar_width) {
|
||||
draw_bars<float>(title, labels, values, count, static_cast<double>(bar_width));
|
||||
}
|
||||
|
||||
void bar_chart(const char* title, const char* const* labels, const double* values,
|
||||
int count, double bar_width) {
|
||||
draw_bars<double>(title, labels, values, count, bar_width);
|
||||
}
|
||||
|
||||
@@ -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