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