[nctree] draw a tree with no items

This commit is contained in:
nick black 2021-12-12 04:15:06 -05:00 committed by nick black
parent 174445bb60
commit a1cdecd8d2
2 changed files with 17 additions and 9 deletions

View File

@ -36,6 +36,9 @@ The following keypresses are recognized:
# BUGS # BUGS
**tfman** does not currently (and is unlikely to ever) support the full
**groff** macro language.
# SEE ALSO # SEE ALSO
**man(1)**, **man(1)**,

View File

@ -14,7 +14,7 @@ typedef struct nctree {
nctree_int_item* curitem; // item addressed by the path nctree_int_item* curitem; // item addressed by the path
unsigned maxdepth; // maximum hierarchy level unsigned maxdepth; // maximum hierarchy level
unsigned* currentpath; // array of |maxdepth|+1 elements, ended by UINT_MAX unsigned* currentpath; // array of |maxdepth|+1 elements, ended by UINT_MAX
int activerow; // active row 0 <= activerow < dimy int activerow; // active row -1 <= activerow < dimy
int indentcols; // cols to indent per level int indentcols; // cols to indent per level
uint64_t bchannels; // border glyph channels uint64_t bchannels; // border glyph channels
} nctree; } nctree;
@ -81,10 +81,16 @@ goto_last_item(nctree* n){
static void static void
goto_first_item(nctree* n){ goto_first_item(nctree* n){
n->currentpath[0] = 0; if(n->maxdepth == 0){
n->currentpath[1] = UINT_MAX; n->currentpath[0] = UINT_MAX;
n->curitem = &n->items.subs[0]; n->curitem = NULL;
n->activerow = 0; n->activerow = -1;
}else{
n->currentpath[0] = 0;
n->currentpath[1] = UINT_MAX;
n->curitem = &n->items.subs[0];
n->activerow = 0;
}
} }
// the initial path ought point to the first item. // the initial path ought point to the first item.
@ -141,10 +147,6 @@ nctree* nctree_create(ncplane* n, const nctree_options* opts){
if(opts->flags){ if(opts->flags){
logwarn("Passed invalid flags 0x%016" PRIx64 "\n", opts->flags); logwarn("Passed invalid flags 0x%016" PRIx64 "\n", opts->flags);
} }
if(opts->count == 0 || opts->items == NULL){
logerror("Can't create empty tree\n");
goto error;
}
if(opts->nctreecb == NULL){ if(opts->nctreecb == NULL){
logerror("Can't use NULL callback\n"); logerror("Can't use NULL callback\n");
goto error; goto error;
@ -390,6 +392,9 @@ destroy_below(nctree* n, nctree_int_item* nii, unsigned* path, int distance){
// to hold n->maxdepth + 1 unsigneds. // to hold n->maxdepth + 1 unsigneds.
static int static int
nctree_inner_redraw(nctree* n, unsigned* tmppath){ nctree_inner_redraw(nctree* n, unsigned* tmppath){
if(n->activerow < 0){
return 0;
}
ncplane* ncp = n->items.ncp; ncplane* ncp = n->items.ncp;
if(ncplane_cursor_move_yx(ncp, n->activerow, 0)){ if(ncplane_cursor_move_yx(ncp, n->activerow, 0)){
return -1; return -1;