Hello,
I have the following definition in a lua file for creating an inventory list:
local listview = playdate.ui.gridview.new(0, 24)
listview:setCellPadding(4, 4, 4, 4)
function listview:drawCell(section, row, column, selected, x, y, width, height)
if selected and inventoryUiWindow.currentMenu == MENU_INVENTORY then
gfx.setColor(gfx.kColorBlack)
gfx.fillRoundRect(x, y, width, height, 4)
gfx.setImageDrawMode(gfx.kDrawModeFillWhite)
else
gfx.setImageDrawMode(gfx.kDrawModeCopy)
end
gfx.setFont(font_getBoldFont())
gfx.drawTextInRect(inventory[row].name, x + 24, y + 8, width, height, nil, "...", kTextAlignment.left)
if inventory[row].isNew then
gfx.drawTextInRect('New', x, y + 8, width - 5, height, nil, "...", kTextAlignment.right)
end
local itemImage = inventory[row].animation:image()
itemImage:draw(x, y + 1)
end
This listview is then set into a sprite that I've defined as the inventory window. Said sprite will reference the list view in its draw method, and call drawInRect. Everything seems to work fine, it scrolls up and down with the dpad. However when i append a new item, and im scrolled to the bottom, it doesnt scroll down immediately on pressing the d pad. It will select the new item without scrolling, and then if i press the D pad again, the scroll position changes. The selected item is initially kept out of view.
What's interesting is, this only happens when i use timers to show the inventory window. If i get rid of the timers, this bug does not occur:
function window_openWindow(windowSprite, callback)
local timer = playdate.timer.new(300, 40, windowSprite.MAX_HEIGHT, playdate.easingFunctions.outCubic)
windowSprite:setSize(windowSprite.width, 40)
windowSprite:add()
timer.updateCallback = function(timer)
windowSprite:setSize(windowSprite.width, timer.value)
end
timer.timerEndedCallback = function(timer)
windowSprite:setSize(windowSprite.width, timer.value)
timer = nil
if callback ~= nil then
callback()
end
end
end
The callback() in this case is defined as so:
inventoryUiWindow = InventoryWindow()
window_openWindow(inventoryUiWindow, function()
inventoryUiWindow:setListView(listview)
end)
Where setListView does the following:
function InventoryWindow:setListView(listview)
self.listview = listview
self:markDirty()
self.selectedItem = listview:getSelectedRow()
end
So it does mark the area as needing redrawing.
Here is a gif of the issue occurring: