diff --git a/menu.h b/menu.h index 62a6cfd..fb52800 100644 --- a/menu.h +++ b/menu.h @@ -56,6 +56,26 @@ class MenuBar { } } + void resize(WINDOW *new_win) + { + delwin(menuwin); + + this->win = new_win; + + int yMax,xMax,yBeg,xBeg; + getmaxyx(win,yMax,xMax); + getbegyx(win,yBeg,xBeg); + + menuwin = newwin(yMax-2,xMax-2,yBeg+1,xBeg+1); + + int current_pos = 2; + for (int i = 0; i < num_menus; i++) + { + menus[i].start_x = current_pos; + current_pos += menus[i].text.length() + 1; + } + } + void reset() { for (int i = 0; i < num_menus; i++) diff --git a/tui.cpp b/tui.cpp index cc3bfc3..efd5a94 100644 --- a/tui.cpp +++ b/tui.cpp @@ -20,7 +20,7 @@ int main(int argc, char **argv){ int yMax,xMax; getmaxyx(stdscr,yMax,xMax); - WINDOW *win = newwin(9*(yMax)/10,9*(xMax)/10,1,1); + WINDOW *win = newwin(yMax-1,xMax-1,1,1); box(win,0,0); string menu1[] = {"New","Open","Save","Exit"}; @@ -46,11 +46,15 @@ int main(int argc, char **argv){ } else if(ch == KEY_RESIZE) { + clear(); + refresh(); delwin(win); getmaxyx(stdscr,yMax,xMax); - win = newwin(9*(yMax)/10,9*(xMax)/10,1,1); + win = newwin(yMax-1,xMax-1,1,1); box(win,0,0); + menubar.resize(win); menubar.draw(); + wrefresh(win); } }