mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-10 01:29:05 -04:00
ncmenu_section: add enabled_item_count flag #1057
This commit is contained in:
parent
0676101811
commit
2dc1b89fbd
@ -170,6 +170,7 @@ typedef struct ncmenu_int_section {
|
|||||||
int bodycols; // column width of longest item
|
int bodycols; // column width of longest item
|
||||||
int itemselected; // current item selected, -1 for no selection
|
int itemselected; // current item selected, -1 for no selection
|
||||||
int shortcut_offset; // column offset within name of shortcut EGC
|
int shortcut_offset; // column offset within name of shortcut EGC
|
||||||
|
int enabled_item_count; // number of enabled items: section is disabled iff 0
|
||||||
} ncmenu_int_section;
|
} ncmenu_int_section;
|
||||||
|
|
||||||
typedef struct ncfdplane {
|
typedef struct ncfdplane {
|
||||||
|
@ -81,6 +81,7 @@ dup_menu_section(ncmenu_int_section* dst, const struct ncmenu_section* src){
|
|||||||
// we must reject any section which is entirely separators
|
// we must reject any section which is entirely separators
|
||||||
bool gotitem = false;
|
bool gotitem = false;
|
||||||
dst->itemcount = 0;
|
dst->itemcount = 0;
|
||||||
|
dst->enabled_item_count = 0;
|
||||||
dst->items = malloc(sizeof(*dst->items) * src->itemcount);
|
dst->items = malloc(sizeof(*dst->items) * src->itemcount);
|
||||||
if(dst->items == NULL){
|
if(dst->items == NULL){
|
||||||
return -1;
|
return -1;
|
||||||
@ -114,6 +115,7 @@ dup_menu_section(ncmenu_int_section* dst, const struct ncmenu_section* src){
|
|||||||
}
|
}
|
||||||
++dst->itemcount;
|
++dst->itemcount;
|
||||||
}
|
}
|
||||||
|
dst->enabled_item_count = dst->itemcount;
|
||||||
if(!gotitem){
|
if(!gotitem){
|
||||||
while(dst->itemcount){
|
while(dst->itemcount){
|
||||||
free(dst->items[--dst->itemcount].desc);
|
free(dst->items[--dst->itemcount].desc);
|
||||||
@ -452,36 +454,26 @@ int ncmenu_rollup(ncmenu* n){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int ncmenu_nextsection(ncmenu* n){
|
int ncmenu_nextsection(ncmenu* n){
|
||||||
int nextsection = n->unrolledsection + 1;
|
int nextsection = n->unrolledsection;
|
||||||
if(nextsection){
|
// FIXME probably best to detect cycles
|
||||||
ncmenu_rollup(n);
|
do{
|
||||||
if(nextsection == n->sectioncount){
|
|
||||||
nextsection = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(n->sections[nextsection].name == NULL){
|
|
||||||
if(++nextsection == n->sectioncount){
|
if(++nextsection == n->sectioncount){
|
||||||
nextsection = 0;
|
nextsection = 0;
|
||||||
}
|
}
|
||||||
}
|
}while(n->sections[nextsection].name == NULL ||
|
||||||
|
n->sections[nextsection].enabled_item_count == 0);
|
||||||
return ncmenu_unroll(n, nextsection);
|
return ncmenu_unroll(n, nextsection);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ncmenu_prevsection(ncmenu* n){
|
int ncmenu_prevsection(ncmenu* n){
|
||||||
int prevsection = n->unrolledsection;
|
int prevsection = n->unrolledsection;
|
||||||
if(n->unrolledsection < 0){
|
// FIXME probably best to detect cycles
|
||||||
prevsection = 1;
|
do{
|
||||||
}else{
|
|
||||||
ncmenu_rollup(n);
|
|
||||||
}
|
|
||||||
if(--prevsection == -1){
|
|
||||||
prevsection = n->sectioncount - 1;
|
|
||||||
}
|
|
||||||
if(n->sections[prevsection].name == NULL){
|
|
||||||
if(--prevsection < 0){
|
if(--prevsection < 0){
|
||||||
prevsection = n->sectioncount - 1;
|
prevsection = n->sectioncount - 1;
|
||||||
}
|
}
|
||||||
}
|
}while(n->sections[prevsection].name == NULL ||
|
||||||
|
n->sections[prevsection].enabled_item_count == 0);
|
||||||
return ncmenu_unroll(n, prevsection);
|
return ncmenu_unroll(n, prevsection);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,6 +484,7 @@ int ncmenu_nextitem(ncmenu* n){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ncmenu_int_section* sec = &n->sections[n->unrolledsection];
|
ncmenu_int_section* sec = &n->sections[n->unrolledsection];
|
||||||
|
// FIXME probably best to detect cycles
|
||||||
do{
|
do{
|
||||||
if(++sec->itemselected == sec->itemcount){
|
if(++sec->itemselected == sec->itemcount){
|
||||||
sec->itemselected = 0;
|
sec->itemselected = 0;
|
||||||
@ -507,6 +500,7 @@ int ncmenu_previtem(ncmenu* n){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ncmenu_int_section* sec = &n->sections[n->unrolledsection];
|
ncmenu_int_section* sec = &n->sections[n->unrolledsection];
|
||||||
|
// FIXME probably best to detect cycles
|
||||||
do{
|
do{
|
||||||
if(sec->itemselected-- == 0){
|
if(sec->itemselected-- == 0){
|
||||||
sec->itemselected = sec->itemcount - 1;
|
sec->itemselected = sec->itemcount - 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user