]> git.seodisparate.com - jumpartifact.com_demo_0/commitdiff
Add ScreenStack::clear_screens()
authorStephen Seo <seo.disparate@gmail.com>
Tue, 1 Aug 2023 08:55:30 +0000 (17:55 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Tue, 1 Aug 2023 08:55:30 +0000 (17:55 +0900)
src/screen.cc
src/screen.h

index 5d1bf4a8e51cb759b5ab9727e065446e64482167..290760833f5b873db765dfc776dc4930d64a9279 100644 (file)
@@ -56,6 +56,10 @@ void ScreenStack::pop_screen() {
   actions.push_back(PendingAction(Action::POP_SCREEN));
 }
 
+void ScreenStack::clear_screens() {
+  actions.push_back(PendingAction(Action::CLEAR_SCREENS));
+}
+
 ScreenStack::ScreenStack() : self_weak(), stack(), actions() {}
 
 void ScreenStack::handle_pending_actions() {
@@ -74,6 +78,14 @@ void ScreenStack::handle_pending_actions() {
         }
 #endif  // NDEBUG
         break;
+      case Action::CLEAR_SCREENS:
+#ifndef NDEBUG
+        if (stack.empty()) {
+          std::cerr << "WARNING: Clearing an empty screen stack!\n";
+        }
+#endif
+        stack.clear();
+        break;
       case Action::NOP:
         // Intentionally left blank.
         break;
index fb11512a2707142ddef6f3353927694b0deeb78f..f9f9e7b5f96d6195852e9d43fe56013c6cfefeaa 100644 (file)
@@ -37,7 +37,7 @@ class Screen {
 
 class ScreenStack {
  private:
-  enum Action { PUSH_SCREEN, POP_SCREEN, NOP };
+  enum Action { PUSH_SCREEN, POP_SCREEN, CLEAR_SCREENS, NOP };
 
   struct PendingAction {
     PendingAction();
@@ -80,6 +80,8 @@ class ScreenStack {
 
   void pop_screen();
 
+  void clear_screens();
+
  private:
   ScreenStack();