daniel/recycler-list (#66)

@cooljqln should be good to merge to main, give it a look over though please? :)

Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/66
Co-authored-by: ailurux <ailuruxx@gmail.com>
Co-committed-by: ailurux <ailuruxx@gmail.com>
This commit is contained in:
ailurux
2024-04-19 02:06:37 +00:00
committed by cooljqln
parent b17f8a3dcc
commit 7f630cebdd
4 changed files with 216 additions and 97 deletions
+19 -54
View File
@@ -78,62 +78,27 @@ return screen:new{
queue.clear()
queue.add(original_iterator)
playback.playing:set(true)
backstack.push(playing)
backstack.push(playing:new())
end)
self.list = lvgl.List(self.root, {
w = lvgl.PCT(100),
h = lvgl.PCT(100),
flex_grow = 1,
scrollbar_mode = lvgl.SCROLLBAR_MODE.OFF
local recycle_list = widgets.RecyclerList(self.root, self.iterator, {
callback = function(item)
return function()
local contents = item:contents()
if type(contents) == "userdata" then
backstack.push(require("browser"):new{
title = self.title,
iterator = contents,
breadcrumb = tostring(item)
})
else
queue.clear()
queue.add(contents)
playback.playing:set(true)
backstack.push(playing:new())
end
end
end
})
-- local back = self.list:add_btn(nil, "< Back")
-- back:onClicked(backstack.pop)
-- back:add_style(styles.list_item)
self.focused_item = 0
self.last_item = 0
self.add_item = function(item)
if not item then
return
end
self.last_item = self.last_item + 1
local this_item = self.last_item
local btn = self.list:add_btn(nil, tostring(item))
btn:onClicked(function()
local contents = item:contents()
if type(contents) == "userdata" then
backstack.push(require("browser"):new{
title = self.title,
iterator = contents,
breadcrumb = tostring(item)
})
else
queue.clear()
queue.add(contents)
playback.playing:set(true)
backstack.push(playing:new())
end
end)
btn:onevent(lvgl.EVENT.FOCUSED, function()
self.focused_item = this_item
if self.last_item - 5 < this_item then
self.add_item(self.iterator())
end
end)
btn:add_style(styles.list_item)
if this_item == 1 then
btn:focus()
end
end
for _ = 1, 8 do
local val = self.iterator()
if not val then
break
end
self.add_item(val)
end
end
}