From: Daniel Date: Tue, 30 Mar 2021 20:08:14 +0000 (-0400) Subject: abstract menu driver a bit X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=dd1e302d132c07167c4a9b9d1803918d599a72ab;p=taskasaur.git abstract menu driver a bit --- diff --git a/render.c b/render.c index 4601ce9..71d675e 100644 --- a/render.c +++ b/render.c @@ -343,7 +343,9 @@ make_popupmenu(TodoItem* itemdata) set_menu_win(popupmenu_menu, popupmenu_menu_win); set_menu_focus(popupmenu_menu, 1); box(popupmenu_win, 0, 0); - box(popupmenu_menu_win, 0, 0); + + /* move this stuff to render phase later? */ + mvwprintw(popupmenu_win, 1, 2, itemdata->item_name); /* don't forget to free popupmenu after */ new_popupmenu->win = popupmenu_win; @@ -356,7 +358,6 @@ int render_popupmenu(PopupMenu* popupmenu) { render_menu(popupmenu->menu); - wrefresh(popupmenu->win); return 0; diff --git a/taskasaur.c b/taskasaur.c index 62adc7d..100430e 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -9,6 +9,7 @@ char* boardfile_name = "test_board.md"; 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); @@ -65,12 +66,6 @@ normal_handleinput(BoardMenu* boardmenu, int ch) switch (ch) { - case BINDING_SCROLL_UP: - menu_driver(active_menu, MENU_UP); - break; - case BINDING_SCROLL_DOWN: - menu_driver(active_menu, MENU_DOWN); - break; case BINDING_SCROLL_LEFT: if (boardmenu->selected-1 < 0) break; set_selected_menu(boardmenu, boardmenu->selected-1); @@ -79,18 +74,6 @@ normal_handleinput(BoardMenu* boardmenu, int ch) if (boardmenu->selected+1 > boardmenu->menu_count-1) break; set_selected_menu(boardmenu, boardmenu->selected+1); break; - case BINDING_JUMP_TOP: - menu_driver(active_menu, MENU_TOP); - break; - case BINDING_JUMP_BOTTOM: - menu_driver(active_menu, MENU_BOTTOM); - break; - case BINDING_MOVE_ITEM_UP: - menu_driver(active_menu, MENU_MOVE_UP); - break; - case BINDING_MOVE_ITEM_DOWN: - menu_driver(active_menu, MENU_MOVE_DOWN); - break; case BINDING_MOVE_ITEM_LEFT: if (boardmenu->selected-1 < 0) break; if (get_menu_length(boardmenu->menu_list[boardmenu->selected]) == 0) break; @@ -149,18 +132,6 @@ normal_handleinput(BoardMenu* boardmenu, int ch) set_selected_menu(boardmenu, boardmenu->selected+1); } - break; - case BINDING_DELETE_ITEM: - menu_driver(active_menu, MENU_DELETE); - break; - case BINDING_APPEND_ITEM: - menu_driver(active_menu, MENU_APPEND); - break; - case BINDING_INSERT_ABOVE: - menu_driver(active_menu, MENU_INSERT_ABOVE); - break; - case BINDING_INSERT_BELOW: - menu_driver(active_menu, MENU_INSERT_BELOW); break; /* case BINDING_MOVE_MENU_LEFT: */ /* if (boardmenu->selected-1 < 0) break; */ @@ -177,9 +148,6 @@ normal_handleinput(BoardMenu* boardmenu, int ch) /* set_selected_menu(boardmenu, boardmenu->selected); */ /* break; */ - case BINDING_EDIT_ITEM: - menu_driver(active_menu, MENU_EDIT); - break; case BINDING_SELECT: { Menu* sel_menu; @@ -212,6 +180,10 @@ normal_handleinput(BoardMenu* boardmenu, int ch) /* mvprintw(20, 20, out); */ /* resize_term(y, x); */ break; + + default: + generic_handleinput(active_menu, ch); + } } @@ -222,18 +194,57 @@ popup_handleinput(BoardMenu* boardmenu, int ch) popupmenu_menu = boardmenu->popupmenu->menu; + switch (ch) { + + case BINDING_QUIT: + boardmenu->popup_open = 0; + clear(); + break; + + default: + generic_handleinput(popupmenu_menu, ch); + } +} + +void +generic_handleinput(Menu* menu, int ch) +{ switch (ch) { case BINDING_SCROLL_UP: - menu_driver(popupmenu_menu, MENU_UP); + menu_driver(menu, MENU_UP); break; case BINDING_SCROLL_DOWN: - menu_driver(popupmenu_menu, MENU_DOWN); + menu_driver(menu, MENU_DOWN); break; - case BINDING_QUIT: - boardmenu->popup_open = 0; + case BINDING_JUMP_TOP: + menu_driver(menu, MENU_TOP); break; - } + case BINDING_JUMP_BOTTOM: + menu_driver(menu, MENU_BOTTOM); + break; + case BINDING_MOVE_ITEM_UP: + menu_driver(menu, MENU_MOVE_UP); + break; + case BINDING_MOVE_ITEM_DOWN: + menu_driver(menu, MENU_MOVE_DOWN); + break; + case BINDING_DELETE_ITEM: + menu_driver(menu, MENU_DELETE); + break; + case BINDING_APPEND_ITEM: + menu_driver(menu, MENU_APPEND); + break; + case BINDING_INSERT_ABOVE: + menu_driver(menu, MENU_INSERT_ABOVE); + break; + case BINDING_INSERT_BELOW: + menu_driver(menu, MENU_INSERT_BELOW); + break; + case BINDING_EDIT_ITEM: + menu_driver(menu, MENU_EDIT); + break; + } } void