summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorailurux <ailuruxx@gmail.com>2024-02-16 15:10:45 +1100
committerailurux <ailuruxx@gmail.com>2024-02-16 15:10:45 +1100
commitd25e5860c7cfcd4a5349c67f088ed6e4f55ffaed (patch)
tree912f8daeb82acd28252d65afcfb827f3b833f457
parent665679b8854d34c13d8eb92167aa8a4691619d8b (diff)
downloadtangara-fw-d25e5860c7cfcd4a5349c67f088ed6e4f55ffaed.tar.gz
Only update scrubber if not currently dragging
-rw-r--r--lib/luavgl/src/lvgl.lua5
-rw-r--r--lib/luavgl/src/widgets/slider.c10
-rw-r--r--lua/playing.lua13
3 files changed, 24 insertions, 4 deletions
diff --git a/lib/luavgl/src/lvgl.lua b/lib/luavgl/src/lvgl.lua
index e06f673d..13fd6908 100644
--- a/lib/luavgl/src/lvgl.lua
+++ b/lib/luavgl/src/lvgl.lua
@@ -1098,6 +1098,11 @@ end
function slider:value()
end
+--- get whether slider is dragged or not
+--- @return boolean
+function slider:is_dragged()
+end
+
---
--- Switch widget
---@class Switch:Object
diff --git a/lib/luavgl/src/widgets/slider.c b/lib/luavgl/src/widgets/slider.c
index c385f6bb..ad093fb5 100644
--- a/lib/luavgl/src/widgets/slider.c
+++ b/lib/luavgl/src/widgets/slider.c
@@ -73,9 +73,19 @@ static int luavgl_slider_tostring(lua_State *L) {
return 1;
}
+static int luavgl_slider_is_dragged(lua_State *L) {
+ lv_obj_t *obj = luavgl_to_obj(L, 1);
+ bool is_dragged = lv_slider_is_dragged(obj);
+ lv_group_t * g = lv_obj_get_group(obj);
+ bool editing = lv_group_get_editing(g);
+ lua_pushboolean(L, editing || is_dragged);
+ return 1;
+}
+
static const luaL_Reg luavgl_slider_methods[] = {
{"set", luavgl_slider_set},
{"value", luavgl_slider_value},
+ {"is_dragged", luavgl_slider_is_dragged},
{NULL, NULL},
};
diff --git a/lua/playing.lua b/lua/playing.lua
index 22b3390f..4767e42f 100644
--- a/lua/playing.lua
+++ b/lua/playing.lua
@@ -112,13 +112,17 @@ return function(opts)
}
playlist:Object({ w = 3, h = 1 }) -- spacer
- local scrubber = screen.root:Bar {
+ local scrubber = screen.root:Slider {
w = lvgl.PCT(100),
h = 5,
range = { min = 0, max = 100 },
value = 0,
}
+ scrubber:onevent(lvgl.EVENT.RELEASED, function()
+ playback.position:set(scrubber:value())
+ end)
+
local controls = screen.root:Object {
flex = {
flex_direction = "row",
@@ -147,8 +151,7 @@ return function(opts)
local play_pause_btn = controls:Button {}
play_pause_btn:onClicked(function()
- --playback.playing:set(not playback.playing:get())
- playback.position:set(playback.position:get() + 5)
+ playback.playing:set(not playback.playing:get())
end)
play_pause_btn:focus()
local play_pause_img = play_pause_btn:Image { src = img.pause }
@@ -183,7 +186,9 @@ return function(opts)
cur_time:set {
text = format_time(pos)
}
- scrubber:set { value = pos }
+ if not scrubber:is_dragged() then
+ scrubber:set { value = pos }
+ end
end),
playback.track:bind(function(track)
if not track then return end