summaryrefslogtreecommitdiff
path: root/lua/settings.lua
diff options
context:
space:
mode:
authorTom Kirchner <git@halffull.org>2025-01-09 21:54:55 -0800
committerTom Kirchner <git@halffull.org>2025-01-12 21:42:20 -0800
commitfcc9addc9a30797d9a1e5a1bbd6d5f5a6e8d8d6f (patch)
tree8d00ebff7b7e33f9ba40fee41927bfe6c15e28c1 /lua/settings.lua
parent430742c29776931a66658735e76f574dbf486330 (diff)
downloadtangara-fw-fcc9addc9a30797d9a1e5a1bbd6d5f5a6e8d8d6f.tar.gz
Ensure Audio section header in settings is visible
Diffstat (limited to 'lua/settings.lua')
-rw-r--r--lua/settings.lua24
1 files changed, 21 insertions, 3 deletions
diff --git a/lua/settings.lua b/lua/settings.lua
index 195c3898..de126249 100644
--- a/lua/settings.lua
+++ b/lua/settings.lua
@@ -805,24 +805,42 @@ settings.Root = widgets.MenuScreen:new {
flex_grow = 1,
}
+ -- Creates a section header, not selectable.
+ -- The return value can be passed into submenu() if scrolling behavior
+ -- needs special treatment.
local function section(name)
local elem = list:Label {
text = name,
pad_left = 4,
}
theme.set_subject(elem, "settings_title")
+ return elem
end
- local function submenu(name, class)
+ -- Creates a selectable menu item that opens the screen given by 'class'.
+ -- If 'section_label' is given, will scroll that section header label into
+ -- view when this item is selected; this helps with the very top section,
+ -- which normally has nothing scrolling it into view.
+ local function submenu(name, class, section_label)
local item = list:add_btn(nil, name)
item:onClicked(function()
backstack.push(class:new())
end)
+ if section_label then
+ -- Make sure item is visible, and, ideally, the section header.
+ item:onevent(lvgl.EVENT.FOCUSED, function()
+ -- Scroll to section in case it's off the top of the screen.
+ -- (0 for no animation; doesn't work if both scroll with animation.)
+ section_label:scroll_to_view(0);
+ -- Scroll to item in case it's off the bottom of the screen.
+ item:scroll_to_view(1);
+ end)
+ end
item:add_style(styles.list_item)
end
- section("Audio")
- submenu("Bluetooth", settings.BluetoothSettings)
+ local audio_section = section("Audio")
+ submenu("Bluetooth", settings.BluetoothSettings, audio_section)
submenu("Headphones", settings.HeadphonesSettings)
section("Interface")