X-Git-Url: https://git.danieliu.xyz/?p=taskasaur.git;a=blobdiff_plain;f=menu.c;h=f077fd2395209a52071cdc0aafc96cc9dcc1a8a3;hp=2c1975f805d1e4a4f270a20a406ae3e3dd736072;hb=7cd288f609ab7d99e5fb5b8da07d2c1b6f32907d;hpb=303071d6e0488d7da4dc810897948b8ed97354d2 diff --git a/menu.c b/menu.c index 2c1975f..f077fd2 100644 --- a/menu.c +++ b/menu.c @@ -4,6 +4,7 @@ #include #include "headers/menu.h" +#include "headers/render.h" #include "headers/utils.h" typedef struct MenuItem { @@ -77,13 +78,24 @@ render_menu(Menu* menu) 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 */ - mvwprintw(menu->menu_win, cur_line, 0, menu->menu_items[i]->contents); + wrapped_text = wrap_text(menu->menu_items[i]->contents, menu->max_width, &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)); + + cur_line += wrapped_lines; - cur_line += 1; + free(wrapped_text); }