diff options
| author | cooljqln <cooljqln@noreply.codeberg.org> | 2025-01-14 04:33:47 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2025-01-14 04:33:47 +0000 |
| commit | 1625d5a6b8d13ec26d76e5d32fa7641bf5f46c87 (patch) | |
| tree | caeb492c51e0922c189d5abf75e0910521f43de7 | |
| parent | db7c28347c29b84db9c0a8b9306cf2537f1f3053 (diff) | |
| parent | fcc9addc9a30797d9a1e5a1bbd6d5f5a6e8d8d6f (diff) | |
| download | tangara-fw-1625d5a6b8d13ec26d76e5d32fa7641bf5f46c87.tar.gz | |
Merge pull request 'Ensure settings sections are in view' (#177) from tjk/tangara-fw:settings-scroll into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/177
| -rw-r--r-- | lua/settings.lua | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/lua/settings.lua b/lua/settings.lua index 2dade1d2..c0e7c23e 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -809,24 +809,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") |
