Added reactiveness to terminal resize
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
|
||||
class Menu {
|
||||
public:
|
||||
Menu(std::string text, char trigger, std::string *items, int num_items)
|
||||
Menu(std::string text, int trigger, std::string *items, int num_items)
|
||||
{
|
||||
this->text = text;
|
||||
this->trigger = trigger;
|
||||
@@ -16,7 +16,7 @@ class Menu {
|
||||
}
|
||||
int start_x;
|
||||
std::string text;
|
||||
char trigger;
|
||||
int trigger;
|
||||
std::string *items;
|
||||
int num_items;
|
||||
int selected_item;
|
||||
@@ -99,10 +99,10 @@ class MenuBar {
|
||||
{
|
||||
switch(ch)
|
||||
{
|
||||
case 'k':
|
||||
case 'j':
|
||||
menu.selectNextItem();
|
||||
break;
|
||||
case 'j':
|
||||
case 'k':
|
||||
menu.selectPrevItem();
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -20,7 +20,7 @@ int main(int argc, char **argv){
|
||||
int yMax,xMax;
|
||||
getmaxyx(stdscr,yMax,xMax);
|
||||
|
||||
WINDOW *win = newwin(yMax-1,xMax-1,yMax-yMax+1,xMax-xMax+1);
|
||||
WINDOW *win = newwin(9*(yMax)/10,9*(xMax)/10,1,1);
|
||||
box(win,0,0);
|
||||
|
||||
string menu1[] = {"New","Open","Save","Exit"};
|
||||
@@ -36,10 +36,22 @@ int main(int argc, char **argv){
|
||||
MenuBar menubar = MenuBar(win,menus,3);
|
||||
menubar.draw();
|
||||
|
||||
char ch;
|
||||
keypad(win, TRUE);
|
||||
int ch;
|
||||
while((ch = wgetch(win))){
|
||||
menubar.handleTrigger(ch);
|
||||
menubar.draw();
|
||||
if(ch <= 255)
|
||||
{
|
||||
menubar.handleTrigger(ch);
|
||||
menubar.draw();
|
||||
}
|
||||
else if(ch == KEY_RESIZE)
|
||||
{
|
||||
delwin(win);
|
||||
getmaxyx(stdscr,yMax,xMax);
|
||||
win = newwin(9*(yMax)/10,9*(xMax)/10,1,1);
|
||||
box(win,0,0);
|
||||
menubar.draw();
|
||||
}
|
||||
}
|
||||
|
||||
endwin();
|
||||
|
||||
Reference in New Issue
Block a user