From: Daniel Date: Sat, 6 Mar 2021 16:26:23 +0000 (-0500) Subject: removed subwin X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=cc7da4297912fa4cacc4b13ebc59223df415a116;p=taskasaur.git removed subwin --- diff --git a/config.h b/config.h index bffbcea..61f5bf0 100644 --- a/config.h +++ b/config.h @@ -23,6 +23,10 @@ static int selected_color = COLOR_MAGENTA; static int non_selected_color = COLOR_WHITE; static int menu_selected_color = COLOR_CYAN; static int menu_non_selected_color = COLOR_GREEN; +static int item_count_color = COLOR_YELLOW; +static int due_faraway_color = COLOR_GREEN; +static int due_soon_color = COLOR_YELLOW; +static int due_urgent_color = COLOR_RED; /* KEYS */ #define BINDING_QUIT 'q' diff --git a/headers/menu.h b/headers/menu.h index 39fe8d5..9afda2e 100644 --- a/headers/menu.h +++ b/headers/menu.h @@ -30,7 +30,6 @@ extern MenuItem* create_menuitem(char* title); extern Menu* create_menu(char* menu_name, MenuItem** item_list); extern WINDOW* get_menu_win(Menu* menu); -extern WINDOW* get_menu_subwin(Menu* menu); extern MenuItem* get_menu_item(Menu* menu, int index); extern int get_selected_item(Menu* menu); extern int get_menu_length(Menu* menu); diff --git a/headers/render.h b/headers/render.h index a14301c..a241620 100644 --- a/headers/render.h +++ b/headers/render.h @@ -16,6 +16,7 @@ enum TaskasaurColors { TS_NONSELECTED, TS_MENU_SELECTED, TS_MENU_NONSELECTED, + TS_ITEMCOUNT }; typedef struct BoardMenu { @@ -38,6 +39,7 @@ extern BoardMenu* create_board_menu(Board* board); extern Menu** make_menus(Board* board, int todolist_length); extern MenuItem** todolist_to_menuitem(TodoItem** item_list, int list_length); extern Board* boardmenu_to_board(BoardMenu* boardmenu); +extern int render_board(Board* board); extern int set_selected_menu(BoardMenu* boardmenu, int index); extern int swap_menu(BoardMenu* boardmenu, int src_index, int dest_index); diff --git a/menu.c b/menu.c index 4f9ee5e..abb2fdf 100644 --- a/menu.c +++ b/menu.c @@ -30,7 +30,6 @@ typedef struct Menu { int scroll_offset; bool focused; WINDOW* menu_win; - WINDOW* sub_win; int max_height; int max_width; void* userdata; @@ -102,12 +101,6 @@ get_menu_win(Menu* menu) return menu->menu_win; } -WINDOW* -get_menu_subwin(Menu* menu) -{ - return menu->sub_win; -} - MenuItem* get_menu_item(Menu* menu, int index) { @@ -171,13 +164,6 @@ set_menu_win(Menu* menu, WINDOW* win) /* 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; - menu->sub_win = derwin( - menu->menu_win, - menu->max_height, - menu->max_width, - MENU_PAD_TOP, - MENU_PAD_LEFT - ); return 0; } @@ -286,7 +272,7 @@ menu_insert_mode(Menu* menu, int insert_index) /* move cursor to right spot */ ungetstr(menu->menu_items[insert_index]->title); - mvwgetnstr(menu->sub_win, + mvwgetnstr(menu->menu_win, insert_pos, 0, temp, @@ -375,16 +361,7 @@ menu_driver(Menu* menu, MenuAction action) int render_menu(Menu* menu) { - /* draw outer menu (prob dont need this every render) */ - /* wclear(menu->menu_win); */ - int titlecolor; - titlecolor = COLOR_PAIR((menu->focused == true) ? TS_MENU_SELECTED: TS_MENU_NONSELECTED); - wattron(menu->menu_win, titlecolor); - mvwprintw(menu->menu_win, 0, MENU_PAD_LEFT, menu->menu_name); - wattroff(menu->menu_win, titlecolor); - - /* draw inner menu */ - wclear(menu->sub_win); + wclear(menu->menu_win); /* calculate scroll */ int visible; @@ -406,19 +383,13 @@ render_menu(Menu* menu) ); } - /* char abuf[20]; */ - /* int y; */ - /* int x; */ - /* getmaxyx(menu->sub_win, y, x); */ - /* sprintf(abuf, "%d,%d,%d max:%d,%d", menu->selected_item, visible, menu->scroll_offset,y,x); */ - /* mvprintw(19, 27, abuf); */ - + /* render menu items */ int curline = 0; for (int i = menu->scroll_offset; i < menu->menu_length; i++) { curline += render_item(menu, i, curline); } - wrefresh(menu->sub_win); + wrefresh(menu->menu_win); wrefresh(menu->menu_win); return 0; @@ -433,13 +404,15 @@ render_item(Menu* menu, int item_index, int start_y) /* color selected item */ hlcolor = COLOR_PAIR((item_index == menu->selected_item && menu->focused == true) ? TS_SELECTED : TS_NONSELECTED); - wattron(menu->sub_win, hlcolor); - mvwprintw(menu->sub_win, start_y, 0, curitem->title); - wattroff(menu->sub_win, hlcolor); + wattron(menu->menu_win, hlcolor); + mvwprintw(menu->menu_win, start_y, 0, curitem->title); + wattroff(menu->menu_win, hlcolor); /* display number of items */ if (strlen(curitem->description) > 0) { - mvwprintw(menu->sub_win, start_y+1, 0, curitem->description); + 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); @@ -464,7 +437,7 @@ items_visible(Menu* menu, int offset) int maxheight; int maxwidth; // unused - getmaxyx(menu->sub_win, maxheight, maxwidth); + getmaxyx(menu->menu_win, maxheight, maxwidth); int vis = 0; int lines = 0; @@ -485,7 +458,7 @@ items_visible_rev(Menu* menu, int offset) int maxheight; int maxwidth; // unused - getmaxyx(menu->sub_win, maxheight, maxwidth); + getmaxyx(menu->menu_win, maxheight, maxwidth); int vis = 0; int lines = 0; diff --git a/render.c b/render.c index 963e0e5..2f9261c 100644 --- a/render.c +++ b/render.c @@ -45,6 +45,7 @@ init_tscolors(void) init_pair(TS_NONSELECTED, non_selected_color, COLOR_BLACK); init_pair(TS_MENU_SELECTED, menu_selected_color, COLOR_BLACK); init_pair(TS_MENU_NONSELECTED, menu_non_selected_color, COLOR_BLACK); + init_pair(TS_ITEMCOUNT, item_count_color, COLOR_BLACK); return 0; } @@ -197,6 +198,13 @@ boardmenu_to_board(BoardMenu* boardmenu) return newboard; } +int +render_board(Board* board) +{ + + return 0; +} + int set_selected_menu(BoardMenu* boardmenu, int index) { @@ -312,7 +320,6 @@ make_popup_menu(TodoItem* itemdata) POPUP_BORDER, POPUP_BORDER*2 ); - box(popup_win, 0, 0); set_menu_win(new_popup_menu, popup_win); set_menu_focus(new_popup_menu, 1); @@ -328,8 +335,6 @@ render_popup_menu(Menu* popup_menu) popup_win = get_menu_win(popup_menu); wclear(popup_win); - box(popup_win, 0, 0); - render_menu(popup_menu); wrefresh(popup_win); diff --git a/taskasaur.c b/taskasaur.c index b00d29a..8ebd419 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -14,6 +14,8 @@ void normal_renderstep(BoardMenu* boardmenu); void popup_renderstep(BoardMenu* boardmenu); void save_to_file(char* filepath, BoardMenu* boardmenu); +void exit_step(BoardMenu* boardmenu); + int main(int argc, char** argv) { @@ -34,7 +36,9 @@ main(int argc, char** argv) normal_renderstep(boardmenu); int ch; - while ((ch = getch()) != BINDING_QUIT) { + while (1) { + + ch = getch(); if (boardmenu->popup_open == 0) { normal_handleinput(boardmenu, ch); @@ -49,7 +53,6 @@ main(int argc, char** argv) /* save on exit - this causes weird stuff to happen, maybe it's not given enough time to write before program exits? */ /* save_to_file(boardfile_name, boardmenu); */ - exit_tscurses(); return 0; } @@ -196,6 +199,9 @@ normal_handleinput(BoardMenu* boardmenu, int ch) case BINDING_WRITE: save_to_file(boardfile_name, boardmenu); break; + case BINDING_QUIT: + exit_step(boardmenu); + break; case KEY_RESIZE: /* ; */ /* int y, x; */ @@ -224,6 +230,9 @@ popup_handleinput(BoardMenu* boardmenu, int ch) case BINDING_SCROLL_DOWN: menu_driver(popup_menu, MENU_DOWN); break; + case BINDING_QUIT: + boardmenu->popup_open = 0; + break; } } @@ -261,3 +270,10 @@ save_to_file(char* filepath, BoardMenu* boardmenu) begin_write(filepath, writeboard); free_board(writeboard); } + +void +exit_step(BoardMenu* boardmenu) +{ + exit_tscurses(); + exit(0); +}