X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=render.c;h=7187ec2e66d8ec052fdfd91a5972eea07a84984b;hb=8276ee5a5a1262b062d39c627c8c1abf9568c4fa;hp=3779273f55ad6436ddc76ea5c121ad14bceff1cb;hpb=2239977d543e94803e2b0ecb07021152498350c8;p=taskasaur.git diff --git a/render.c b/render.c index 3779273..7187ec2 100644 --- a/render.c +++ b/render.c @@ -147,10 +147,12 @@ render_menuitem(Menu* menu, int item_index, int start_y) { MenuItem* curitem; WINDOW* menu_win; + TodoItem* item_data; int hlcolor; curitem = get_menu_item(menu, item_index); menu_win = get_menu_win(menu); + item_data = (TodoItem*)get_menuitem_userdata(curitem); /* color selected item */ hlcolor = COLOR_PAIR((item_index == get_selected_item(menu) && get_menu_focused(menu) == true) ? TS_SELECTED : TS_NONSELECTED); @@ -158,22 +160,34 @@ render_menuitem(Menu* menu, int item_index, int start_y) 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)); + /* item tag line */ + wmove(menu_win, start_y+1, 0); + wattron(menu_win, COLOR_PAIR(TS_ITEMCOUNT)); + /* display tiny character to indicate item has a descrip */ + if (strlen(item_data->description) > 0) { + wprintw(menu_win, "# "); } - + /* display number of complete tasks */ + if (item_data->subtask_count > 0) { + int tasks_complete = 0; + for (int i = 0; i < item_data->subtask_count; i++) { + if (item_data->subtask_list[i]->done == SubTaskState_done) + tasks_complete += 1; + } + wprintw(menu_win, "[%d/%d]", tasks_complete, item_data->subtask_count); + } + wattroff(menu_win, COLOR_PAIR(TS_ITEMCOUNT)); } int menuitem_height(MenuItem* menuitem) { + TodoItem* item_data; int lines; + item_data = get_menuitem_userdata(menuitem); lines = 1; - if (strlen(get_menuitem_descrip(menuitem)) > 0) { + if (item_data->subtask_count > 0 || strlen(item_data->description) > 0) { lines += 1; } @@ -309,52 +323,6 @@ swap_menu(BoardMenu* boardmenu, int src_index, int dest_index) return 0; } -/* menuitem */ -int -update_menuitem_descrip(MenuItem* menuitem) -{ /* need to do something about colored text */ - - TodoItem* item_data; - char* new_descrip; - - item_data = (TodoItem*)get_menuitem_userdata(menuitem); - new_descrip = strdup(""); - - if (strlen(item_data->description) > 0) { - /* strcat(new_descrip, "☰ "); */ - strcat(new_descrip, "# "); - } - if (strlen(item_data->due) > 0) { - strcat(new_descrip, item_data->due); - strcat(new_descrip, " "); - } - if (item_data->subtask_count > 0) { - - int tasks_complete = 0; - for (int i = 0; i < item_data->subtask_count; i++) { - if (item_data->subtask_list[i]->done == SubTaskState_done) { - tasks_complete += 1; - } - } - - /* [, # done, /, # total, ], null */ - char subtask_done[4]; // assume there wont be more than 999 subtasks (possibly danger?) - snprintf(subtask_done, 4, "%d", tasks_complete); - int substask_len = 1+item_data->subtask_count+1+strlen(subtask_done)+1+1; - char subtask_text[substask_len]; - sprintf(subtask_text, "[%s/%d]", subtask_done, item_data->subtask_count); - strcat(new_descrip, subtask_text); - } - - /* free old string */ - if (strlen(new_descrip) > 0) { - free(get_menuitem_descrip(menuitem)); - set_menuitem_descrip(menuitem, new_descrip); - } - - return 0; -} - /* popup */ PopupMenu* make_popupmenu(TodoItem* itemdata) @@ -439,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 */