diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-04-11 17:20:07 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-04-11 17:20:41 +1000 |
| commit | e34842516ec851647eb7be3c417b74fd5ae4b137 (patch) | |
| tree | 59f4eb5f2a3a62634f3e30419f51f78c58c05ffa /lua/playing.lua | |
| parent | dd1ea595a7753706d4fa5f19b66f3dc1cbd56a02 (diff) | |
| download | tangara-fw-e34842516ec851647eb7be3c417b74fd5ae4b137.tar.gz | |
show a preview of the new track position while scrubbing
Diffstat (limited to 'lua/playing.lua')
| -rw-r--r-- | lua/playing.lua | 26 |
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 |
