Skip to content

Commit ff38ab8

Browse files
committed
UI Optimization
* Added some optimization to the UI so hopefully feels smoother
1 parent 3114ea7 commit ff38ab8

1 file changed

Lines changed: 71 additions & 34 deletions

File tree

UI.lua

Lines changed: 71 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ local FONT_SIZE_MAX = 20
3232
local ROW_HEIGHT = 18
3333
local HEADER_HEIGHT = 18
3434
local PADDING = 6
35+
local BuildModuleStatsCache
36+
local GetModuleStats
3537

3638
local GetWindowLayoutValue
3739
local SetWindowLayoutValue
@@ -1697,6 +1699,7 @@ function MR:RefreshUI()
16971699
if not self.frame or not self.content then return end
16981700

16991701
RecalcLayout()
1702+
self._moduleStatsCache = BuildModuleStatsCache(self)
17001703

17011704
for _, w in ipairs(self.widgets or {}) do
17021705
w:Hide(); w:SetParent(nil)
@@ -1717,9 +1720,12 @@ function MR:RefreshUI()
17171720
for _, mod in ipairs(MR:GetOrderedModules()) do
17181721
local modVisible = not mod.isVisible or mod:isVisible()
17191722
if MR:IsModuleEnabled(mod.key) and modVisible and not MR:IsModuleDetached(mod.key) then
1720-
local totalRows, doneRows, shownRows = self:GetModuleRowStats(mod)
1723+
local stats = GetModuleStats(self, mod)
1724+
local totalRows = stats and stats.totalRows or 0
1725+
local doneRows = stats and stats.doneRows or 0
1726+
local shownRows = stats and stats.shownRows or 0
17211727
if shownRows > 0 then
1722-
local h = self:MeasureSection(mod)
1728+
local h = stats and stats.height or 0
17231729
table.insert(visibleMods, { mod = mod, h = h })
17241730
allTotal = allTotal + shownRows
17251731
allDone = allDone + math.min(doneRows, shownRows)
@@ -1798,7 +1804,8 @@ function MR:RefreshUI()
17981804
local modVisible = not mod.isVisible or mod:isVisible()
17991805
local detached = MR:IsModuleDetached(mod.key)
18001806
local frame = self.detachedFrames[mod.key]
1801-
local _, _, shownRows = self:GetModuleRowStats(mod)
1807+
local stats = GetModuleStats(self, mod)
1808+
local shownRows = stats and stats.shownRows or 0
18021809
if detached and MR:IsModuleEnabled(mod.key) and modVisible and shownRows > 0 then
18031810
frame = self:EnsureDetachedFrame(mod)
18041811
seenDetached[mod.key] = true
@@ -1856,6 +1863,8 @@ function MR:RefreshUI()
18561863
if self.altBoardFrame and self.altBoardFrame:IsShown() and self.RefreshWarbandBoard then
18571864
self:RefreshWarbandBoard()
18581865
end
1866+
1867+
self._moduleStatsCache = nil
18591868
end
18601869

18611870
function MR:IsRowComplete(mod, row, done)
@@ -1865,57 +1874,85 @@ function MR:IsRowComplete(mod, row, done)
18651874
return row.max and not row.noMax and done >= row.max
18661875
end
18671876

1868-
function MR:MeasureSection(mod)
1869-
local isOpen = MR:IsModuleOpen(mod.key)
1870-
local _, _, shownRows = self:GetModuleRowStats(mod)
1871-
if shownRows == 0 then
1872-
return 0
1873-
end
1874-
local h = HEADER_HEIGHT + 1
1875-
if isOpen then
1877+
BuildModuleStatsCache = function(self)
1878+
local cache = {}
1879+
1880+
for _, mod in ipairs(MR:GetOrderedModules()) do
1881+
local hideComplete = MR:IsModuleHideComplete(mod.key)
1882+
local isOpen = MR:IsModuleOpen(mod.key)
1883+
local totalRows, doneRows, shownRows = 0, 0, 0
1884+
local height = HEADER_HEIGHT + 1
1885+
18761886
for _, row in ipairs(mod.rows) do
18771887
local rowVisible = not row.isVisible or row.isVisible()
18781888
if rowVisible and MR:IsRowEnabled(mod.key, row.key) then
1889+
totalRows = totalRows + 1
1890+
18791891
local done = MR:GetProgress(mod.key, row.key)
18801892
local isComplete = self:IsRowComplete(mod, row, done)
1881-
if not (MR:IsModuleHideComplete(mod.key) and isComplete) then
1882-
h = h + ROW_HEIGHT
1893+
if isComplete then
1894+
doneRows = doneRows + 1
1895+
end
1896+
1897+
if not (hideComplete and isComplete) then
1898+
shownRows = shownRows + 1
1899+
if isOpen then
1900+
height = height + ROW_HEIGHT
1901+
end
18831902
end
18841903
end
18851904
end
1905+
1906+
if shownRows == 0 then
1907+
height = 0
1908+
end
1909+
1910+
cache[mod.key] = {
1911+
doneRows = doneRows,
1912+
height = height,
1913+
hideComplete = hideComplete,
1914+
isOpen = isOpen,
1915+
shownRows = shownRows,
1916+
totalRows = totalRows,
1917+
}
18861918
end
1887-
return h
1919+
1920+
return cache
18881921
end
18891922

1890-
function MR:GetModuleRowStats(mod)
1891-
local hideComplete = MR:IsModuleHideComplete(mod.key)
1892-
local totalRows, doneRows, shownRows = 0, 0, 0
1923+
GetModuleStats = function(self, mod)
1924+
local cache = self._moduleStatsCache
1925+
if cache and cache[mod.key] then
1926+
return cache[mod.key]
1927+
end
18931928

1894-
for _, row in ipairs(mod.rows) do
1895-
local rowVisible = not row.isVisible or row.isVisible()
1896-
if rowVisible and MR:IsRowEnabled(mod.key, row.key) then
1897-
totalRows = totalRows + 1
1929+
local fallback = BuildModuleStatsCache(self)
1930+
return fallback[mod.key]
1931+
end
18981932

1899-
local isComplete = self:IsRowComplete(mod, row, MR:GetProgress(mod.key, row.key))
1900-
if isComplete then
1901-
doneRows = doneRows + 1
1902-
end
1903-
if not (hideComplete and isComplete) then
1904-
shownRows = shownRows + 1
1905-
end
1906-
end
1933+
function MR:MeasureSection(mod)
1934+
local stats = GetModuleStats(self, mod)
1935+
return stats and stats.height or 0
1936+
end
1937+
1938+
function MR:GetModuleRowStats(mod)
1939+
local stats = GetModuleStats(self, mod)
1940+
if not stats then
1941+
return 0, 0, 0
19071942
end
19081943

1909-
return totalRows, doneRows, shownRows
1944+
return stats.totalRows, stats.doneRows, stats.shownRows
19101945
end
19111946

19121947
function MR:BuildSection(mod, yOff, xOff, colW, col, parent, widgetBucket, opts)
19131948
parent = parent or self.content
19141949
widgetBucket = widgetBucket or self.widgets
19151950
opts = opts or {}
1916-
local isOpen = MR:IsModuleOpen(mod.key)
1917-
1918-
local secTotal, secDone, shownRows = self:GetModuleRowStats(mod)
1951+
local stats = GetModuleStats(self, mod)
1952+
local isOpen = stats and stats.isOpen
1953+
local secTotal = stats and stats.totalRows or 0
1954+
local secDone = stats and stats.doneRows or 0
1955+
local shownRows = stats and stats.shownRows or 0
19191956
if shownRows == 0 then
19201957
return yOff
19211958
end
@@ -2042,7 +2079,7 @@ function MR:BuildSection(mod, yOff, xOff, colW, col, parent, widgetBucket, opts)
20422079
table.insert(widgetBucket, div)
20432080

20442081
if isOpen then
2045-
local hideComplete = MR:IsModuleHideComplete(mod.key)
2082+
local hideComplete = stats and stats.hideComplete
20462083
for _, row in ipairs(mod.rows) do
20472084
local rowVisible = not row.isVisible or row.isVisible()
20482085
if rowVisible and MR:IsRowEnabled(mod.key, row.key) then

0 commit comments

Comments
 (0)