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 852322a708
commit 750b7abcd5
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();
+16
View File
@@ -113,8 +113,24 @@ struct AppConfig {
// Callbacks de layouts persistentes. Si layouts_cb != nullptr, run_app
// llama fn_ui::app_menubar(panels, panel_count, layouts_cb) cada frame.
// Si layouts_cb == nullptr y auto_layouts == true (default), run_app abre
// un fn_ui::LayoutStorage por defecto sobre `<local_dir>/<auto_layouts_db>`,
// genera unos LayoutCallbacks estandar (save/load/list/delete/reset),
// los aplica al inicio de cada frame y los cierra al salir. Asi cualquier
// app obtiene el menu Layouts gratis sin tocar codigo.
fn_ui::LayoutCallbacks* layouts_cb = nullptr;
// Auto-wiring del menu Layouts cuando layouts_cb == nullptr.
// - true (default): run_app crea LayoutStorage interno con SQLite.
// - false: no se crea storage. Util si la app no quiere persistencia
// (ej. demo headless, capture mode).
bool auto_layouts = true;
// Nombre del archivo SQLite (relativo a `<exe_dir>/local_files/`) usado
// por el layout storage por defecto. Solo se consulta si layouts_cb es
// nullptr y auto_layouts es true. Default "layouts.db".
const char* auto_layouts_db = "layouts.db";
// Items extra dentro del menu "View", al final tras los toggles de
// paneles. Si view_extras != nullptr, run_app lo pasa a app_menubar.
// El callback se invoca dentro de un BeginMenu("View") ya abierto: