From eeb3f2d406a951b423b83f559fe749df0b4f745a Mon Sep 17 00:00:00 2001 From: ailurux Date: Mon, 6 May 2024 12:36:16 +1000 Subject: WIP: File browser, needs bug fixes --- lua/file_browser.lua | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lua/main_menu.lua | 10 +++++++ 2 files changed, 83 insertions(+) create mode 100644 lua/file_browser.lua (limited to 'lua') diff --git a/lua/file_browser.lua b/lua/file_browser.lua new file mode 100644 index 00000000..57ebde58 --- /dev/null +++ b/lua/file_browser.lua @@ -0,0 +1,73 @@ +local lvgl = require("lvgl") +local widgets = require("widgets") +local backstack = require("backstack") +local font = require("font") +local queue = require("queue") +local playing = require("playing") +local styles = require("styles") +local playback = require("playback") +local theme = require("theme") +local screen = require("screen") +local filesystem = require("filesystem") + +return screen:new{ + createUi = function(self) + self.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() + }) + self.root:center() + + self.status_bar = widgets.StatusBar(self, { + back_cb = backstack.pop, + title = self.title + }) + + 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), + scrollbar_mode = lvgl.SCROLLBAR_MODE.OFF + } + theme.set_style(header, "header") + + if self.breadcrumb then + header:Label{ + text = self.breadcrumb, + text_font = font.fusion_10 + } + end + + local recycle_list = widgets.RecyclerList(self.root, self.iterator, { + callback = function(item) + return function() + local is_dir = item:is_directory() + if is_dir then + backstack.push(require("file_browser"):new{ + title = self.title, + iterator = filesystem.iterator(tostring(item)), + breadcrumb = tostring(item) + }) + end + end + end + }) + end +} diff --git a/lua/main_menu.lua b/lua/main_menu.lua index 5fd6417f..9c52340b 100644 --- a/lua/main_menu.lua +++ b/lua/main_menu.lua @@ -5,6 +5,7 @@ local backstack = require("backstack") local browser = require("browser") local playing = require("playing") local styles = require("styles") +local filesystem = require("filesystem") local screen = require("screen") return widgets.MenuScreen:new { @@ -35,6 +36,15 @@ return widgets.MenuScreen:new { btn:add_style(styles.list_item) end + local files = list:add_btn(nil, "Files") + files:onClicked(function() + backstack.push(require("file_browser"):new { + title = "Files", + iterator = filesystem.iterator(""), + }) + end) + files:add_style(styles.list_item) + local settings = list:add_btn(nil, "Settings") settings:onClicked(function() backstack.push(require("settings"):new()) -- cgit v1.2.3 From 8019c7691889cde4c3d40bbd78d485a92d713bbf Mon Sep 17 00:00:00 2001 From: ailurux Date: Mon, 6 May 2024 15:48:04 +1000 Subject: File browser and track browser bug fixes --- lua/widgets.lua | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) (limited to 'lua') diff --git a/lua/widgets.lua b/lua/widgets.lua index 4d7ff077..6d37e9ac 100644 --- a/lua/widgets.lua +++ b/lua/widgets.lua @@ -288,13 +288,8 @@ function widgets.RecyclerList(parent, iterator, opts) end btn:onevent(lvgl.EVENT.FOCUSED, function() if refreshing then return end - selected = this_item - if this_item > last_selected and this_item > 3 then + if this_item > last_selected and this_item - first_index > 5 then -- moving forward - if moving_back == true then - fwd_iterator:next() - moving_back = false - end local to_add = fwd_iterator:next() if to_add then remove_top() @@ -303,19 +298,15 @@ function widgets.RecyclerList(parent, iterator, opts) end if this_item < last_selected then -- moving backward - if last_index - this_item > 3 then - if moving_back == false then - -- Special case for the element we switch on - bck_iterator:prev() - moving_back = true - end - if (last_index > 10) then - remove_last() - end - if (first_index > 0) then - add_item(bck_iterator:prev(), first_index-1) - end - end + if (last_index - first_index > 10) then + remove_last() + end + if (first_index > 0 and this_item - first_index < 5) then + local to_add = bck_iterator:prev(); + if to_add then + add_item(to_add, first_index-1) + end + end end last_selected = this_item refresh_group() -- cgit v1.2.3 From 0062eb9a9ea265c7802d3c4bc8c1cd043cefbea3 Mon Sep 17 00:00:00 2001 From: ailurux Date: Fri, 10 May 2024 13:16:29 +1000 Subject: Rename widget to InfiniteList --- lua/browser.lua | 2 +- lua/file_browser.lua | 2 +- lua/widgets.lua | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'lua') diff --git a/lua/browser.lua b/lua/browser.lua index 96ebbcab..c314e8f8 100644 --- a/lua/browser.lua +++ b/lua/browser.lua @@ -81,7 +81,7 @@ return screen:new{ backstack.push(playing:new()) end) - local recycle_list = widgets.RecyclerList(self.root, self.iterator, { + local infinite_list = widgets.InfiniteList(self.root, self.iterator, { callback = function(item) return function() local contents = item:contents() diff --git a/lua/file_browser.lua b/lua/file_browser.lua index 57ebde58..bd1e7d8e 100644 --- a/lua/file_browser.lua +++ b/lua/file_browser.lua @@ -55,7 +55,7 @@ return screen:new{ } end - local recycle_list = widgets.RecyclerList(self.root, self.iterator, { + local infinite_list = widgets.InfiniteList(self.root, self.iterator, { callback = function(item) return function() local is_dir = item:is_directory() diff --git a/lua/widgets.lua b/lua/widgets.lua index 6d37e9ac..bd8c84f8 100644 --- a/lua/widgets.lua +++ b/lua/widgets.lua @@ -215,10 +215,10 @@ function widgets.IconBtn(parent, icon, text) return btn end -function widgets.RecyclerList(parent, iterator, opts) - local recycler_list = {} +function widgets.InfiniteList(parent, iterator, opts) + local infinite_list = {} - recycler_list.root = lvgl.List(parent, { + infinite_list.root = lvgl.List(parent, { w = lvgl.PCT(100), h = lvgl.PCT(100), flex_grow = 1, @@ -230,13 +230,13 @@ function widgets.RecyclerList(parent, iterator, opts) refreshing = true local group = lvgl.group.get_default() local focused_obj = group:get_focused() - local num_children = recycler_list.root:get_child_cnt() + local num_children = infinite_list.root:get_child_cnt() -- remove all children from the group and re-add them for i = 0, num_children-1 do - lvgl.group.remove_obj(recycler_list.root:get_child(i)) + lvgl.group.remove_obj(infinite_list.root:get_child(i)) end for i = 0, num_children-1 do - group:add_obj(recycler_list.root:get_child(i)) + group:add_obj(infinite_list.root:get_child(i)) end if (focused_obj) then lvgl.group.focus_obj(focused_obj) @@ -252,14 +252,14 @@ function widgets.RecyclerList(parent, iterator, opts) local first_index = 0 local function remove_top() - local obj = recycler_list.root:get_child(0) + local obj = infinite_list.root:get_child(0) obj:delete() first_index = first_index + 1 bck_iterator:next() end local function remove_last() - local obj = recycler_list.root:get_child(-1) + local obj = infinite_list.root:get_child(-1) obj:delete() last_index = last_index - 1 fwd_iterator:prev() @@ -278,7 +278,7 @@ function widgets.RecyclerList(parent, iterator, opts) add_to_top = true end if this_item > last_index then last_index = index end - local btn = recycler_list.root:add_btn(nil, tostring(item)) + local btn = infinite_list.root:add_btn(nil, tostring(item)) if add_to_top then btn:move_to_index(0) end @@ -323,7 +323,7 @@ function widgets.RecyclerList(parent, iterator, opts) add_item(val, idx) end - return recycler_list + return infinite_list end return widgets -- cgit v1.2.3 From ce9861260d5642eb496e447eb7e93de5938c6b1f Mon Sep 17 00:00:00 2001 From: ailurux Date: Fri, 10 May 2024 14:18:04 +1000 Subject: Remove unused local var --- lua/browser.lua | 2 +- lua/file_browser.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lua') diff --git a/lua/browser.lua b/lua/browser.lua index c314e8f8..7ea8e240 100644 --- a/lua/browser.lua +++ b/lua/browser.lua @@ -81,7 +81,7 @@ return screen:new{ backstack.push(playing:new()) end) - local infinite_list = widgets.InfiniteList(self.root, self.iterator, { + widgets.InfiniteList(self.root, self.iterator, { callback = function(item) return function() local contents = item:contents() diff --git a/lua/file_browser.lua b/lua/file_browser.lua index bd1e7d8e..91b84c84 100644 --- a/lua/file_browser.lua +++ b/lua/file_browser.lua @@ -55,7 +55,7 @@ return screen:new{ } end - local infinite_list = widgets.InfiniteList(self.root, self.iterator, { + widgets.InfiniteList(self.root, self.iterator, { callback = function(item) return function() local is_dir = item:is_directory() -- cgit v1.2.3