summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-04-11 17:20:07 +1000
committerjacqueline <me@jacqueline.id.au>2024-04-11 17:20:41 +1000
commite34842516ec851647eb7be3c417b74fd5ae4b137 (patch)
tree59f4eb5f2a3a62634f3e30419f51f78c58c05ffa
parentdd1ea595a7753706d4fa5f19b66f3dc1cbd56a02 (diff)
downloadtangara-fw-e34842516ec851647eb7be3c417b74fd5ae4b137.tar.gz
show a preview of the new track position while scrubbing
-rw-r--r--lua/playing.lua26
1 files changed, 18 insertions, 8 deletions
diff --git a/lua/playing.lua b/lua/playing.lua
index c5f54b98..deee6987 100644
--- a/lua/playing.lua
+++ b/lua/playing.lua
@@ -16,6 +16,11 @@ local img = {
repeat_src = lvgl.ImgData("//lua/img/repeat.png"), -- repeat is a reserved word
}
+local format_time = function(time)
+ time = math.floor(time)
+ return string.format("%d:%02d", time // 60, time % 60)
+end
+
local is_now_playing_shown = false
local icon_enabled_class = "icon_enabled"
@@ -128,6 +133,16 @@ return screen:new {
if not track.duration then return end
playback.position:set(scrubber:value() / 100 * track.duration)
end)
+ scrubber:onevent(lvgl.EVENT.VALUE_CHANGED, function()
+ if scrubber:is_dragged() then
+ local track = playback.track:get()
+ if not track then return end
+ if not track.duration then return end
+ cur_time:set {
+ text = format_time(scrubber:value() / 100 * track.duration)
+ }
+ end
+ end)
local controls = self.root:Object {
flex = {
@@ -142,7 +157,6 @@ return screen:new {
pad_all = 2,
}
-
controls:Object({ flex_grow = 1, h = 1 }) -- spacer
local repeat_btn = controls:Button {}
@@ -187,10 +201,6 @@ return screen:new {
controls:Object({ flex_grow = 1, h = 1 }) -- spacer
- local format_time = function(time)
- return string.format("%d:%02d", time // 60, time % 60)
- end
-
self.bindings = {
playback.playing:bind(function(playing)
if playing then
@@ -201,10 +211,10 @@ return screen:new {
end),
playback.position:bind(function(pos)
if not pos then return end
- cur_time:set {
- text = format_time(pos)
- }
if not scrubber:is_dragged() then
+ cur_time:set {
+ text = format_time(pos)
+ }
local track = playback.track:get()
if not track then return end
if not track.duration then return end