From: Daniel Date: Wed, 31 Mar 2021 21:26:06 +0000 (-0400) Subject: calling render callbacks from render.c X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=8dc5ccc88d4e0976ca44ed53f50e769905115db1;p=taskasaur.git calling render callbacks from render.c --- diff --git a/headers/menu.h b/headers/menu.h index 63a410f..0b952a5 100644 --- a/headers/menu.h +++ b/headers/menu.h @@ -32,6 +32,7 @@ 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 bool get_menu_focused(Menu* menu); extern int get_menu_length(Menu* menu); extern char* get_menu_name(Menu* menu); extern void* get_menu_userdata(Menu* menu); diff --git a/menu.c b/menu.c index da064ba..8b46187 100644 --- a/menu.c +++ b/menu.c @@ -120,6 +120,12 @@ get_selected_item(Menu* menu) return menu->selected_item; } +bool +get_menu_focused(Menu* menu) +{ + return menu->focused; +} + int get_menu_length(Menu* menu) { @@ -418,6 +424,7 @@ default_render_item(Menu* menu, int item_index, int start_y) { MenuItem* curitem; int hlcolor; + curitem = menu->menu_items[item_index]; /* color selected item */ @@ -425,31 +432,8 @@ default_render_item(Menu* menu, int item_index, int start_y) wattron(menu->menu_win, hlcolor); mvwprintw(menu->menu_win, start_y, 0, curitem->title); wattroff(menu->menu_win, hlcolor); - } -/* int */ -/* default_render_item(Menu* menu, int item_index, int start_y) */ -/* { */ -/* MenuItem* curitem; */ -/* int hlcolor; */ -/* curitem = menu->menu_items[item_index]; */ - -/* /1* color selected item *1/ */ -/* hlcolor = COLOR_PAIR((item_index == menu->selected_item && menu->focused == true) ? TS_SELECTED : TS_NONSELECTED); */ -/* wattron(menu->menu_win, hlcolor); */ -/* mvwprintw(menu->menu_win, start_y, 0, curitem->title); */ -/* wattroff(menu->menu_win, hlcolor); */ - -/* /1* display number of items *1/ */ -/* if (strlen(curitem->description) > 0) { */ -/* wattron(menu->menu_win, COLOR_PAIR(TS_ITEMCOUNT)); */ -/* mvwprintw(menu->menu_win, start_y+1, 0, curitem->description); */ -/* wattroff(menu->menu_win, COLOR_PAIR(TS_ITEMCOUNT)); */ -/* } */ - -/* return item_height(curitem); */ -/* } */ int default_item_height(MenuItem* menuitem) diff --git a/render.c b/render.c index 0c0270e..8c95642 100644 --- a/render.c +++ b/render.c @@ -11,6 +11,10 @@ int init_tscolors(void); int create_todowin(void); +/* menu render callbacks */ +void render_menuitem(Menu* menu, int item_index, int start_y); +int menuitem_height(MenuItem* menuitem); + /* init stuff */ int init_tscurses(void) @@ -120,6 +124,10 @@ make_menus(Board* board, int todolist_length) set_menu_win(new_menu, win); set_menu_focus(new_menu, i == 0); // make first win focused + /* set menu render callbacks */ + set_menu_renderitem(new_menu, *render_menuitem); + set_menu_itemheight(new_menu, *menuitem_height); + /* refresh */ refresh(); wrefresh(win); @@ -130,6 +138,44 @@ make_menus(Board* board, int todolist_length) return menu_list; } +void +render_menuitem(Menu* menu, int item_index, int start_y) +{ + MenuItem* curitem; + WINDOW* menu_win; + int hlcolor; + + curitem = get_menu_item(menu, item_index); + menu_win = get_menu_win(menu); + + /* color selected item */ + hlcolor = COLOR_PAIR((item_index == get_selected_item(menu) && get_menu_focused(menu) == true) ? TS_SELECTED : TS_NONSELECTED); + wattron(menu_win, hlcolor); + mvwprintw(menu_win, start_y, 0, get_menuitem_title(curitem)); + wattroff(menu_win, hlcolor); + + /* display number of items */ + if (strlen(get_menuitem_descrip(curitem)) > 0) { + wattron(menu_win, COLOR_PAIR(TS_ITEMCOUNT)); + mvwprintw(menu_win, start_y+1, 0, get_menuitem_descrip(curitem)); + wattroff(menu_win, COLOR_PAIR(TS_ITEMCOUNT)); + } + +} + +int +menuitem_height(MenuItem* menuitem) +{ + int lines; + + lines = 1; + if (strlen(get_menuitem_descrip(menuitem)) > 0) { + lines += 1; + } + + return lines; +} + MenuItem** todolist_to_menuitem(TodoItem** item_list, int list_length) {