Minor refactoring
All checks were successful
Build and Publish WASM version of demo / Build-And-Deploy (push) Successful in 17s

Prevent creating a screen-less PendingAction with invalid type.
This commit is contained in:
Stephen Seo 2023-08-17 16:07:09 +09:00
parent 89e19cf084
commit ff03f30809

View file

@ -14,7 +14,21 @@ Screen::Screen(std::weak_ptr<ScreenStack> stack) : stack(stack) {}
ScreenStack::PendingAction::PendingAction() : screen(), action(Action::NOP) {} ScreenStack::PendingAction::PendingAction() : screen(), action(Action::NOP) {}
ScreenStack::PendingAction::PendingAction(Action action) ScreenStack::PendingAction::PendingAction(Action action)
: screen(), action(action) {} : screen(), action(action) {
switch (action) {
case Action::PUSH_SCREEN:
case Action::CONSTRUCT_SCREEN:
// Cannot push non-existant screen.
this->action = Action::NOP;
#ifndef NDEBUG
std::clog << "WARNING: Cannot create PendingAction with PUSH_SCREEN or "
"CONSTRUCT_SCREEN!\n";
#endif
break;
default:
break;
}
}
ScreenStack::PendingAction::PendingAction(Screen::Ptr &&screen) ScreenStack::PendingAction::PendingAction(Screen::Ptr &&screen)
: screen(std::forward<Screen::Ptr>(screen)), action(Action::PUSH_SCREEN) {} : screen(std::forward<Screen::Ptr>(screen)), action(Action::PUSH_SCREEN) {}