From: Daniel Liu Date: Mon, 1 Feb 2021 04:22:27 +0000 (-0500) Subject: windows X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=11705fff523e2180e53a3b91fc92dc65ac7969b7;p=taskasaur.git windows --- diff --git a/menu.c b/menu.c index 5016dcc..997fc15 100644 --- a/menu.c +++ b/menu.c @@ -8,6 +8,11 @@ #include "headers/render.h" #include "headers/utils.h" +#define MENU_PAD_TOP 2 +#define MENU_PAD_BOTTOM 1 +#define MENU_PAD_LEFT 2 +#define MENU_PAD_RIGHT 1 + typedef struct MenuItem { char* contents; } MenuItem; @@ -17,6 +22,7 @@ typedef struct Menu { int menu_length; int selected_item; WINDOW* menu_win; + WINDOW* sub_win; int max_height; int max_width; } Menu; @@ -52,8 +58,21 @@ create_menu(MenuItem** item_list) int set_menu_win(Menu* menu, WINDOW* win) { + int height, width; + menu->menu_win = win; - getmaxyx(menu->menu_win, menu->max_height, menu->max_width); + 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; + menu->sub_win = derwin( + menu->menu_win, + menu->max_height, + menu->max_width, + MENU_PAD_TOP, + MENU_PAD_LEFT + ); return 0; } @@ -149,25 +168,26 @@ menu_driver(Menu* menu, MenuAction action) int render_menu(Menu* menu) { - int cur_line; - - cur_line = 0; + /* draw outer menu (prob dont need this every render) */ + mvwprintw(menu->menu_win, 0, MENU_PAD_LEFT, "TODO"); + /* draw inner menu */ + int cur_line = 0; for (int i = 0; i < menu->menu_length; i++) { int wrapped_lines; char* wrapped_text; int text_color; - /* wrap text by inserting newlines */ - wrapped_text = wrap_text(menu->menu_items[i]->contents, menu->max_width, &wrapped_lines); + /* wrap text by inserting newlines (maxwidth-1 for newline char)*/ + wrapped_text = wrap_text(menu->menu_items[i]->contents, menu->max_width-1, &wrapped_lines); /* color selected item */ text_color = (i == menu->selected_item) ? TS_SELECTED : TS_NONSELECTED; - wattron(menu->menu_win, COLOR_PAIR(text_color)); - mvwprintw(menu->menu_win, cur_line, 0, wrapped_text); - wattroff(menu->menu_win, COLOR_PAIR(text_color)); + wattron(menu->sub_win, COLOR_PAIR(text_color)); + mvwprintw(menu->sub_win, cur_line, 0, wrapped_text); + wattroff(menu->sub_win, COLOR_PAIR(text_color)); cur_line += wrapped_lines; @@ -175,6 +195,9 @@ render_menu(Menu* menu) } + wrefresh(menu->sub_win); + wrefresh(menu->menu_win); + return 0; } diff --git a/taskasaur.c b/taskasaur.c index 08c5695..e201d86 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -24,6 +24,12 @@ main(int argc, char** argv) item_list[4] = 0; Menu* menu = create_menu(item_list); + WINDOW* win = newwin(20, 40, 5, 5); + set_menu_win(menu, win); + box(win, 0, 0); + refresh(); + wrefresh(win); + render_menu(menu); while ((ch = getch()) != BINDING_QUIT) {