Add next+prev buttons to the Now Playing screen.

custom
Robin Howard 1 year ago committed by Robin Howard
parent 429abd1237
commit 2f93ac3c59
  1. 39
      lua/playing.lua

@ -5,6 +5,15 @@ local font = require("font")
local playback = require("playback") local playback = require("playback")
local queue = require("queue") local queue = require("queue")
local img = {
play = "//lua/img/play.png",
pause = "//lua/img/pause.png",
next = "//lua/img/next.png",
next_disabled = "//lua/img/next_disabled.png",
prev = "//lua/img/prev.png",
prev_disabled = "//lua/img/prev_disabled.png",
}
return function(opts) return function(opts)
local screen = {} local screen = {}
screen.root = lvgl.Object(nil, { screen.root = lvgl.Object(nil, {
@ -106,19 +115,20 @@ return function(opts)
controls:Object({ flex_grow = 1, h = 1 }) -- spacer controls:Object({ flex_grow = 1, h = 1 }) -- spacer
controls:Image { local prev_btn = controls:Button {}
src = "//lua/img/prev.png", prev_btn:onClicked(queue.previous)
} local prev_img = prev_btn:Image { src = img.prev_disabled }
local play_pause_btn = controls:Button {} local play_pause_btn = controls:Button {}
play_pause_btn:onClicked(function() play_pause_btn:onClicked(function()
playback.playing:set(not playback.playing:get()) playback.playing:set(not playback.playing:get())
end) end)
local play_pause_img = play_pause_btn:Image { local play_pause_img = play_pause_btn:Image { src = img.pause }
src = "//lua/img/pause.png",
} local next_btn = controls:Button {}
controls:Image { next_btn:onClicked(queue.next)
src = "//lua/img/next.png", local next_img = next_btn:Image { src = img.next_disabled }
}
controls:Object({ flex_grow = 1, h = 1 }) -- spacer controls:Object({ flex_grow = 1, h = 1 }) -- spacer
local end_time = controls:Label { local end_time = controls:Label {
@ -136,9 +146,9 @@ return function(opts)
screen.bindings = { screen.bindings = {
playback.playing:bind(function(playing) playback.playing:bind(function(playing)
if playing then if playing then
play_pause_img:set_src("//lua/img/pause.png") play_pause_img:set_src(img.pause)
else else
play_pause_img:set_src("//lua/img/play.png") play_pause_img:set_src(img.play)
end end
end), end),
playback.position:bind(function(pos) playback.position:bind(function(pos)
@ -162,6 +172,13 @@ return function(opts)
queue.position:bind(function(pos) queue.position:bind(function(pos)
if not pos then return end if not pos then return end
playlist_pos:set { text = tostring(pos) } playlist_pos:set { text = tostring(pos) }
next_img:set_src(
pos < queue.size:get() and img.next or img.next_disabled
)
prev_img:set_src(
pos > 1 and img.prev or img.prev_disabled
)
end), end),
queue.size:bind(function(num) queue.size:bind(function(num)
if not num then return end if not num then return end

Loading…
Cancel
Save