如何设置菜单光标位置?
How to set menu cursor position?
ncurses中菜单的标准位置是0,0。
我可以改变它吗?如果是,如何?
我尝试了 move()
和 wmove()
,但结果没有改变。
提前致谢。
PS:我试过的:
#include <stdlib.h>
#include <ncurses.h>
#include <menu.h>
#define GETMIDDLEX(w) ((COLS - w)/2)
#define GETMIDDLEY(h) ((LINES - h)/2)
#define ARRAYCOUNT(a) (sizeof(a) / sizeof(a[0]))
#define ENTER 10
MENU *startMenu = (MENU *)NULL;
ITEM **startMenu_items = (ITEM **)NULL;
char *startMenu_choices[] =
{
"Play",
"Exit",
};
int startMenu_choices_N, selItem_index = 0;
int startMenu_status = TRUE;
const int menuW = 6;
const int menuH = 2;
int draw_startMenu();
int remove_startMenu();
int draw_startMenu()
{
startMenu_choices_N = ARRAYCOUNT(startMenu_choices);
startMenu_items = (ITEM **)calloc(startMenu_choices_N + 1, sizeof(ITEM *));
for(int i = 0; i < startMenu_choices_N; ++i)
{
startMenu_items[i] = new_item(startMenu_choices[i], "");
}
startMenu_items[startMenu_choices_N] = (ITEM *)NULL;
startMenu = new_menu((ITEM **)startMenu_items);
move(GETMIDDLEY(menuH), GETMIDDLEX(menuW));
post_menu(startMenu);
refresh();
}
int remove_startMenu()
{
unpost_menu(startMenu);
for(int i = 0; i < startMenu_choices_N; ++i)
{
free_item(startMenu_items[i]);
}
free_menu(startMenu);
return 0;
}
没有主要功能我以为它是另一个程序的库。
我发现一个功能 set_menu_sub(my_menu, derwin(stdscr, 0, 0, 10, 20));
非常好用!
ncurses中菜单的标准位置是0,0。
我可以改变它吗?如果是,如何?
我尝试了 move()
和 wmove()
,但结果没有改变。
提前致谢。
PS:我试过的:
#include <stdlib.h>
#include <ncurses.h>
#include <menu.h>
#define GETMIDDLEX(w) ((COLS - w)/2)
#define GETMIDDLEY(h) ((LINES - h)/2)
#define ARRAYCOUNT(a) (sizeof(a) / sizeof(a[0]))
#define ENTER 10
MENU *startMenu = (MENU *)NULL;
ITEM **startMenu_items = (ITEM **)NULL;
char *startMenu_choices[] =
{
"Play",
"Exit",
};
int startMenu_choices_N, selItem_index = 0;
int startMenu_status = TRUE;
const int menuW = 6;
const int menuH = 2;
int draw_startMenu();
int remove_startMenu();
int draw_startMenu()
{
startMenu_choices_N = ARRAYCOUNT(startMenu_choices);
startMenu_items = (ITEM **)calloc(startMenu_choices_N + 1, sizeof(ITEM *));
for(int i = 0; i < startMenu_choices_N; ++i)
{
startMenu_items[i] = new_item(startMenu_choices[i], "");
}
startMenu_items[startMenu_choices_N] = (ITEM *)NULL;
startMenu = new_menu((ITEM **)startMenu_items);
move(GETMIDDLEY(menuH), GETMIDDLEX(menuW));
post_menu(startMenu);
refresh();
}
int remove_startMenu()
{
unpost_menu(startMenu);
for(int i = 0; i < startMenu_choices_N; ++i)
{
free_item(startMenu_items[i]);
}
free_menu(startMenu);
return 0;
}
没有主要功能我以为它是另一个程序的库。
我发现一个功能 set_menu_sub(my_menu, derwin(stdscr, 0, 0, 10, 20));
非常好用!