From: Daniel Liu Date: Sat, 23 Jan 2021 19:23:54 +0000 (-0500) Subject: menu init X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=63ddce932065c2d05cf6412f52fd5c4637e195a3;p=taskasaur.git menu init --- diff --git a/headers/menu.h b/headers/menu.h index 8ccd1fb..120ddad 100644 --- a/headers/menu.h +++ b/headers/menu.h @@ -8,8 +8,13 @@ typedef struct Menu Menu; typedef struct MenuItem MenuItem; +extern MenuItem* create_menuitem(char* contents); + extern Menu* create_menu(MenuItem** item_list); extern int set_menu_items(Menu* menu, MenuItem** item_list); +extern int set_menu_win(Menu* menu, WINDOW* win); extern MenuItem* get_menu_items(Menu* menu); +extern int free_menu(Menu* menu); + #endif diff --git a/menu.c b/menu.c index ddcd8de..5d5a0eb 100644 --- a/menu.c +++ b/menu.c @@ -15,27 +15,51 @@ typedef struct Menu { int menu_length; int selected_item; WINDOW* menu_win; + int max_height; + int max_width; } Menu; int render_menu(Menu* menu); +MenuItem* +create_menuitem(char* contents) +{ + MenuItem* new_menuitem; + + new_menuitem = malloc(sizeof(MenuItem)); + new_menuitem->contents = contents; + + return new_menuitem; +} + Menu* create_menu(MenuItem** item_list) { - Menu *new_menu; + Menu* new_menu; new_menu = malloc(sizeof(Menu)); - new_menu->menu_items = item_list; - new_menu->menu_length = array_length(MenuItem*, item_list); + set_menu_items(new_menu, item_list); new_menu->selected_item = 0; - WINDOW* menu_win = NULL; + set_menu_win(new_menu, stdscr); - return NULL; + return new_menu; } int set_menu_items(Menu* menu, MenuItem** item_list) { + menu->menu_items = item_list; + menu->menu_length = array_length(MenuItem*, item_list); + + return 0; +} + +int +set_menu_win(Menu* menu, WINDOW* win) +{ + menu->menu_win = win; + getmaxyx(menu->menu_win, menu->max_height, menu->max_width); + return 0; } @@ -51,6 +75,8 @@ render_menu(Menu* menu) for (int i = 0; i < menu->menu_length; i++) { + /* wrap text by inserting newlines */ + /* color selected item */ } @@ -58,4 +84,9 @@ render_menu(Menu* menu) return 0; } +int +free_menu(Menu* menu) +{ + return 0; +} diff --git a/taskasaur.c b/taskasaur.c index eee0edb..15dcb9a 100644 --- a/taskasaur.c +++ b/taskasaur.c @@ -16,6 +16,14 @@ main(int argc, char** argv) getch(); + MenuItem** item_list = malloc(4*sizeof(MenuItem*)); + for (int i = 0; i < 3; i++) { + item_list[i] = create_menuitem("lmao"); + } + item_list[3] = 0; + + Menu* menu = create_menu(item_list); + exit_tscurses();