From ebc012a5db893e271298071882d495f26367f358 Mon Sep 17 00:00:00 2001 From: Egutierrez Date: Wed, 29 Apr 2026 21:32:44 +0200 Subject: [PATCH] fix(primitives_gallery): preserve scroll position when font size changes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cuando se cambia "Size" en Settings la fuente se escala via style.FontSizeBase y el contenido del child "##gallery_content" crece o encoge proporcionalmente. La scroll_y se quedaba en pixeles absolutos, asi que la linea logica visible "se bajaba" al usuario tras el cambio de zoom. Fix: cachear FontSizeBase entre frames y, cuando cambia, escalar scroll_y por el ratio nuevo/viejo. Mantiene la misma linea arriba del viewport — sin saltos. --- cpp/apps/primitives_gallery/main.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cpp/apps/primitives_gallery/main.cpp b/cpp/apps/primitives_gallery/main.cpp index d2c513b0..c831e7d9 100644 --- a/cpp/apps/primitives_gallery/main.cpp +++ b/cpp/apps/primitives_gallery/main.cpp @@ -20,6 +20,7 @@ #include "demo.h" #include "capture.h" +#include #include #include #include @@ -154,6 +155,20 @@ static void render() { ImGui::BeginChild("##gallery_content", ImVec2(0, 0), ImGuiChildFlags_Borders, ImGuiWindowFlags_HorizontalScrollbar); + // Cuando cambia el tamaño de fuente (Settings > Size), el contenido + // del child crece/encoge pero la posicion de scroll en pixeles + // no — efecto: lo visible "se baja". Escalamos scroll_y por el + // ratio de fuentes para mantener la misma linea logica arriba. + { + static float s_prev_font_size = 0.0f; + float cur_font_size = ImGui::GetStyle().FontSizeBase; + if (s_prev_font_size > 0.0f && + std::fabs(s_prev_font_size - cur_font_size) > 0.01f) { + ImGui::SetScrollY(ImGui::GetScrollY() * + (cur_font_size / s_prev_font_size)); + } + s_prev_font_size = cur_font_size; + } const DemoEntry* d = find_demo(g_selected_id); if (d && d->fn) d->fn(); ImGui::EndChild();