selector: bgchannels only inside the body #302

This commit is contained in:
nick black 2020-01-31 21:25:21 -05:00
parent eab1ce0262
commit c1664170fd
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
5 changed files with 31 additions and 15 deletions

View File

@ -2134,8 +2134,7 @@ typedef struct selector_options {
uint64_t titlechannels;// title channels uint64_t titlechannels;// title channels
uint64_t footchannels; // secondary and footer channels uint64_t footchannels; // secondary and footer channels
uint64_t boxchannels; // border channels uint64_t boxchannels; // border channels
uint64_t bgchannels; // base cell channels uint64_t bgchannels; // background channels, used only in body
const char* base_egc; // base EGC, NULL is interpreted as "" for convenience
} selector_options; } selector_options;
struct ncselector; struct ncselector;

View File

@ -32,8 +32,7 @@ typedef struct selector_options {
uint64_t titlechannels;// title channels uint64_t titlechannels;// title channels
uint64_t footchannels; // secondary and footer channels uint64_t footchannels; // secondary and footer channels
uint64_t boxchannels; // border channels uint64_t boxchannels; // border channels
uint64_t bgchannels; // base cell channels uint64_t bgchannels; // background channels for body
const char* base_egc; // base EGC or NULL
} selector_options; } selector_options;
``` ```

View File

@ -2157,8 +2157,7 @@ typedef struct selector_options {
uint64_t titlechannels;// title channels uint64_t titlechannels;// title channels
uint64_t footchannels; // secondary and footer channels uint64_t footchannels; // secondary and footer channels
uint64_t boxchannels; // border channels uint64_t boxchannels; // border channels
uint64_t bgchannels; // base cell channels uint64_t bgchannels; // background channels, used only in body
const char* base_egc; // base EGC, NULL is interpreted as "" for convenience
} selector_options; } selector_options;
struct ncselector; struct ncselector;

View File

@ -138,6 +138,7 @@ typedef struct ncselector {
int secondarycols; // columns occupied by secondary int secondarycols; // columns occupied by secondary
char* footer; // can be NULL char* footer; // can be NULL
int footercols; // columns occupied by footer int footercols; // columns occupied by footer
cell background; // background, used in body only
uint64_t opchannels; // option channels uint64_t opchannels; // option channels
uint64_t descchannels; // description channels uint64_t descchannels; // description channels
uint64_t titlechannels; // title channels uint64_t titlechannels; // title channels

View File

@ -58,8 +58,14 @@ ncselector_draw(ncselector* n){
n->ncp->channels = n->footchannels; n->ncp->channels = n->footchannels;
ncplane_putstr_yx(n->ncp, dimy - 1, xloc, n->footer); ncplane_putstr_yx(n->ncp, dimy - 1, xloc, n->footer);
} }
// Top line of body (background and possibly up arrow)
++yoff;
ncplane_cursor_move_yx(n->ncp, yoff, xoff + 1);
for(int i = xoff + 1 ; i < dimx - 1 ; ++i){
ncplane_putc(n->ncp, &n->background);
}
n->ncp->channels = n->descchannels; n->ncp->channels = n->descchannels;
ncplane_putegc_yx(n->ncp, ++yoff, bodywidth - (n->longdesc + 3) + xoff, "", NULL); ncplane_putegc_yx(n->ncp, yoff, bodywidth - (n->longdesc + 3) + xoff, "", NULL);
unsigned printidx = n->startdisp; unsigned printidx = n->startdisp;
int bodyoffset = dimx - bodywidth + 2; int bodyoffset = dimx - bodywidth + 2;
unsigned printed = 0; unsigned printed = 0;
@ -67,12 +73,15 @@ ncselector_draw(ncselector* n){
if(n->maxdisplay && printed == n->maxdisplay){ if(n->maxdisplay && printed == n->maxdisplay){
break; break;
} }
ncplane_cursor_move_yx(n->ncp, yoff, xoff + 1);
for(int i = xoff + 1 ; i < dimx - 1 ; ++i){
ncplane_putc(n->ncp, &n->background);
}
n->ncp->channels = n->opchannels; n->ncp->channels = n->opchannels;
if(printidx == n->selected){ if(printidx == n->selected){
n->ncp->channels = (uint64_t)channels_bchannel(n->opchannels) << 32u | channels_fchannel(n->opchannels); n->ncp->channels = (uint64_t)channels_bchannel(n->opchannels) << 32u | channels_fchannel(n->opchannels);
} }
ncplane_printf_yx(n->ncp, yoff, bodyoffset, "%*.*s", (int)n->longop, ncplane_printf_yx(n->ncp, yoff, bodyoffset + (n->longop - n->items[printidx].opcolumns), "%s", n->items[printidx].option);
(int)n->longop, n->items[printidx].option);
n->ncp->channels = n->descchannels; n->ncp->channels = n->descchannels;
if(printidx == n->selected){ if(printidx == n->selected){
n->ncp->channels = (uint64_t)channels_bchannel(n->descchannels) << 32u | channels_fchannel(n->descchannels); n->ncp->channels = (uint64_t)channels_bchannel(n->descchannels) << 32u | channels_fchannel(n->descchannels);
@ -83,6 +92,11 @@ ncselector_draw(ncselector* n){
} }
++printed; ++printed;
} }
// Bottom line of body (background and possibly down arrow)
ncplane_cursor_move_yx(n->ncp, yoff, xoff + 1);
for(int i = xoff + 1 ; i < dimx - 1 ; ++i){
ncplane_putc(n->ncp, &n->background);
}
n->ncp->channels = n->descchannels; n->ncp->channels = n->descchannels;
ncplane_putegc_yx(n->ncp, yoff, bodywidth - (n->longdesc + 3) + xoff, "", NULL); ncplane_putegc_yx(n->ncp, yoff, bodywidth - (n->longdesc + 3) + xoff, "", NULL);
return notcurses_render(n->ncp->nc); return notcurses_render(n->ncp->nc);
@ -154,11 +168,15 @@ ncselector* ncselector_create(ncplane* n, int y, int x, const selector_options*
} }
for(ns->itemcount = 0 ; ns->itemcount < opts->itemcount ; ++ns->itemcount){ for(ns->itemcount = 0 ; ns->itemcount < opts->itemcount ; ++ns->itemcount){
const struct selector_item* src = &opts->items[ns->itemcount]; const struct selector_item* src = &opts->items[ns->itemcount];
if(mbswidth(src->option) > ns->longop){ int cols = mbswidth(src->option);
ns->longop = mbswidth(src->option); ns->items[ns->itemcount].opcolumns = cols;
if(cols > ns->longop){
ns->longop = cols;
} }
if(mbswidth(src->desc) > ns->longdesc){ cols = mbswidth(src->desc);
ns->longdesc = mbswidth(src->desc); ns->items[ns->itemcount].desccolumns = cols;
if(cols > ns->longdesc){
ns->longdesc = cols;
} }
ns->items[ns->itemcount].option = strdup(src->option); ns->items[ns->itemcount].option = strdup(src->option);
ns->items[ns->itemcount].desc = strdup(src->desc); ns->items[ns->itemcount].desc = strdup(src->desc);
@ -175,8 +193,7 @@ ncselector* ncselector_create(ncplane* n, int y, int x, const selector_options*
if(!(ns->ncp = ncplane_new(n->nc, dimy, dimx, y, x, NULL))){ if(!(ns->ncp = ncplane_new(n->nc, dimy, dimx, y, x, NULL))){
goto freeitems; goto freeitems;
} }
if(ncplane_set_base(ns->ncp, opts->bgchannels, 0, if(cell_prime(ns->ncp, &ns->background, " ", 0, opts->bgchannels) < 0){
opts->base_egc ? opts->base_egc : "") < 0){
ncplane_destroy(ns->ncp); ncplane_destroy(ns->ncp);
goto freeitems; goto freeitems;
} }
@ -291,6 +308,7 @@ void ncselector_destroy(ncselector* n, char** item){
free(n->items[n->itemcount].option); free(n->items[n->itemcount].option);
free(n->items[n->itemcount].desc); free(n->items[n->itemcount].desc);
} }
cell_release(n->ncp, &n->background);
ncplane_destroy(n->ncp); ncplane_destroy(n->ncp);
free(n->items); free(n->items);
free(n->title); free(n->title);