From: Daniel Date: Tue, 30 Mar 2021 01:34:40 +0000 (-0400) Subject: popup win rendering X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=0b8a464220518abd203044984daaed9727a5029d;p=taskasaur.git popup win rendering --- diff --git a/headers/render.h b/headers/render.h index a241620..b9af53b 100644 --- a/headers/render.h +++ b/headers/render.h @@ -19,11 +19,16 @@ enum TaskasaurColors { TS_ITEMCOUNT }; +typedef struct PopupMenu { + WINDOW* win; + Menu* menu; +} PopupMenu; + typedef struct BoardMenu { Menu** menu_list; int menu_count; int selected; - Menu* popup_menu; + PopupMenu* popupmenu; int popup_open; } BoardMenu; @@ -48,9 +53,9 @@ extern int swap_menu(BoardMenu* boardmenu, int src_index, int dest_index); extern int update_menuitem_descrip(MenuItem* menuitem); /* popup menu for menu item */ -extern Menu* make_popup_menu(TodoItem* itemdata); +extern PopupMenu* make_popupmenu(TodoItem* itemdata); extern WINDOW* create_popup_win(TodoItem* item_info); -extern int render_popup_menu(Menu* popup_menu); +extern int render_popupmenu(PopupMenu* popupmenu); extern MenuItem** subtasklist_to_menuitem(SubTask** subtask_list, int list_length); /* some helpers */ diff --git a/menu.c b/menu.c index abb2fdf..374ccaf 100644 --- a/menu.c +++ b/menu.c @@ -161,7 +161,6 @@ set_menu_win(Menu* menu, WINDOW* win) menu->menu_win = win; getmaxyx(menu->menu_win, height, width); - /* create a subwin (also prob free old subwin?) */ menu->max_height = height-MENU_PAD_TOP-MENU_PAD_BOTTOM; menu->max_width = width-MENU_PAD_LEFT-MENU_PAD_RIGHT; @@ -389,7 +388,6 @@ render_menu(Menu* menu) curline += render_item(menu, i, curline); } - wrefresh(menu->menu_win); wrefresh(menu->menu_win); return 0; diff --git a/render.c b/render.c index 2f9261c..4601ce9 100644 --- a/render.c +++ b/render.c @@ -3,6 +3,11 @@ #include #include "config.h" +#define POPUP_MENU_PAD_TOP 2 +#define POPUP_MENU_PAD_BOTTOM 2 +#define POPUP_MENU_PAD_LEFT 2 +#define POPUP_MENU_PAD_RIGHT 1 + int init_tscolors(void); int create_todowin(void); @@ -85,7 +90,7 @@ create_board_menu(Board* board) new_boardmenu->menu_list = make_menus(board, board->todolist_count); new_boardmenu->menu_count = board->todolist_count; new_boardmenu->selected = 0; - new_boardmenu->popup_menu = NULL; + new_boardmenu->popupmenu = NULL; new_boardmenu->popup_open = 0; return new_boardmenu; @@ -301,43 +306,58 @@ update_menuitem_descrip(MenuItem* menuitem) } /* popup */ -Menu* -make_popup_menu(TodoItem* itemdata) +PopupMenu* +make_popupmenu(TodoItem* itemdata) { + PopupMenu* new_popupmenu; MenuItem** subtask_menuitems; - Menu* new_popup_menu; - WINDOW* popup_win; + Menu* popupmenu_menu; + WINDOW* popupmenu_win; + WINDOW* popupmenu_menu_win; + + new_popupmenu = malloc(sizeof(PopupMenu)); subtask_menuitems = subtasklist_to_menuitem(itemdata->subtask_list, itemdata->subtask_count); - new_popup_menu = create_menu(strdup(""), subtask_menuitems); + popupmenu_menu = create_menu(strdup(""), subtask_menuitems); /* popup win */ int maxheight, maxwidth; getmaxyx(stdscr, maxheight, maxwidth); - popup_win = newwin( + popupmenu_win = newwin( maxheight-2*POPUP_BORDER, maxwidth-2*2*POPUP_BORDER, POPUP_BORDER, POPUP_BORDER*2 ); - set_menu_win(new_popup_menu, popup_win); - set_menu_focus(new_popup_menu, 1); + int popup_maxheight, popup_maxwidth; + getmaxyx(popupmenu_win, popup_maxheight, popup_maxwidth); + popupmenu_menu_win = derwin( + popupmenu_win, + popup_maxheight-POPUP_MENU_PAD_TOP-POPUP_MENU_PAD_BOTTOM, + popup_maxwidth-POPUP_MENU_PAD_LEFT-POPUP_MENU_PAD_RIGHT, + POPUP_MENU_PAD_TOP, + POPUP_MENU_PAD_LEFT + ); + + 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); - return new_popup_menu; + /* don't forget to free popupmenu after */ + new_popupmenu->win = popupmenu_win; + new_popupmenu->menu = popupmenu_menu; + + return new_popupmenu; } int -render_popup_menu(Menu* popup_menu) +render_popupmenu(PopupMenu* popupmenu) { - WINDOW* popup_win; - - popup_win = get_menu_win(popup_menu); - wclear(popup_win); - - render_menu(popup_menu); + render_menu(popupmenu->menu); - wrefresh(popup_win); + wrefresh(popupmenu->win); return 0; } diff --git a/taskasaur.c b/taskasaur.c index 8ebd419..62adc7d 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -191,7 +191,7 @@ normal_handleinput(BoardMenu* boardmenu, int ch) ); /* set mode to popup */ - boardmenu->popup_menu = make_popup_menu(sel_itemdata); + boardmenu->popupmenu = make_popupmenu(sel_itemdata); boardmenu->popup_open = 1; } @@ -218,17 +218,17 @@ normal_handleinput(BoardMenu* boardmenu, int ch) void popup_handleinput(BoardMenu* boardmenu, int ch) { - Menu* popup_menu; + Menu* popupmenu_menu; - popup_menu = boardmenu->popup_menu; + popupmenu_menu = boardmenu->popupmenu->menu; switch (ch) { case BINDING_SCROLL_UP: - menu_driver(popup_menu, MENU_UP); + menu_driver(popupmenu_menu, MENU_UP); break; case BINDING_SCROLL_DOWN: - menu_driver(popup_menu, MENU_DOWN); + menu_driver(popupmenu_menu, MENU_DOWN); break; case BINDING_QUIT: boardmenu->popup_open = 0; @@ -255,10 +255,9 @@ normal_renderstep(BoardMenu* boardmenu) void popup_renderstep(BoardMenu* boardmenu) { - if (boardmenu->popup_menu == NULL) return; - - render_popup_menu(boardmenu->popup_menu); + if (boardmenu->popupmenu == NULL) return; + render_popupmenu(boardmenu->popupmenu); } void