An example of setScrollPosition

Does anybody by chance have a working sample of the setScrollPosition function for gridview ? I didn't see any examples in the SDK files.

I can't manage to see getScrollPosition print out anything other than 0.0, 0.0 and can't seem to figure out how to set it to anything. It's looking for an x,y value according to the documentation, but is that screen space relative or relative to the gridview's current x,y (probably the latter)? Any insight would be helpful ! Thank you.

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()

self.text = gfx.getLocalizedText(text, systemLanguage)
self.textWidth, self.textHeight = gfx.getTextSizeForMaxWidth(self.text, self.width)
self.textHeight = self.textHeight
self.textView =, self.textHeight)
self.scrollPos = 0
cellText = self.text
function self.textView:drawCell(section, row, column, selected, x, y, width, height)
	gfx.drawTextInRect(cellText, x, y, width, height, nil, "...", kTextAlignment.left)

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
1 Like

Will mark complete !