Let scrollbar only scroll to whole row numbers

This commit is contained in:
Max
2026-06-01 05:19:36 +02:00
parent 0a9380cd22
commit 991bc5eb3e
+7 -3
View File
@@ -470,9 +470,13 @@ local function runScrollableGrid(options)
targetScrollRow = tonumber(initialTargetRow) or currentScrollRow targetScrollRow = tonumber(initialTargetRow) or currentScrollRow
end end
local function snapScrollRow(row)
return math.floor((tonumber(row) or 0) + 0.5)
end
local function persistScrollState() local function persistScrollState()
if options.setScrollState then if options.setScrollState then
options.setScrollState(currentScrollRow, targetScrollRow) options.setScrollState(snapScrollRow(targetScrollRow), snapScrollRow(targetScrollRow))
end end
end end
@@ -503,7 +507,7 @@ local function runScrollableGrid(options)
end end
local function scrollTo(row) local function scrollTo(row)
local clampedRow = clampScrollRow(row) local clampedRow = clampScrollRow(snapScrollRow(row))
if clampedRow ~= targetScrollRow then if clampedRow ~= targetScrollRow then
targetScrollRow = clampedRow targetScrollRow = clampedRow
@@ -520,7 +524,7 @@ local function runScrollableGrid(options)
totalRows = math.ceil(#entries / columns) totalRows = math.ceil(#entries / columns)
maxScrollRow = math.max(0, totalRows - rowsPerView) maxScrollRow = math.max(0, totalRows - rowsPerView)
currentScrollRow = clampScrollRow(currentScrollRow) currentScrollRow = clampScrollRow(currentScrollRow)
targetScrollRow = clampScrollRow(targetScrollRow) targetScrollRow = clampScrollRow(snapScrollRow(targetScrollRow))
persistScrollState() persistScrollState()
local firstVisibleRow = math.floor(currentScrollRow) local firstVisibleRow = math.floor(currentScrollRow)