ncmenu: nextsection/prevsection

pull/319/head
nick black 4 years ago
parent f8ee8b2a10
commit fa88f9b525
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -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);

@ -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){

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

Loading…
Cancel
Save