Remember overview scroll position
This commit is contained in:
@@ -23,6 +23,8 @@ local fallbackIcon = false
|
||||
local backButton = false
|
||||
local scrollUpButton = false
|
||||
local scrollDownButton = false
|
||||
local overviewScrollCurrentRow = 0
|
||||
local overviewScrollTargetRow = 0
|
||||
local drawOverview
|
||||
|
||||
local function ensureChainsLoaded()
|
||||
@@ -462,6 +464,18 @@ local function runScrollableGrid(options)
|
||||
local scrollbarTrackPixelY = cellToPixelY(scrollbarTrackY)
|
||||
local scrollbarTrackPixelHeight = math.max(0, scrollbarTrackHeight * 3)
|
||||
|
||||
if options.getInitialScrollState then
|
||||
local initialCurrentRow, initialTargetRow = options.getInitialScrollState()
|
||||
currentScrollRow = tonumber(initialCurrentRow) or 0
|
||||
targetScrollRow = tonumber(initialTargetRow) or currentScrollRow
|
||||
end
|
||||
|
||||
local function persistScrollState()
|
||||
if options.setScrollState then
|
||||
options.setScrollState(currentScrollRow, targetScrollRow)
|
||||
end
|
||||
end
|
||||
|
||||
local function clampScrollRow(row)
|
||||
return math.max(0, math.min(maxScrollRow, row))
|
||||
end
|
||||
@@ -493,6 +507,7 @@ local function runScrollableGrid(options)
|
||||
|
||||
if clampedRow ~= targetScrollRow then
|
||||
targetScrollRow = clampedRow
|
||||
persistScrollState()
|
||||
scheduleAnimation()
|
||||
end
|
||||
end
|
||||
@@ -506,6 +521,7 @@ local function runScrollableGrid(options)
|
||||
maxScrollRow = math.max(0, totalRows - rowsPerView)
|
||||
currentScrollRow = clampScrollRow(currentScrollRow)
|
||||
targetScrollRow = clampScrollRow(targetScrollRow)
|
||||
persistScrollState()
|
||||
|
||||
local firstVisibleRow = math.floor(currentScrollRow)
|
||||
local rowOffsetPixels = -math.floor((currentScrollRow - firstVisibleRow) * rowStepPixels + 0.5)
|
||||
@@ -591,6 +607,7 @@ local function runScrollableGrid(options)
|
||||
end
|
||||
end
|
||||
|
||||
persistScrollState()
|
||||
renderGrid()
|
||||
elseif event == "monitor_touch" and p1 == monName then
|
||||
if options.handleChromeTouch and options.handleChromeTouch(x, y) then
|
||||
@@ -681,6 +698,13 @@ drawOverview = function()
|
||||
|
||||
runScrollableGrid({
|
||||
refreshSeconds = 30,
|
||||
getInitialScrollState = function()
|
||||
return overviewScrollCurrentRow, overviewScrollTargetRow
|
||||
end,
|
||||
setScrollState = function(currentRow, targetRow)
|
||||
overviewScrollCurrentRow = currentRow
|
||||
overviewScrollTargetRow = targetRow
|
||||
end,
|
||||
getEntriesAndCounts = function()
|
||||
local itemCounts = getMeItemCounts(items)
|
||||
local sortedItemIds = {}
|
||||
|
||||
Reference in New Issue
Block a user