From ef72b25660912ff247997089abfb93e9f0b52809 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 7 Mar 2024 10:59:03 +1100 Subject: use prototype inheritance for lua screens, rather than functions this gives us a way to give each screen nice little hooks, like 'onShown' and 'onHidden'. later we can use these hooks to disable bindings for screens that aren't in-use. --- lua/main_menu.lua | 61 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'lua/main_menu.lua') diff --git a/lua/main_menu.lua b/lua/main_menu.lua index 1311f8ea..7d47b785 100644 --- a/lua/main_menu.lua +++ b/lua/main_menu.lua @@ -5,41 +5,42 @@ local backstack = require("backstack") local browser = require("browser") local playing = require("playing") local theme = require("theme") +local screen = require("screen") -return function() - local menu = widgets.MenuScreen({}) +return screen:new { + createUi = function() + local menu = widgets.MenuScreen({}) - menu.list = lvgl.List(menu.root, { - w = lvgl.PCT(100), - h = lvgl.PCT(100), - flex_grow = 1, - }) + menu.list = lvgl.List(menu.root, { + w = lvgl.PCT(100), + h = lvgl.PCT(100), + flex_grow = 1, + }) - local now_playing = menu.list:add_btn(nil, "Now Playing") - now_playing:onClicked(function() - backstack.push(playing) - end) - now_playing:add_style(theme.list_item) + local now_playing = menu.list:add_btn(nil, "Now Playing") + now_playing:onClicked(function() + backstack.push(playing:new()) + end) + now_playing:add_style(theme.list_item) - local indexes = database.indexes() - for _, idx in ipairs(indexes) do - local btn = menu.list:add_btn(nil, tostring(idx)) - btn:onClicked(function() - backstack.push(function() - return browser { + local indexes = database.indexes() + for _, idx in ipairs(indexes) do + local btn = menu.list:add_btn(nil, tostring(idx)) + btn:onClicked(function() + backstack.push(browser:new { title = tostring(idx), - iterator = idx:iter() - } + iterator = idx:iter(), + }) end) - end) - btn:add_style(theme.list_item) - end + btn:add_style(theme.list_item) + end - local settings = menu.list:add_btn(nil, "Settings") - settings:onClicked(function() - backstack.push(require("settings").root) - end) - settings:add_style(theme.list_item) + local settings = menu.list:add_btn(nil, "Settings") + settings:onClicked(function() + backstack.push(require("settings"):new()) + end) + settings:add_style(theme.list_item) - return menu -end + return menu + end, +} -- cgit v1.2.3 From a78614a5806c9800956f10f993e1c70b74fbf323 Mon Sep 17 00:00:00 2001 From: ailurux Date: Thu, 7 Mar 2024 12:12:32 +1100 Subject: WIP: Getting styles from lua --- lua/main_menu.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lua/main_menu.lua') diff --git a/lua/main_menu.lua b/lua/main_menu.lua index 1311f8ea..1a9d9975 100644 --- a/lua/main_menu.lua +++ b/lua/main_menu.lua @@ -4,7 +4,7 @@ local database = require("database") local backstack = require("backstack") local browser = require("browser") local playing = require("playing") -local theme = require("theme") +local styles = require("styles") return function() local menu = widgets.MenuScreen({}) @@ -19,7 +19,7 @@ return function() now_playing:onClicked(function() backstack.push(playing) end) - now_playing:add_style(theme.list_item) + now_playing:add_style(styles.list_item) local indexes = database.indexes() for _, idx in ipairs(indexes) do @@ -32,14 +32,14 @@ return function() } end) end) - btn:add_style(theme.list_item) + btn:add_style(styles.list_item) end local settings = menu.list:add_btn(nil, "Settings") settings:onClicked(function() backstack.push(require("settings").root) end) - settings:add_style(theme.list_item) + settings:add_style(styles.list_item) return menu end -- cgit v1.2.3