From 06aca259cbb84c41a002e5a93735b289cc2aa93a Mon Sep 17 00:00:00 2001 From: jacqueline Date: Wed, 22 Nov 2023 14:38:52 +1100 Subject: Add basic lua browser screen --- lua/assets/audio.png | Bin 623 -> 4318 bytes lua/assets/battery_20.png | Bin 617 -> 4337 bytes lua/assets/battery_40.png | Bin 617 -> 4338 bytes lua/assets/battery_60.png | Bin 618 -> 4338 bytes lua/assets/battery_80.png | Bin 622 -> 4340 bytes lua/assets/battery_empty.png | Bin 614 -> 4332 bytes lua/assets/battery_full.png | Bin 618 -> 4339 bytes lua/assets/bt.png | Bin 8502 -> 4595 bytes lua/assets/bt_conn.png | Bin 654 -> 4363 bytes lua/assets/pause.png | Bin 608 -> 4286 bytes lua/assets/play.png | Bin 616 -> 4309 bytes lua/browser.lua | 113 +++++++++++++++++++++++++++++++++++++++++++ lua/main_menu.lua | 8 +++ lua/widgets.lua | 13 ++--- 14 files changed, 126 insertions(+), 8 deletions(-) create mode 100644 lua/browser.lua (limited to 'lua') diff --git a/lua/assets/audio.png b/lua/assets/audio.png index b8ad9071..6151307f 100644 Binary files a/lua/assets/audio.png and b/lua/assets/audio.png differ diff --git a/lua/assets/battery_20.png b/lua/assets/battery_20.png index 9012376f..3a702397 100644 Binary files a/lua/assets/battery_20.png and b/lua/assets/battery_20.png differ diff --git a/lua/assets/battery_40.png b/lua/assets/battery_40.png index 88a0b448..ae7e3d7b 100644 Binary files a/lua/assets/battery_40.png and b/lua/assets/battery_40.png differ diff --git a/lua/assets/battery_60.png b/lua/assets/battery_60.png index d86c997a..44ba7954 100644 Binary files a/lua/assets/battery_60.png and b/lua/assets/battery_60.png differ diff --git a/lua/assets/battery_80.png b/lua/assets/battery_80.png index 344b3703..33bae9fc 100644 Binary files a/lua/assets/battery_80.png and b/lua/assets/battery_80.png differ diff --git a/lua/assets/battery_empty.png b/lua/assets/battery_empty.png index c9176e8c..5f3bfdbc 100644 Binary files a/lua/assets/battery_empty.png and b/lua/assets/battery_empty.png differ diff --git a/lua/assets/battery_full.png b/lua/assets/battery_full.png index 57122a23..f5da13a3 100644 Binary files a/lua/assets/battery_full.png and b/lua/assets/battery_full.png differ diff --git a/lua/assets/bt.png b/lua/assets/bt.png index 180e6b3a..73f3179f 100644 Binary files a/lua/assets/bt.png and b/lua/assets/bt.png differ diff --git a/lua/assets/bt_conn.png b/lua/assets/bt_conn.png index 7a5f2b27..91f9964d 100644 Binary files a/lua/assets/bt_conn.png and b/lua/assets/bt_conn.png differ diff --git a/lua/assets/pause.png b/lua/assets/pause.png index ec388cd5..f1a3d8cb 100644 Binary files a/lua/assets/pause.png and b/lua/assets/pause.png differ diff --git a/lua/assets/play.png b/lua/assets/play.png index 0d0bb34d..81927a8a 100644 Binary files a/lua/assets/play.png and b/lua/assets/play.png differ diff --git a/lua/browser.lua b/lua/browser.lua new file mode 100644 index 00000000..380922a8 --- /dev/null +++ b/lua/browser.lua @@ -0,0 +1,113 @@ +local lvgl = require("lvgl") +local widgets = require("widgets") +local legacy_ui = require("legacy_ui") +local database = require("database") +local backstack = require("backstack") + +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, { + back_cb = backstack.pop, + title = opts.title, + }) + + if opts.breadcrumb then + local header = screen.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_top = 2, + pad_bottom = 2, + bg_opa = lvgl.OPA(100), + bg_color = "#f3e5f5", + scrollbar_mode = lvgl.SCROLLBAR_MODE.OFF, + } + + header:Label { text = opts.breadcrumb } + + 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 enqueue = buttons:Button {} + enqueue:Label { text = "Enqueue" } + enqueue:add_flag(lvgl.FLAG.HIDDEN) + local play = buttons:Button {} + play:Label { text = "Play all" } + end + + screen.list = lvgl.List(screen.root, { + w = lvgl.PCT(100), + h = lvgl.PCT(100), + flex_grow = 1, + scrollbar_mode = lvgl.SCROLLBAR_MODE.OFF, + }) + + 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) == "function" then + backstack.push(function() + return browser.create({ + title = opts.title, + iterator = contents, + breadcrumb = tostring(item), + }) + end) + else + print("selected track", contents) + end + end) + btn:onevent(lvgl.EVENT.FOCUSED, function() + screen.focused_item = this_item + if screen.last_item - 5 < this_item then + opts.iterator(screen.add_item) + end + end) + end + + for _ = 1, 8 do + opts.iterator(screen.add_item) + end + + return screen +end + +return browser.create diff --git a/lua/main_menu.lua b/lua/main_menu.lua index e38ed2c1..7c236a23 100644 --- a/lua/main_menu.lua +++ b/lua/main_menu.lua @@ -2,6 +2,8 @@ local lvgl = require("lvgl") local widgets = require("widgets") local legacy_ui = require("legacy_ui") local database = require("database") +local backstack = require("backstack") +local browser = require("browser") return function() local menu = {} @@ -35,6 +37,12 @@ return function() local btn = menu.list:add_btn(nil, tostring(idx)) btn:onClicked(function() legacy_ui.open_browse(id); + -- backstack.push(function() + -- return browser { + -- title = tostring(idx), + -- iterator = idx:iter() + -- } + -- end) end) end diff --git a/lua/widgets.lua b/lua/widgets.lua index 9807bc09..76f7c839 100644 --- a/lua/widgets.lua +++ b/lua/widgets.lua @@ -17,23 +17,20 @@ function widgets.StatusBar(parent, opts) }, w = lvgl.HOR_RES(), h = lvgl.SIZE_CONTENT, - bg_opa = lvgl.OPA(100), - bg_color = "#fff", pad_top = 1, pad_bottom = 1, pad_column = 1, - shadow_width = 6, - shadow_opa = lvgl.OPA(50), - shaddow_ofs_x = 0, + bg_opa = lvgl.OPA(100), + bg_color = "#e1bee7", scrollbar_mode = lvgl.SCROLLBAR_MODE.OFF, } if opts.back_cb then - status_bar.back = status_bar.root:Label { + status_bar.back = status_bar.root:Button { w = lvgl.SIZE_CONTENT, h = 12, - text = "<", } + status_bar.back:Label({ text = "<", align = lvgl.ALIGN.CENTER }) status_bar.back:onClicked(opts.back_cb) end @@ -44,7 +41,7 @@ function widgets.StatusBar(parent, opts) flex_grow = 1, } if opts.title then - status_bar.title.set { text = opts.title } + status_bar.title:set { text = opts.title } end status_bar.playing = status_bar.root:Image {} -- cgit v1.2.3