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