diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-03-07 11:23:31 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-03-07 11:23:31 +1100 |
| commit | beb1f654958c28429323fcb9622c9c8d206979a3 (patch) | |
| tree | 2e81e643a6099e5a9e884dbe2346dd2e761751e1 /lua/browser.lua | |
| parent | 14552881900bb3ed0e9ed2d4a732e4104b32ccfa (diff) | |
| parent | eba5adeb8cc606b4d685132248c6481c0aca53f6 (diff) | |
| download | tangara-fw-beb1f654958c28429323fcb9622c9c8d206979a3.tar.gz | |
Merge branch 'main' of git.sr.ht:~jacqueline/tangara-fw
Diffstat (limited to 'lua/browser.lua')
| -rw-r--r-- | lua/browser.lua | 210 |
1 files changed, 102 insertions, 108 deletions
diff --git a/lua/browser.lua b/lua/browser.lua index a7f0c336..5577d4df 100644 --- a/lua/browser.lua +++ b/lua/browser.lua @@ -6,30 +6,11 @@ local queue = require("queue") local playing = require("playing") local theme = require("theme") local playback = require("playback") +local screen = require("screen") -local browser = {} - -function browser.create(opts) - local screen = {} - screen.root = lvgl.Object(nil, { - flex = { - flex_direction = "column", - flex_wrap = "wrap", - justify_content = "flex-start", - align_items = "flex-start", - align_content = "flex-start", - }, - w = lvgl.HOR_RES(), - h = lvgl.VER_RES(), - }) - screen.root:center() - - screen.status_bar = widgets.StatusBar(screen.root, { - title = opts.title, - }) - - if opts.breadcrumb then - local header = screen.root:Object { +return screen:new { + createUi = function(self) + self.root = lvgl.Object(nil, { flex = { flex_direction = "column", flex_wrap = "wrap", @@ -38,100 +19,113 @@ function browser.create(opts) align_content = "flex-start", }, w = lvgl.HOR_RES(), - h = lvgl.SIZE_CONTENT, - pad_left = 4, - pad_right = 4, - pad_bottom = 2, - bg_opa = lvgl.OPA(100), - bg_color = "#fafafa", - scrollbar_mode = lvgl.SCROLLBAR_MODE.OFF, - } - - header:Label { - text = opts.breadcrumb, - text_font = font.fusion_10, - } + h = lvgl.VER_RES(), + }) + self.root:center() - local buttons = header:Object({ - flex = { - flex_direction = "row", - flex_wrap = "wrap", - justify_content = "flex-end", - align_items = "center", - align_content = "center", - }, - w = lvgl.PCT(100), - h = lvgl.SIZE_CONTENT, - pad_column = 4, + self.status_bar = widgets.StatusBar(self.root, { + title = self.title, }) - local original_iterator = opts.iterator:clone() - local enqueue = widgets.IconBtn(buttons, "//lua/img/enqueue.png", "Enqueue") - enqueue:onClicked(function() - queue.add(original_iterator) - playback.playing:set(true) - end) - -- enqueue:add_flag(lvgl.FLAG.HIDDEN) - local play = widgets.IconBtn(buttons, "//lua/img/play_small.png", "Play") - play:onClicked(function() - queue.clear() - queue.add(original_iterator) - playback.playing:set(true) - backstack.push(playing) - end - ) - end - screen.list = lvgl.List(screen.root, { - w = lvgl.PCT(100), - h = lvgl.PCT(100), - flex_grow = 1, - scrollbar_mode = lvgl.SCROLLBAR_MODE.OFF, - }) + if self.breadcrumb then + local header = self.root:Object { + flex = { + flex_direction = "column", + flex_wrap = "wrap", + justify_content = "flex-start", + align_items = "flex-start", + align_content = "flex-start", + }, + w = lvgl.HOR_RES(), + h = lvgl.SIZE_CONTENT, + pad_left = 4, + pad_right = 4, + pad_bottom = 2, + bg_opa = lvgl.OPA(100), + bg_color = "#fafafa", + scrollbar_mode = lvgl.SCROLLBAR_MODE.OFF, + } - local back = screen.list:add_btn(nil, "< Back") - back:onClicked(backstack.pop) - back:add_style(theme.list_item) + header:Label { + text = self.breadcrumb, + text_font = font.fusion_10, + } - screen.focused_item = 0 - screen.last_item = 0 - screen.add_item = function(item) - if not item then return end - screen.last_item = screen.last_item + 1 - local this_item = screen.last_item - local btn = screen.list:add_btn(nil, tostring(item)) - btn:onClicked(function() - local contents = item:contents() - if type(contents) == "userdata" then - backstack.push(function() - return browser.create({ - title = opts.title, - iterator = contents, - breadcrumb = tostring(item), - }) - end) - else + local buttons = header:Object({ + flex = { + flex_direction = "row", + flex_wrap = "wrap", + justify_content = "flex-end", + align_items = "center", + align_content = "center", + }, + w = lvgl.PCT(100), + h = lvgl.SIZE_CONTENT, + pad_column = 4, + }) + local original_iterator = self.iterator:clone() + local enqueue = widgets.IconBtn(buttons, "//lua/img/enqueue.png", "Enqueue") + enqueue:onClicked(function() + queue.add(original_iterator) + playback.playing:set(true) + end) + -- enqueue:add_flag(lvgl.FLAG.HIDDEN) + local play = widgets.IconBtn(buttons, "//lua/img/play_small.png", "Play") + play:onClicked(function() queue.clear() - queue.add(contents) + queue.add(original_iterator) playback.playing:set(true) backstack.push(playing) end - end) - btn:onevent(lvgl.EVENT.FOCUSED, function() - screen.focused_item = this_item - if screen.last_item - 5 < this_item then - screen.add_item(opts.iterator()) - end - end) - btn:add_style(theme.list_item) - end + ) + end - for _ = 1, 8 do - local val = opts.iterator() - if not val then break end - screen.add_item(val) - end + self.list = lvgl.List(self.root, { + w = lvgl.PCT(100), + h = lvgl.PCT(100), + flex_grow = 1, + scrollbar_mode = lvgl.SCROLLBAR_MODE.OFF, + }) - return screen -end + local back = self.list:add_btn(nil, "< Back") + back:onClicked(backstack.pop) + back:add_style(theme.list_item) -return browser.create + 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(theme.list_item) + end + + for _ = 1, 8 do + local val = self.iterator() + if not val then break end + self.add_item(val) + end + end +} |
