Add support for screens declaring that they can't be popped

Needed as prep for usb msc support; you really shouldn't leave the MSC
settings screen until you've disabled usb msc.
custom
jacqueline 1 year ago
parent 21ae6a9626
commit 684ff50ef4
  1. 14
      src/lua/lua_screen.cpp
  2. 2
      src/ui/include/screen.hpp
  3. 2
      src/ui/include/screen_lua.hpp
  4. 2
      src/ui/include/screen_splash.hpp
  5. 19
      src/ui/screen_lua.cpp
  6. 3
      src/ui/ui_fsm.cpp

@ -50,11 +50,15 @@ static auto screen_noop(lua_State* state) -> int {
return 0; return 0;
} }
static const struct luaL_Reg kScreenFuncs[] = {{"new", screen_new}, static auto screen_true(lua_State* state) -> int {
{"createUi", screen_noop}, lua_pushboolean(state, true);
{"onShown", screen_noop}, return 1;
{"onHidden", screen_noop}, }
{NULL, NULL}};
static const struct luaL_Reg kScreenFuncs[] = {
{"new", screen_new}, {"createUi", screen_noop},
{"onShown", screen_noop}, {"onHidden", screen_noop},
{"canPop", screen_true}, {NULL, NULL}};
static auto lua_screen(lua_State* state) -> int { static auto lua_screen(lua_State* state) -> int {
luaL_newlib(state, kScreenFuncs); luaL_newlib(state, kScreenFuncs);

@ -43,6 +43,8 @@ class Screen {
return group_; return group_;
} }
virtual auto canPop() -> bool = 0;
protected: protected:
lv_obj_t* const root_; lv_obj_t* const root_;
lv_obj_t* content_; lv_obj_t* content_;

@ -21,6 +21,8 @@ class Lua : public Screen {
auto onShown() -> void override; auto onShown() -> void override;
auto onHidden() -> void override; auto onHidden() -> void override;
auto canPop() -> bool override;
auto SetObjRef(lua_State*) -> void; auto SetObjRef(lua_State*) -> void;
private: private:

@ -20,6 +20,8 @@ class Splash : public Screen {
Splash(); Splash();
~Splash(); ~Splash();
auto canPop() -> bool override { return false; }
private: private:
lv_obj_t* container_; lv_obj_t* container_;
lv_obj_t* label_; lv_obj_t* label_;

@ -58,6 +58,25 @@ auto Lua::onHidden() -> void {
lua_pop(s_, 1); lua_pop(s_, 1);
} }
auto Lua::canPop() -> bool {
if (!s_ || !obj_ref_) {
return true;
}
lua_rawgeti(s_, LUA_REGISTRYINDEX, *obj_ref_);
lua_pushliteral(s_, "canPop");
if (lua_gettable(s_, -2) == LUA_TFUNCTION) {
// If we got a callback instead of a value, then invoke it to turn it into
// value.
lua_pushvalue(s_, -2);
lua::CallProtected(s_, 1, 1);
}
bool ret = lua_toboolean(s_, -1);
lua_pop(s_, 2);
return ret;
}
auto Lua::SetObjRef(lua_State* s) -> void { auto Lua::SetObjRef(lua_State* s) -> void {
assert(s_ == nullptr); assert(s_ == nullptr);
s_ = s; s_ = s;

@ -610,6 +610,9 @@ auto Lua::QueuePrevious(lua_State*) -> int {
} }
auto Lua::PopLuaScreen(lua_State* s) -> int { auto Lua::PopLuaScreen(lua_State* s) -> int {
if (!sCurrentScreen->canPop()) {
return 0;
}
PopScreen(); PopScreen();
luavgl_set_root(s, sCurrentScreen->content()); luavgl_set_root(s, sCurrentScreen->content());
lv_group_set_default(sCurrentScreen->group()); lv_group_set_default(sCurrentScreen->group());

Loading…
Cancel
Save