From e06a09619467dc5673b41ae05c7261101cf41bd1 Mon Sep 17 00:00:00 2001 From: ailurux Date: Tue, 14 May 2024 16:34:37 +1000 Subject: [PATCH] Minor improvements to infinite list widget --- lua/widgets.lua | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lua/widgets.lua b/lua/widgets.lua index bd8c84f8..0aa3e0b4 100644 --- a/lua/widgets.lua +++ b/lua/widgets.lua @@ -265,8 +265,6 @@ function widgets.InfiniteList(parent, iterator, opts) fwd_iterator:prev() end - local moving_back = false - local function add_item(item, index) if not item then return @@ -288,7 +286,7 @@ function widgets.InfiniteList(parent, iterator, opts) end btn:onevent(lvgl.EVENT.FOCUSED, function() if refreshing then return end - if this_item > last_selected and this_item - first_index > 5 then + if this_item > last_selected and this_item - first_index > 3 then -- moving forward local to_add = fwd_iterator:next() if to_add then @@ -298,18 +296,16 @@ function widgets.InfiniteList(parent, iterator, opts) end if this_item < last_selected then -- moving backward - if (last_index - first_index > 10) then + if (first_index > 0 and last_index - this_item > 3) then + local to_add = bck_iterator:prev(); + if to_add 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 + add_item(to_add, first_index-1) + refresh_group() + end + end end last_selected = this_item - refresh_group() end) btn:add_style(styles.list_item) return btn