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 <noreply@anthropic.com>
This commit is contained in:
2026-10-13 09:24:51 -05:00
co-authored by Claude Opus 4.8
parent 3ca7a5c90e
commit 01b59d24db
+12
View File
@@ -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));