For me, it was a combination of a few different things (including being an intermediate programmer...), but some things to note for anybody who lands here in the future:
- I was using a gridview with only one cell, and it turns out that
:setNumberOfRows()
needs to be set explicitly (to 1 in my case), or the drawCell
function won't run
- I didn't fully understand how scroll updating works; it mentions in the docs for drawInRect that this needs to be explicitly run in an update call, but I guess I didn't take that seriously enough and had some code doing something slightly different inside of a draw call instead
- using printTable on the gridview was incredibly helpful in the debugging process, and poking around in the gridview.lua file also helped get me to the solution eventually
yay learning!
If anyone has other ways they have approached a scrolling text box, feel free to share.
Code portions included below, note that it's used inside of an object subclass:
somewhere in card:init()
gfx.setFont(infoFont)
self.text = gfx.getLocalizedText(text, systemLanguage)
self.textWidth, self.textHeight = gfx.getTextSizeForMaxWidth(self.text, self.width)
self.textHeight = self.textHeight
self.textView = playdate.ui.gridview.new(0, self.textHeight)
self.textView:setNumberOfRows(1)
self.textView:setScrollDuration(1000)
self.scrollPos = 0
cellText = self.text
function self.textView:drawCell(section, row, column, selected, x, y, width, height)
_setImageColor(kNXOR)
gfx.drawTextInRect(cellText, x, y, width, height, nil, "...", kTextAlignment.left)
end
somewhere in card:draw()
(in draw because of how I had set up the card drawing into an image context, but could be in update instead)
self.textView:drawInRect(0, 0, self.width, self.height)
somewhere in card:update()
if self.textView.isScrolling then
self:draw()
end