ncmenu: call write_header() on section disabled change

pull/1062/head
nick black 4 years ago committed by Nick Black
parent fb6f1e4d53
commit 930d14380c

@ -211,6 +211,7 @@ typedef struct ncmenu {
int unrolledsection; // currently unrolled section, -1 if none int unrolledsection; // currently unrolled section, -1 if none
int headerwidth; // minimum space necessary to display all sections int headerwidth; // minimum space necessary to display all sections
uint64_t headerchannels; // styling for header uint64_t headerchannels; // styling for header
uint64_t dissectchannels; // styling for disabled section headers
uint64_t sectionchannels; // styling for sections uint64_t sectionchannels; // styling for sections
uint64_t disablechannels; // styling for disabled entries uint64_t disablechannels; // styling for disabled entries
bool bottom; // are we on the bottom (vs top)? bool bottom; // are we on the bottom (vs top)?

@ -231,7 +231,8 @@ section_x(const ncmenu* ncm, int x){
} }
static int static int
write_header(ncmenu* ncm){ ncm->ncp->channels = ncm->headerchannels; write_header(ncmenu* ncm){
ncplane_set_channels(ncm->ncp, ncm->headerchannels);
int dimy, dimx; int dimy, dimx;
ncplane_dim_yx(ncm->ncp, &dimy, &dimx); ncplane_dim_yx(ncm->ncp, &dimy, &dimx);
int xoff = 0; // 2-column margin on left int xoff = 0; // 2-column margin on left
@ -263,6 +264,11 @@ write_header(ncmenu* ncm){ ncm->ncp->channels = ncm->headerchannels;
return -1; return -1;
} }
} }
if(ncm->sections[i].enabled_item_count <= 0){
ncplane_set_channels(ncm->ncp, ncm->dissectchannels);
}else{
ncplane_set_channels(ncm->ncp, ncm->headerchannels);
}
if(ncplane_putstr_yx(ncm->ncp, ypos, xoff, ncm->sections[i].name) < 0){ if(ncplane_putstr_yx(ncm->ncp, ypos, xoff, ncm->sections[i].name) < 0){
return -1; return -1;
} }
@ -320,6 +326,8 @@ ncmenu* ncmenu_create(ncplane* n, const ncmenu_options* opts){
if(ret->ncp){ if(ret->ncp){
ret->unrolledsection = -1; ret->unrolledsection = -1;
ret->headerchannels = opts->headerchannels; ret->headerchannels = opts->headerchannels;
ret->dissectchannels = opts->headerchannels;
channels_set_fg_rgb(&ret->dissectchannels, 0xdddddd);
ret->sectionchannels = opts->sectionchannels; ret->sectionchannels = opts->sectionchannels;
ret->disablechannels = ret->sectionchannels; ret->disablechannels = ret->sectionchannels;
channels_set_fg_rgb(&ret->disablechannels, 0xdddddd); channels_set_fg_rgb(&ret->disablechannels, 0xdddddd);
@ -621,13 +629,20 @@ int ncmenu_item_set_status(ncmenu* n, const char* section, const char* item,
i->disabled = !enabled; i->disabled = !enabled;
if(changed){ if(changed){
if(i->disabled){ if(i->disabled){
--sec->enabled_item_count; if(--sec->enabled_item_count == 0){
write_header(n);
}
}else{ }else{
++sec->enabled_item_count; if(++sec->enabled_item_count == 1){
write_header(n);
}
} }
if(n->unrolledsection == si){ if(n->unrolledsection == si){
// FIXME if sec->enabled_item_count == 0, need choose new section if(sec->enabled_item_count == 0){
ncmenu_unroll(n, n->unrolledsection); ncmenu_rollup(n);
}else{
ncmenu_unroll(n, n->unrolledsection);
}
} }
} }
return 0; return 0;

Loading…
Cancel
Save