chore: auto-commit (97 archivos)

- .claude/CLAUDE.md
- .claude/agents/fn-recopilador/SKILL.md
- .claude/rules/INDEX.md
- .claude/rules/cpp_apps.md
- bash/functions/infra/build_cpp_windows.sh
- cpp/CMakeLists.txt
- cpp/PATTERNS.md
- cpp/framework/app_base.cpp
- cpp/framework/app_base.h
- dev/issues/README.md
- ...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-09 18:11:24 +02:00
parent 4b9698b1b7
commit aca2348a20
99 changed files with 7879 additions and 73 deletions
+80 -5
View File
@@ -13,6 +13,7 @@
#include "core/fps_overlay.h"
#include "core/logger.h"
#include "core/log_window.h"
#include "core/layout_storage.h"
#include "gfx/gl_loader.h"
#include <GLFW/glfw3.h>
@@ -203,6 +204,27 @@ int run_app(AppConfig config, std::function<void()> render_fn) {
glfwMakeContextCurrent(window);
glfwSwapInterval(config.vsync ? 1 : 0);
// Anti-jitter: when the OS moves/resizes the window externally (Windows
// tools like AltSnap, tiling WMs, snap-assist), ImGui's viewport pos can
// lag one frame and `UpdatePlatformWindows` reapplies the stale value via
// glfwSetWindowPos, fighting the OS and producing visible jitter.
// Updating the viewport struct directly from the GLFW callback closes the
// loop in the same tick — no stale Pos can ever reach the platform sync.
// ImGui_ImplGlfw_InitForOpenGL does NOT install pos/size callbacks, so we
// can install ours without breaking the backend's own callback chain.
glfwSetWindowPosCallback(window, [](GLFWwindow* w, int x, int y) {
if (ImGui::GetCurrentContext() == nullptr) return;
if (ImGuiViewport* vp = ImGui::FindViewportByPlatformHandle(w)) {
vp->Pos = ImVec2((float)x, (float)y);
}
});
glfwSetWindowSizeCallback(window, [](GLFWwindow* w, int cx, int cy) {
if (ImGui::GetCurrentContext() == nullptr) return;
if (ImGuiViewport* vp = ImGui::FindViewportByPlatformHandle(w)) {
vp->Size = ImVec2((float)cx, (float)cy);
}
});
// Carga punteros a funciones GL >= 2.0 si la app lo pide. En Linux es
// no-op; en Windows usa wglGetProcAddress (requiere ctx GL activo).
if (config.init_gl_loader) {
@@ -241,6 +263,25 @@ int run_app(AppConfig config, std::function<void()> render_fn) {
// fuentes. Si no existe el .ini, los defaults se aplican.
fn_ui::settings_load();
// Auto-wiring del menu Layouts: si la app no proporciono layouts_cb y no
// ha desactivado auto_layouts, abrimos un LayoutStorage por defecto con
// SQLite en `<local_dir>/<auto_layouts_db>` y generamos los callbacks
// estandar (list/save/apply/delete/reset). Asi toda app C++ obtiene el
// menu Layouts gratis sin codigo.
fn_ui::LayoutStorage* auto_layouts_storage = nullptr;
fn_ui::LayoutCallbacks auto_layouts_cb;
if (config.layouts_cb == nullptr && config.auto_layouts) {
const char* db_name = (config.auto_layouts_db && *config.auto_layouts_db)
? config.auto_layouts_db : "layouts.db";
auto_layouts_storage = fn_ui::layout_storage_open(local_path(db_name));
if (auto_layouts_storage) {
fn_ui::layout_storage_make_callbacks(auto_layouts_storage, auto_layouts_cb);
config.layouts_cb = &auto_layouts_cb;
} else {
fn_log::log_warn("auto_layouts: layout_storage_open fallo (%s)", db_name);
}
}
// Registra info de la ventana About si la app la proveyo en AppConfig.
if (config.about.name != nullptr) {
fn_ui::about_window_set_info(
@@ -294,6 +335,25 @@ int run_app(AppConfig config, std::function<void()> render_fn) {
continue;
}
// Anti-jitter pass 2: covers secondary viewport windows that the
// backend creates dynamically (panels dragged outside the main).
// Sync each viewport's Pos/Size to the OS-reported state BEFORE
// NewFrame, so ImGui logic this tick already sees the up-to-date
// values and UpdatePlatformWindows can't stomp them with stale data.
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
ImGuiPlatformIO& pio = ImGui::GetPlatformIO();
for (int i = 0; i < pio.Viewports.Size; ++i) {
ImGuiViewport* vp = pio.Viewports[i];
if (!vp || !vp->PlatformHandle) continue;
GLFWwindow* gw = (GLFWwindow*)vp->PlatformHandle;
int x = 0, y = 0, cx = 0, cy = 0;
glfwGetWindowPos(gw, &x, &y);
glfwGetWindowSize(gw, &cx, &cy);
vp->Pos = ImVec2((float)x, (float)y);
vp->Size = ImVec2((float)cx, (float)cy);
}
}
// Tamaño de fuente: aplica via style.FontSizeBase cada frame. Cambios
// se ven al instante (ImGui 1.92+ escala el atlas dinamicamente, no
// hace falta rebuild).
@@ -313,11 +373,20 @@ int run_app(AppConfig config, std::function<void()> render_fn) {
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
// Menubar canonica (View / Layouts / Settings / About) si la app la
// configuro en AppConfig. Se renderiza ANTES del render_fn para que
// el render_fn pueda hacer DockSpaceOverViewport debajo.
if (config.panels != nullptr || config.layouts_cb != nullptr ||
(bool)config.view_extras) {
// Si auto_layouts esta gestionando el storage, aplica el layout
// pendiente ANTES de que el render_fn cree ventanas. Si la app gestiona
// su propio storage, debe llamar layout_storage_apply_pending ella misma
// dentro de render_fn (patron que ya usan shaders_lab y graph_explorer).
if (auto_layouts_storage) {
std::string applied = fn_ui::layout_storage_apply_pending(auto_layouts_storage);
if (!applied.empty()) auto_layouts_cb.active_name = applied;
}
// Menubar canonica (View / Layouts / Settings / About) — siempre se
// renderiza para que Settings/Logs/About esten disponibles aunque la
// app no declare panels/layouts/view_extras propios. Se dibuja ANTES
// del render_fn para que pueda hacer DockSpaceOverViewport debajo.
{
// Adapter: std::function<bool()> -> ViewMenuExtrasFn(void*).
fn_ui::ViewMenuExtrasFn extras_fn = nullptr;
void* extras_user = nullptr;
@@ -380,6 +449,12 @@ int run_app(AppConfig config, std::function<void()> render_fn) {
fn_log::logger_close();
}
// Cierra el storage de layouts auto-creado, si lo hay.
if (auto_layouts_storage) {
fn_ui::layout_storage_close(auto_layouts_storage);
auto_layouts_storage = nullptr;
}
// Cleanup
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();