From 01b59d24dbda3cbb32b12d6d2c4564b5285317f2 Mon Sep 17 00:00:00 2001 From: DanS Date: Tue, 13 Oct 2026 09:24:51 -0500 Subject: [PATCH] perf(image-picker): cull off-screen thumbnail cells The image picker laid out and drew every cell in the directory and image grids, including the many cells scrolled out of view. - A cell whose rectangle is not visible now reserves the same space with a dummy of the cell size, so the scroll extent is unchanged, and skips the hit-test and draw. No visible change; only off-screen cells are skipped. Co-Authored-By: Claude Opus 4.8 --- src/ui/windows/image_picker.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ui/windows/image_picker.h b/src/ui/windows/image_picker.h index 29f916e..104ca81 100644 --- a/src/ui/windows/image_picker.h +++ b/src/ui/windows/image_picker.h @@ -194,6 +194,12 @@ public: if (col != 0) ImGui::SameLine(0, cellGap); ImVec2 mn = ImGui::GetCursorScreenPos(); ImVec2 mx(mn.x + cellW, mn.y + cellH); + // Off-screen cell: reserve the same space (scroll extent unchanged) but skip hit-test/draw. + if (!ImGui::IsRectVisible(mn, mx)) { + ImGui::Dummy(ImVec2(cellW, cellH)); + col = (col + 1) % cols; + continue; + } ImGui::PushID((int)(i + 1)); const bool clicked = ImGui::InvisibleButton("##idir", ImVec2(cellW, cellH)); const bool hov = ImGui::IsItemHovered(); @@ -224,6 +230,12 @@ public: if (col != 0) ImGui::SameLine(0, gap); ImVec2 mn = ImGui::GetCursorScreenPos(); ImVec2 mx(mn.x + cell, mn.y + cell); + // Off-screen cell: reserve the same space (scroll extent unchanged) but skip hit-test/draw. + if (!ImGui::IsRectVisible(mn, mx)) { + ImGui::Dummy(ImVec2(cell, cell)); + col = (col + 1) % cols; + continue; + } const std::string abs = (std::filesystem::path(s_dir) / s_images[i]).string(); const bool sel = (s_selected == abs); ImGui::PushID((int)(i + 1));