fosterdouglas
(Foster Douglas / Everyday Lemonade)
1
I'm curious if anybody has advice on how to best work with the gridview override functions inside of an object subclass? It's a few times now where I've wanted to do something like:
function self.listView:drawCell(section, row, column, selected, x, y, width, height)
gfx.drawTextInRect(self.optionsList[row], x, y, width, height)
end
But instead need to redeclare that value first to access it properly:
local text = self.optionsList
function self.listView:drawCell(section, row, column, selected, x, y, width, height)
gfx.drawTextInRect(text[row], x, y, width, height)
end
Maybe I'm missing a key concept of the SDK's implementation of subclasses here, though. Let me know if anyone else has come across this. Thanks!
Did you find any other ways? For anyone else finding this thread like I did, the back reference did work for me with something like this (I had it a bit more convoluted but this is the gist):
function Base:init()
Base.super.init(self)
self.optionsList = { ... }
self.listview = playdate.ui.gridview.new(0, 100)
self.listview.parent = self
-- Note self as first arg, it will refer to self.listview when the function is called!
self.listview.drawCell = function(self, section, row, column, selected, x, y, width, height)
self.parent.optionsList[row] [...]
end