nctree: clean up items pushed off the top #1164

pull/1372/head
nick black 3 years ago committed by Nick Black
parent ff228650d6
commit 3f66cb0ff7

@ -287,7 +287,7 @@ draw_tree_item(nctree* n, nctree_int_item* nii, const unsigned* path,
ymin = 0;
ymax = *frontiert;
}
//fprintf(stderr, "x: %d y: %d\n", startx, ymin);
fprintf(stderr, "x: %d y: %d\n", startx, ymin);
struct ncplane_options nopts = {
.x = startx,
.y = ymin,
@ -303,14 +303,20 @@ draw_tree_item(nctree* n, nctree_int_item* nii, const unsigned* path,
return -1;
}
}else{
// FIXME move and possibly enlarge nii->ncp
// FIXME is frontiert always the place to be?
// FIXME possibly enlarge nii->ncp?
}
if(ncplane_y(nii->ncp) <= *frontiert || *frontierb >= ncplane_dim_y(n->items.ncp)){
ncplane_move_yx(nii->ncp, *frontiert, ncplane_x(nii->ncp));
}else{
ncplane_move_yx(nii->ncp, *frontierb, ncplane_x(nii->ncp));
}
int ret = n->cbfxn(nii->ncp, nii->curry, distance);
if(ret < 0){
return -1;
}
// FIXME shrink plane if it was enlarged
//fprintf(stderr, "ft: %d fb: %d %p ncplane_y: %d\n", *frontiert, *frontierb, nii->ncp, ncplane_y(nii->ncp));
fprintf(stderr, "ft: %d fb: %d %p ncplane_y: %d\n", *frontiert, *frontierb, nii->ncp, ncplane_y(nii->ncp));
if(ncplane_y(nii->ncp) <= *frontiert){
*frontiert = ncplane_y(nii->ncp) - 1;
}
@ -320,6 +326,25 @@ draw_tree_item(nctree* n, nctree_int_item* nii, const unsigned* path,
return 0;
}
// iterate backwards from tmppath, destroying any ncplanes we find. they've
// been pushed off-screen. tmppath is changed as we iterate. nii will not be
// destroyed, only items above nii.
static int
destroy_above(nctree* n, nctree_int_item* nii, unsigned* path, int distance){
nctree_int_item* tmpnii;
while((tmpnii = nctree_prev_internal(n, path)) != nii){
nii = tmpnii;
--distance;
if(nii->ncp){
fprintf(stderr, "PREVDESTROY: %s\n", (const char*)nii->curry);
ncplane_destroy(nii->ncp);
nii->ncp = NULL;
n->cbfxn(nii->ncp, nii->curry, distance);
}
}
return 0;
}
// tmppath ought be initialized with currentpath, but having size sufficient
// to hold n->maxdepth + 1 unsigneds.
static int
@ -332,11 +357,14 @@ nctree_inner_redraw(nctree* n, unsigned* tmppath){
int frontierb = n->activerow;
nctree_int_item* nii = n->curitem;
int distance = 0;
fprintf(stderr, "FOCUSED: %s\n", (const char*)nii->curry);
// draw the focused item
if(draw_tree_item(n, nii, tmppath, &frontiert, &frontierb, distance)){
return -1;
}
nctree_int_item* tmpnii;
// draw items above the current one FIXME
// draw items above the current one
fprintf(stderr, "FRONTIERT: %d\n", frontiert);
while(frontiert >= 0){
if((tmpnii = nctree_prev_internal(n, tmppath)) == nii){
break;
@ -346,8 +374,9 @@ nctree_inner_redraw(nctree* n, unsigned* tmppath){
if(draw_tree_item(n, nii, tmppath, &frontiert, &frontierb, distance)){
return -1;
}
fprintf(stderr, "PREV: %s\n", (const char*)nii->curry);
}
// FIXME destroy any drawn ones before us
destroy_above(n, nii, tmppath, distance);
// move items up if there is a gap at the top FIXME
if(frontiert >= 0){
}

@ -360,6 +360,9 @@ static nctree_item rads = {
static int
callback(struct ncplane* ncp, void* curry, int dizzy){
if(ncp == NULL){
return 0;
}
if(ncplane_dim_y(ncp) > 1){
if(ncplane_resize_simple(ncp, 1, ncplane_dim_x(ncp))){
return -1;
@ -368,15 +371,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);
channels_set_bg_rgb(&channels, 0x006080);
ncplane_set_fg_rgb(ncp, 0xffffff);
}else if(dizzy < 0){
float f = -dizzy / 80.0;
channels_set_bg_rgb8(&channels, 0, 60 - 60 * f, 0);
channels_set_bg_rgb8(&channels, 0, 0x60 - 0x60 * f, 0);
ncplane_set_fg_rgb(ncp, 0xbbbbbb);
}else if(dizzy > 0){
float f = dizzy / 80.0;
channels_set_bg_rgb8(&channels, 0, 60 - 60 * f, 0);
float f = dizzy / 60.0;
channels_set_bg_rgb8(&channels, 0, 0x60 - 0x60 * f, 0);
ncplane_set_fg_rgb(ncp, 0xbbbbbb);
}
ncplane_set_base(ncp, "", 0, channels);

Loading…
Cancel
Save