ncmenu: properly place unrolled menu #179

pull/319/head
nick black 5 years ago committed by Nick Black
parent ce965fcbcd
commit 4586dd7e19

@ -2217,6 +2217,8 @@ struct ncmenu_section {
ncinput shortcut; // shortcut, all should be distinct ncinput shortcut; // shortcut, all should be distinct
}* items; }* items;
int itemcount; int itemcount;
int xoff; // used only in library copy, ignored in request
int bodycols; // used only in library copy, ignored in request
}; };
typedef struct ncmenu_options { typedef struct ncmenu_options {

@ -96,6 +96,8 @@ write_header(ncmenu* ncm){
return -1; return -1;
} }
for(int i = 0 ; i < ncm->sectioncount ; ++i){ for(int i = 0 ; i < ncm->sectioncount ; ++i){
ncm->sections[i].xoff = xoff;
ncm->sections[i].bodycols = 10; // FIXME
if(ncplane_putstr(ncm->ncp, ncm->sections[i].name) < 0){ if(ncplane_putstr(ncm->ncp, ncm->sections[i].name) < 0){
return -1; return -1;
} }
@ -157,11 +159,16 @@ ncmenu* ncmenu_create(notcurses* nc, const ncmenu_options* opts){
return NULL; return NULL;
} }
static int static inline int
section_height(const ncmenu* n, int sectionidx){ section_height(const ncmenu* n, int sectionidx){
return n->sections[sectionidx].itemcount + 2; return n->sections[sectionidx].itemcount + 2;
} }
static inline int
section_width(const ncmenu* n, int sectionidx){
return n->sections[sectionidx].bodycols + 2;
}
int ncmenu_unroll(ncmenu* n, int sectionidx){ int ncmenu_unroll(ncmenu* n, int sectionidx){
if(sectionidx < 0 || sectionidx >= n->sectioncount){ if(sectionidx < 0 || sectionidx >= n->sectioncount){
return -1; return -1;
@ -172,13 +179,14 @@ int ncmenu_unroll(ncmenu* n, int sectionidx){
n->unrolledsection = sectionidx; n->unrolledsection = sectionidx;
int dimy, dimx; int dimy, dimx;
ncplane_dim_yx(n->ncp, &dimy, &dimx); ncplane_dim_yx(n->ncp, &dimy, &dimx);
int height = section_height(n, sectionidx); const int height = section_height(n, sectionidx);
int width = 10; // FIXME const int width = section_width(n, sectionidx);
int ypos = n->bottom ? dimy - height - 1 : 1; const int ypos = n->bottom ? dimy - height - 1 : 1;
if(ncplane_cursor_move_yx(n->ncp, ypos, 1)){ const int xpos = n->sections[sectionidx].xoff;
if(ncplane_cursor_move_yx(n->ncp, ypos, xpos)){
return -1; return -1;
} }
if(ncplane_rounded_box_sized(n->ncp, 0, n->sectionchannels, height, width, 0)){ if(ncplane_rounded_box_sized(n->ncp, 0, n->headerchannels, height, width, 0)){
return -1; return -1;
} }
// FIXME // FIXME

Loading…
Cancel
Save