Skip to content

Commit

Permalink
nctree: pass distance to cbfxn #1164
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Feb 25, 2021
1 parent fe8abbe commit 4ea2b67
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/lib/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ nctree_inner_create(ncplane* n, const struct nctree_options* opts){
free(ret);
return NULL;
}
ncplane_set_base(n, " ", 0, opts->bchannels);
ret->items.ncp = n;
ret->items.curry = NULL;
nctree_redraw(ret);
Expand Down Expand Up @@ -250,7 +251,7 @@ tree_path_length(const unsigned* path){
// *|frontierb|. otherwise, draw up from *|frontiert|.
static int
draw_tree_item(nctree* n, nctree_int_item* nii, const unsigned* path,
int* frontiert, int* frontierb){
int* frontiert, int* frontierb, int distance){
//fprintf(stderr, "drawing item ft: %d fb: %d %p\n", *frontiert, *frontierb, nii->ncp);
if(!nii->ncp){
const int startx = (tree_path_length(path) - 1) * n->indentcols;
Expand Down Expand Up @@ -283,7 +284,7 @@ draw_tree_item(nctree* n, nctree_int_item* nii, const unsigned* path,
}else{
// FIXME move and possibly enlarge nii->ncp
}
int ret = n->cbfxn(nii->ncp, nii->curry, 0); // FIXME third param
int ret = n->cbfxn(nii->ncp, nii->curry, distance);
if(ret < 0){
return -1;
}
Expand All @@ -309,7 +310,8 @@ nctree_inner_redraw(nctree* n, unsigned* tmppath){
int frontiert = n->activerow;
int frontierb = n->activerow;
nctree_int_item* nii = n->curitem;
if(draw_tree_item(n, nii, tmppath, &frontiert, &frontierb)){
int distance = 0;
if(draw_tree_item(n, nii, tmppath, &frontiert, &frontierb, distance)){
return -1;
}
nctree_int_item* tmpnii;
Expand All @@ -319,22 +321,25 @@ nctree_inner_redraw(nctree* n, unsigned* tmppath){
break;
}
nii = tmpnii;
if(draw_tree_item(n, nii, tmppath, &frontiert, &frontierb)){
--distance;
if(draw_tree_item(n, nii, tmppath, &frontiert, &frontierb, distance)){
return -1;
}
}
// FIXME destroy any drawn ones before us
// move items up if there is a gap at the top FIXME
if(frontiert >= 0){
}
distance = 0;
n->activerow = ncplane_y(n->curitem->ncp);
// draw items below the current one FIME
while(frontierb < ncplane_dim_y(n->items.ncp)){
if((tmpnii = nctree_next_internal(n, tmppath)) == nii){
break;
}
nii = tmpnii;
if(draw_tree_item(n, nii, tmppath, &frontiert, &frontierb)){
++distance;
if(draw_tree_item(n, nii, tmppath, &frontiert, &frontierb, distance)){
return -1;
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/poc/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,15 @@ callback(struct ncplane* ncp, void* curry, int dizzy){
}
}
ncplane_cursor_move_yx(ncp, 0, 0);
uint64_t channels = 0;
if(dizzy == 0){
channels_set_bg_rgb(&channels, 0x006060);
}else if(dizzy < 0){
channels_set_bg_rgb8(&channels, 0, 60 + dizzy, 0);
}else if(dizzy > 0){
channels_set_bg_rgb8(&channels, 0, 60 - dizzy, 0);
}
ncplane_set_base(ncp, " ", 0, channels);
ncplane_putstr(ncp, curry);
return 0;
}
Expand Down Expand Up @@ -394,6 +403,7 @@ create_tree(struct notcurses* nc){
.count = 1,
.nctreecb = callback,
.indentcols = 2,
.bchannels = 0,
.flags = 0,
};
struct nctree* tree = nctree_create(notcurses_stdplane(nc), &topts);
Expand Down

0 comments on commit 4ea2b67

Please sign in to comment.