Search code examples
cmenupositioncursorncurses

How to set menu cursor position?


the standard position of menu in ncurses is 0,0. Can I change It? If Yes, how? I tried move() and wmove(), but result is not changed. Thanks in advance.

PS: What I tried:

#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;
}

There's not main function I thought It as a library for another program.


Solution

  • I found a function set_menu_sub(my_menu, derwin(stdscr, 0, 0, 10, 20)); that's working very well!