summaryrefslogtreecommitdiff
path: root/lua/settings.lua
diff options
context:
space:
mode:
authorailurux <ailuruxx@gmail.com>2024-08-12 03:19:03 +0000
committercooljqln <cooljqln@noreply.codeberg.org>2024-08-12 03:19:03 +0000
commitd719f9c5017ad8006c21b6d546a5d70e846e9502 (patch)
tree0da75c201e98d12b39c87743ee3ed242d2fc5809 /lua/settings.lua
parent3d7b005dc98235899d1a9ae5a74bf11d916028b9 (diff)
downloadtangara-fw-d719f9c5017ad8006c21b6d546a5d70e846e9502.tar.gz
daniel/theme-setting (#87)
- Themes can be loaded from disk and built-in - Themes can be selected in a new themes menu of the settings screen - Some touch-ups to existing themes - The saved theme is persisted in nvs Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/87 Reviewed-by: cooljqln <cooljqln@noreply.codeberg.org> Co-authored-by: ailurux <ailuruxx@gmail.com> Co-committed-by: ailurux <ailuruxx@gmail.com>
Diffstat (limited to 'lua/settings.lua')
-rw-r--r--lua/settings.lua61
1 files changed, 61 insertions, 0 deletions
diff --git a/lua/settings.lua b/lua/settings.lua
index 79572ee9..3033b36e 100644
--- a/lua/settings.lua
+++ b/lua/settings.lua
@@ -7,9 +7,11 @@ local display = require("display")
local controls = require("controls")
local bluetooth = require("bluetooth")
local theme = require("theme")
+local filesystem = require("filesystem")
local database = require("database")
local usb = require("usb")
local font = require("font")
+local main_menu = require("main_menu")
local SettingsScreen = widgets.MenuScreen:new {
show_back = true,
@@ -301,6 +303,64 @@ local DisplaySettings = SettingsScreen:new {
end
}
+local ThemeSettings = SettingsScreen:new {
+ title = "Theme",
+ createUi = function(self)
+ SettingsScreen.createUi(self)
+
+ theme.set_style(self.content:Label {
+ text = "Theme",
+ }, "settings_title")
+
+ local themeOptions = {}
+ themeOptions["Dark"] = "/lua/theme_dark.lua"
+ themeOptions["Light"] = "/lua/theme_light.lua"
+
+ -- Parse theme directory for more themes
+ local theme_dir_iter = filesystem.iterator("/.themes/")
+ for dir in theme_dir_iter do
+ local theme_name = tostring(dir):match("(.+).lua$")
+ themeOptions[theme_name] = "/sdcard/.themes/" .. theme_name .. ".lua"
+ end
+
+ local saved_theme = theme.theme_filename();
+ local saved_theme_name = saved_theme:match(".+/(.*).lua$")
+
+ local options = ""
+ local idx = 0
+ local selected_idx = -1
+ for i, v in pairs(themeOptions) do
+ if (saved_theme == v) then
+ selected_idx = idx
+ end
+ if idx > 0 then
+ options = options .. "\n"
+ end
+ options = options .. i
+ idx = idx + 1
+ end
+
+ if (selected_idx == -1) then
+ options = options .. "\n" .. saved_theme_name
+ selected_idx = idx
+ end
+
+ local theme_chooser = self.content:Dropdown {
+ options = options,
+ }
+ theme_chooser:set({selected = selected_idx})
+
+ theme_chooser:onevent(lvgl.EVENT.VALUE_CHANGED, function()
+ local option = theme_chooser:get('selected_str')
+ local selectedTheme = themeOptions[option]
+ if (selectedTheme) then
+ theme.load_theme(tostring(selectedTheme))
+ backstack.reset(main_menu:new())
+ end
+ end)
+ end
+}
+
local InputSettings = SettingsScreen:new {
title = "Input Method",
createUi = function(self)
@@ -742,6 +802,7 @@ return widgets.MenuScreen:new {
section("Interface")
submenu("Display", DisplaySettings)
+ submenu("Theme", ThemeSettings)
submenu("Input Method", InputSettings)
section("USB")