fixed screen dying on popup open
authorDaniel Liu <mr.picklepinosaur@gmail.com>
Sat, 3 Apr 2021 00:03:09 +0000 (20:03 -0400)
committerDaniel Liu <mr.picklepinosaur@gmail.com>
Sat, 3 Apr 2021 00:03:09 +0000 (20:03 -0400)
headers/menu.h
headers/render.h
menu.c
render.c
taskasaur.c

index 0b952a5..8c5cdbb 100644 (file)
@@ -31,7 +31,8 @@ extern Menu* create_menu(char* menu_name, MenuItem** item_list);
 
 extern WINDOW* get_menu_win(Menu* menu);
 extern MenuItem* get_menu_item(Menu* menu, int index);
-extern int get_selected_item(Menu* menu);
+extern int get_selected_item(Menu* menu); // rename this to selected_index or sm
+extern MenuItem* get_selected_menuitem(Menu* menu);
 extern bool get_menu_focused(Menu* menu);
 extern int get_menu_length(Menu* menu);
 extern char* get_menu_name(Menu* menu);
index b9af53b..165f74b 100644 (file)
@@ -55,7 +55,7 @@ extern int update_menuitem_descrip(MenuItem* menuitem);
 /* popup menu for menu item */
 extern PopupMenu* make_popupmenu(TodoItem* itemdata);
 extern WINDOW* create_popup_win(TodoItem* item_info);
-extern int render_popupmenu(PopupMenu* popupmenu);
+extern void save_popupmenu_state(Menu* popupmenu_menu);
 extern MenuItem** subtasklist_to_menuitem(SubTask** subtask_list, int list_length);
 
 /* some helpers */
diff --git a/menu.c b/menu.c
index 7c3b510..a4a1639 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -120,6 +120,12 @@ get_selected_item(Menu* menu)
     return menu->selected_item;
 }
 
+MenuItem*
+get_selected_menuitem(Menu* menu)
+{
+    return get_menu_item(menu, get_selected_item(menu));
+}
+
 bool
 get_menu_focused(Menu* menu)
 {
index 4ffd27f..7187ec2 100644 (file)
--- a/render.c
+++ b/render.c
@@ -407,13 +407,17 @@ popup_menuitem_height(MenuItem* menuitem)
     return 1; // account for wrap later
 }
 
-int
-render_popupmenu(PopupMenu* popupmenu)
+/* save menu state to userdata */
+/* sorta duct tape rn */
+/* find a way to tie TodoItem and MenuItem together better in the future */
+void
+save_popupmenu_state(Menu* popupmenu_menu)
 {
-    render_menu(popupmenu->menu);
-    wrefresh(popupmenu->win);
+    /* TodoItem* item_data; */
+
+    /* item_data = get_menu_userdata(popupmenu_menu); */
+    /* item_data->subtask_count = array_length(SubTask*, item_data->subtask_list); */
 
-    return 0;
 }
 
 /* this is copy paste of other, prob abstract */
index 3d787e6..8c44d26 100644 (file)
@@ -11,8 +11,7 @@ void normal_handleinput(BoardMenu* boardmenu, int ch);
 void popup_handleinput(BoardMenu* boardmenu, int ch);
 void generic_handleinput(Menu* menu, int ch);
 
-void normal_renderstep(BoardMenu* boardmenu);
-void popup_renderstep(BoardMenu* boardmenu);
+void renderstep(BoardMenu* boardmenu);
 void save_to_file(char* filepath, BoardMenu* boardmenu);
 
 void exit_step(BoardMenu* boardmenu);
@@ -34,21 +33,21 @@ main(int argc, char** argv)
     boardmenu = create_board_menu(board);
 
     /* need to render before user presses anything */
-    normal_renderstep(boardmenu);
+    renderstep(boardmenu);
 
     int ch;
     while (1) {
-        
+
         ch = getch();
 
         if (boardmenu->popup_open == 0) {
             normal_handleinput(boardmenu, ch);
-            normal_renderstep(boardmenu);
         } else {
             popup_handleinput(boardmenu, ch);
-            popup_renderstep(boardmenu);
         }
 
+        renderstep(boardmenu);
+
     }
     
     /* save on exit - this causes weird stuff to happen, maybe it's not given enough time to write before program exits? */
@@ -86,10 +85,7 @@ normal_handleinput(BoardMenu* boardmenu, int ch)
 
                 insert_item(
                     to_menu,
-                    get_menu_item(
-                        from_menu,
-                        get_selected_item(from_menu)
-                    ),
+                    get_selected_menuitem(from_menu),
                     min(
                         get_selected_item(from_menu),
                         get_menu_length(to_menu)
@@ -116,10 +112,7 @@ normal_handleinput(BoardMenu* boardmenu, int ch)
 
                 insert_item(
                     to_menu,
-                    get_menu_item(
-                        from_menu,
-                        get_selected_item(from_menu)
-                    ),
+                    get_selected_menuitem(from_menu),
                     min(
                         get_selected_item(from_menu),
                         get_menu_length(to_menu)
@@ -161,6 +154,7 @@ normal_handleinput(BoardMenu* boardmenu, int ch)
                 /* set mode to popup */
                 boardmenu->popupmenu = make_popupmenu(sel_itemdata);
                 boardmenu->popup_open = 1;
+
             } 
 
             break;
@@ -198,13 +192,17 @@ popup_handleinput(BoardMenu* boardmenu, int ch)
 
         case BINDING_QUIT:
             boardmenu->popup_open = 0;
+            
+            /* reset screen */
             clear();
+            renderstep(boardmenu);
             break;
 
         case BINDING_TOGGLE_DONE:
             {
                 SubTask* curitem_data = (SubTask*)get_menuitem_userdata(get_menu_item(popupmenu_menu, get_selected_item(popupmenu_menu))); 
                 curitem_data->done = (curitem_data->done == SubTaskState_todo) ? SubTaskState_done : SubTaskState_todo;
+                /* save_popupmenu_state(popupmenu_menu); */
             }
 
             break;
@@ -256,27 +254,28 @@ generic_handleinput(Menu* menu, int ch)
 }
 
 void
-normal_renderstep(BoardMenu* boardmenu)
+renderstep(BoardMenu* boardmenu)
 {
-    for (int i = 0; i < boardmenu->menu_count; i++) {
+    /* render main board menu */
+    if (boardmenu->popup_open == 0) {
+        for (int i = 0; i < boardmenu->menu_count; i++) {
 
-        Menu* curmenu = boardmenu->menu_list[i];
+            Menu* curmenu = boardmenu->menu_list[i];
 
-        /* update the descriptions - maybe not do this here */ 
-        for (int j = 0; j < get_menu_length(curmenu); j++) {
-            update_menuitem_descrip(get_menu_item(curmenu, j));
+            render_menu(curmenu);
         }
 
-        render_menu(curmenu);
-    }
-}
+    /* render popup if it's open */
+    } else {
 
-void
-popup_renderstep(BoardMenu* boardmenu)
-{
-    if (boardmenu->popupmenu == NULL) return;
+        // something weird happened, maybe raise error
+        /* if (boradmenu->popupmenu == NULL) return; */
 
-    render_popupmenu(boardmenu->popupmenu); 
+        render_menu(boardmenu->popupmenu->menu);
+        wrefresh(boardmenu->popupmenu->win);
+
+    }
+    refresh();
 }
 
 void