From ea776c20e09b9189eefc2b816be9e50cc69c3aa0 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Fri, 3 Apr 2026 18:14:49 +1100 Subject: [PATCH] fix: lazy list view spacing + debounce relayout --- .../src/Caelestia/Components/lazylistview.cpp | 18 +++++++++++++----- .../src/Caelestia/Components/lazylistview.hpp | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/plugin/src/Caelestia/Components/lazylistview.cpp b/plugin/src/Caelestia/Components/lazylistview.cpp index 88703a7f..b8c37976 100644 --- a/plugin/src/Caelestia/Components/lazylistview.cpp +++ b/plugin/src/Caelestia/Components/lazylistview.cpp @@ -422,13 +422,15 @@ void LazyListView::relayout() { qreal y = 0; bool hasLayoutItem = false; for (auto& record : m_layout) { - record.targetY = y; const qreal layoutH = record.heightKnown ? record.height : effectiveEstimatedHeight(); if (layoutH > 0) { if (hasLayoutItem) y += m_spacing; hasLayoutItem = true; + record.targetY = y; y += layoutH; + } else { + record.targetY = y; } } @@ -653,10 +655,16 @@ LazyListView::DelegateEntry LazyListView::createDelegate(int modelIndex) { if (wasKnown) untrackHeight(oldH); trackHeight(h); - // Relayout immediately so layoutHeight/contentHeight update - // synchronously for parent bindings, then polish for delegate sync. - relayout(); - polish(); + // Batch relayout: multiple height changes in the same event loop + // iteration are coalesced into a single relayout + polish. + if (!m_relayoutPending) { + m_relayoutPending = true; + QTimer::singleShot(0, this, [this] { + m_relayoutPending = false; + relayout(); + polish(); + }); + } } return; } diff --git a/plugin/src/Caelestia/Components/lazylistview.hpp b/plugin/src/Caelestia/Components/lazylistview.hpp index f3f92208..7147169c 100644 --- a/plugin/src/Caelestia/Components/lazylistview.hpp +++ b/plugin/src/Caelestia/Components/lazylistview.hpp @@ -281,6 +281,7 @@ private: int m_activeAnimations = 0; bool m_componentComplete = false; + bool m_relayoutPending = false; QSet m_pendingAddAnimations; QList m_modelConnections;