I’ve got a simple DataList of custom components; each component has an icon and a slider. Right now I’m just trying to get the icons set up correctly, but the first element doesn’t change its icon, and each element after that is offset by one, except for the last, which is missing.
i.e. instead of “ABCDEF” it’s “_ABCDE”
here’s the relevant code:
local function create_function(self, data, index, data_list)
-- In data list create funtion we made all init stuff for this node
local nodes = gui.clone_tree(self.prefab)
local root = nodes["prefab/prefab"]
gui.set_enabled(root, true)
local bar = self.druid:new(statbar, "statbar", on_change)
gui.set_texture(bar.icon, "mutopiya")
gui.play_flipbook(bar.icon, tostring(data.icon))
print("added "..data.icon)
-- We should return in this function root node and optionally - Druid component
return root, bar
end
function init(self)
self.druid = druid.new(self)
druid.register("statbar", statbar)
self.prefab = gui.get_node("prefab/prefab")
gui.set_enabled(self.prefab, false)
local data = {
{ icon = 197, value = 1 },
{ icon = 198, value = 1 },
{ icon = 199, value = 1 },
{ icon = 200, value = 1 },
{ icon = 201, value = 1 },
{ icon = 202, value = 1 }
}
self.scroll = self.druid:new_scroll("stats_view", "stats_view_content")
self.scroll:set_horizontal_scroll(false)
self.grid = self.druid:new_static_grid("stats_view_content", "prefab/prefab", 1)
-- Pass already created scroll and grid components to data_list:
self.data_list = self.druid:new_data_list(self.scroll, self.grid, create_function)
self.data_list:set_data(data)
end
I’m really not sure what I’m doing wrong. Am I not initializing the custom component correctly?