diff --git a/lua/playing.lua b/lua/playing.lua index a183e1ab..fab3f394 100644 --- a/lua/playing.lua +++ b/lua/playing.lua @@ -107,7 +107,11 @@ return function(opts) controls:Image { src = "//lua/img/prev.png", } - local play_pause_img = controls:Image { + local play_pause_btn = controls:Button {} + play_pause_btn:onClicked(function() + playback.playing:set(not playback.playing:get()) + end) + local play_pause_img = play_pause_btn:Image { src = "//lua/img/pause.png", } controls:Image { diff --git a/src/lua/include/property.hpp b/src/lua/include/property.hpp index 207696bd..c1dcf44b 100644 --- a/src/lua/include/property.hpp +++ b/src/lua/include/property.hpp @@ -26,6 +26,8 @@ class Property { Property(const LuaValue&); Property(const LuaValue&, std::function); + auto Get() -> const LuaValue& { return value_; } + auto IsTwoWay() -> bool { return cb_.has_value(); } auto PushValue(lua_State& s) -> int; diff --git a/src/lua/property.cpp b/src/lua/property.cpp index 3e492237..b424a866 100644 --- a/src/lua/property.cpp +++ b/src/lua/property.cpp @@ -221,7 +221,7 @@ auto Property::PopValue(lua_State& s) -> bool { } break; case LUA_TBOOLEAN: - new_val = lua_toboolean(&s, 2); + new_val = static_cast(lua_toboolean(&s, 2)); break; case LUA_TSTRING: new_val = lua_tostring(&s, 2); diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index 9f530d71..a8291a46 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -136,6 +136,7 @@ class Lua : public UiState { private: auto PushLuaScreen(lua_State*) -> int; auto PopLuaScreen(lua_State*) -> int; + auto SetPlaying(const lua::LuaValue&) -> bool; std::shared_ptr battery_pct_; std::shared_ptr battery_mv_; diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index 557dc1a3..539cbc9b 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -7,6 +7,7 @@ #include "ui_fsm.hpp" #include +#include #include "lua.h" #include "lua.hpp" @@ -179,7 +180,8 @@ void Lua::entry() { queue_position_ = std::make_shared(0); queue_size_ = std::make_shared(0); - playback_playing_ = std::make_shared(false); + playback_playing_ = std::make_shared( + false, [&](const lua::LuaValue& val) { return SetPlaying(val); }); playback_track_ = std::make_shared(); playback_position_ = std::make_shared(); @@ -250,6 +252,18 @@ auto Lua::PopLuaScreen(lua_State* s) -> int { return 0; } +auto Lua::SetPlaying(const lua::LuaValue& val) -> bool { + bool current_val = std::get(playback_playing_->Get()); + if (!std::holds_alternative(val)) { + return false; + } + bool new_val = std::get(val); + if (current_val != new_val) { + events::Audio().Dispatch(audio::TogglePlayPause{}); + } + return true; +} + void Lua::exit() { lv_group_set_default(NULL); }