I just ran into the same issue, and ended up doing this:
local pd <const> = playdate
local gfx <const> = pd.graphics
class('ItemListView').extends()
function ItemListView:init(cellWidth, cellHeight, options)
ItemListView.super.init(self)
self.options = options
self._gridView = playdate.ui.gridview.new(cellWidth, cellHeight)
-- self.options = options
self._gridView:setNumberOfRows(#options)
self._gridView:setCellPadding(0, 0, 13, 10)
self._gridView:setContentInset(24, 24, 13, 11)
self.font = gfx.getSystemFont()
local listViewSelf = self
function self._gridView:drawCell(section, row, column, selected, x, y, width, height)
if selected then
gfx.setColor(gfx.kColorBlack)
gfx.fillRoundRect(x, y, width, 20, 4)
gfx.setImageDrawMode(gfx.kDrawModeFillWhite)
else
gfx.setImageDrawMode(gfx.kDrawModeCopy)
end
gfx.setFont(listViewSelf.font)
gfx.drawTextInRect(listViewSelf.options[row], x, y+6, width, height+2, nil, "...", kTextAlignment.center)
end
end
function ItemListView:selectNextRow(wrapSelection, scrollToSelection, animate)
self._gridView:selectNextRow(wrapSelection, scrollToSelection, animate)
end
function ItemListView:selectPreviousRow(wrapSelection, scrollToSelection, animate)
self._gridView:selectPreviousRow(wrapSelection, scrollToSelection, animate)
end
function ItemListView:drawInRect(x, y, w, h)
self._gridView:drawInRect(x, y, w, h)
end
-- Elsewhere:
local itemListView = ItemListView(40, 20, { 'one', 'two', 'three', 'four', 'five' })
I can't say I'm happy about it, but I haven't figured out a better way to encapsulate this.