diff --git a/include/notcurses.h b/include/notcurses.h index 7a3c937d0..5e846100a 100644 --- a/include/notcurses.h +++ b/include/notcurses.h @@ -2242,6 +2242,16 @@ API int ncmenu_unroll(struct ncmenu* n, int sectionidx); // Roll up any unrolled menu section, and hide the menu if using hiding. API int ncmenu_rollup(struct ncmenu* n); +// Unroll the previous/next section (relative to current unrolled). If no +// section is unrolled, the first section will be unrolled. +API int ncmenu_nextsection(struct ncmenu* n); +API int ncmenu_prevsection(struct ncmenu* n); + +// Move to the previous/next item within the currently unrolled section. If no +// section is unrolled, the first section will be unrolled. +API int ncmenu_nextitem(struct ncmenu* n); +API int ncmenu_previtem(struct ncmenu* n); + // Destroy a menu created with ncmenu_create(). API int ncmenu_destroy(struct ncmenu* n); diff --git a/src/lib/menu.c b/src/lib/menu.c index 9b5706115..3557c2a1d 100644 --- a/src/lib/menu.c +++ b/src/lib/menu.c @@ -240,6 +240,40 @@ int ncmenu_rollup(ncmenu* n){ return write_header(n); } +int ncmenu_nextsection(ncmenu* n){ + int nextsection = n->unrolledsection + 1; + if(nextsection){ + ncmenu_rollup(n); + if(nextsection == n->sectioncount){ + nextsection = 0; + } + } + return ncmenu_unroll(n, nextsection); +} + +int ncmenu_prevsection(ncmenu* n){ + int prevsection = n->unrolledsection; + if(n->unrolledsection < 0){ + prevsection = 1; + }else{ + ncmenu_rollup(n); + } + if(--prevsection == -1){ + prevsection = n->sectioncount - 1; + } + return ncmenu_unroll(n, prevsection); +} + +int ncmenu_nextitem(ncmenu* n){ + // FIXME + return 0; +} + +int ncmenu_previtem(ncmenu* n){ + // FIXME + return 0; +} + int ncmenu_destroy(ncmenu* n){ int ret = 0; if(n){ diff --git a/src/poc/menu.c b/src/poc/menu.c index 485e2a759..145bcdf27 100644 --- a/src/poc/menu.c +++ b/src/poc/menu.c @@ -10,7 +10,19 @@ run_menu(struct notcurses* nc, struct ncmenu* ncm){ ncinput ni; notcurses_render(nc); while((keypress = notcurses_getc_blocking(nc, &ni)) != (char32_t)-1){ - if(ni.alt){ + if(keypress == NCKEY_LEFT){ + if(ncmenu_prevsection(ncm)){ + return -1; + } + }else if(keypress == NCKEY_RIGHT){ + if(ncmenu_nextsection(ncm)){ + return -1; + } + }else if(keypress == '\x1b'){ + if(ncmenu_unroll(ncm, 1)){ + return -1; + } + }else if(ni.alt){ switch(keypress){ case 'd': case 'D': if(ncmenu_unroll(ncm, 0)){ @@ -23,8 +35,7 @@ run_menu(struct notcurses* nc, struct ncmenu* ncm){ } break; } - } - if(keypress == 'q'){ + }else if(keypress == 'q'){ ncmenu_destroy(ncm); return 0; }