diff options
| author | Vaxry <vaxry@vaxry.net> | 2026-04-07 14:09:06 +0100 |
|---|---|---|
| committer | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2026-04-07 12:07:36 -0400 |
| commit | 0448e707fce798d6864320ef629ae681845bde26 (patch) | |
| tree | bea6ed92bcb2abef80bef756c60ca167598104ea /src/desktop/view/Popup.cpp | |
| parent | 8a97b11b22422bcb6907a66010388856317c7ff5 (diff) | |
desktop/popup: cache tree count
Diffstat (limited to 'src/desktop/view/Popup.cpp')
| -rw-r--r-- | src/desktop/view/Popup.cpp | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/desktop/view/Popup.cpp b/src/desktop/view/Popup.cpp index cf0c981b..7791e921 100644 --- a/src/desktop/view/Popup.cpp +++ b/src/desktop/view/Popup.cpp @@ -418,7 +418,8 @@ void CPopup::invalidateTreeExtentsCache() { if (!head) return; - head->m_treeExtentsCacheDirty = true; + head->m_treeExtentsCacheDirty = true; + head->m_treePopupCountCacheDirty = true; } void CPopup::recheckTree() { @@ -561,6 +562,37 @@ const CBox& CPopup::popupTreeExtents() const { return head->m_cachedTreeExtents; } +int CPopup::popupTreeCount() const { + auto head = popupHead(); + if (!head) + return 0; + + if (!head->m_treePopupCountCacheDirty) + return head->m_cachedTreePopupCount; + + head->m_treePopupCountCacheDirty = false; + head->m_cachedTreePopupCount = 0; + + std::vector<SP<CPopup>> popups; + popups.emplace_back(head); + + for (size_t i = 0; i < popups.size(); ++i) { + const auto& popup = popups[i]; + if (!popup) + continue; + + for (const auto& c : popup->m_children) { + if (!c) + continue; + + popups.emplace_back(c); + head->m_cachedTreePopupCount++; + } + } + + return head->m_cachedTreePopupCount; +} + SP<CPopup> CPopup::at(const Vector2D& globalCoords, bool allowsInput) { thread_local std::vector<SP<CPopup>> popups; popups.clear(); |
