Skip to content

Commit

Permalink
nctree PoC: set backgrounds relative to active #1164
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Feb 24, 2021
1 parent 8da418a commit ff050d9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
29 changes: 26 additions & 3 deletions src/lib/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,18 @@ nctree_prev_internal(nctree* n, unsigned* newpath){
}

void* nctree_prev(nctree* n){
n->curitem = nctree_prev_internal(n, n->currentpath);
int rows = 0;
if(n->curitem->ncp){
rows = ncplane_dim_y(n->curitem->ncp);
}
nctree_int_item* tmp = nctree_prev_internal(n, n->currentpath);
if(tmp != n->curitem){
n->curitem = tmp;
n->activerow -= rows;
if(n->activerow < 0){
n->activerow = 0;
}
}
return n->curitem->curry;
}

Expand Down Expand Up @@ -232,8 +243,18 @@ nctree_next_internal(nctree* n, unsigned* newpath){
}

void* nctree_next(nctree* n){
// FIXME update n->activerow, redraw
n->curitem = nctree_next_internal(n, n->currentpath);
int rows = 0;
if(n->curitem->ncp){
rows = ncplane_dim_y(n->curitem->ncp);
}
nctree_int_item* tmp = nctree_next_internal(n, n->currentpath);
if(tmp != n->curitem){
n->curitem = tmp;
n->activerow += rows;
if(n->activerow >= ncplane_dim_y(n->items.ncp)){
n->activerow = ncplane_dim_y(n->items.ncp) - 1;
}
}
return n->curitem->curry;
}

Expand Down Expand Up @@ -332,7 +353,9 @@ nctree_inner_redraw(nctree* n, unsigned* tmppath){
}
distance = 0;
n->activerow = ncplane_y(n->curitem->ncp);
nii = n->curitem;
// draw items below the current one FIME
memcpy(tmppath, n->currentpath, sizeof(*tmppath) * (n->maxdepth + 1));
while(frontierb < ncplane_dim_y(n->items.ncp)){
if((tmpnii = nctree_next_internal(n, tmppath)) == nii){
break;
Expand Down
15 changes: 12 additions & 3 deletions src/poc/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,19 @@ callback(struct ncplane* ncp, void* curry, int dizzy){
uint64_t channels = 0;
if(dizzy == 0){
channels_set_bg_rgb(&channels, 0x006060);
ncplane_set_fg_rgb(ncp, 0xffffff);
}else if(dizzy < 0){
channels_set_bg_rgb8(&channels, 0, 60 + dizzy, 0);
float f = -dizzy / 80.0;
channels_set_bg_rgb8(&channels, 0, 60 - 60 * f, 0);
ncplane_set_fg_rgb(ncp, 0xbbbbbb);
}else if(dizzy > 0){
channels_set_bg_rgb8(&channels, 0, 60 - dizzy, 0);
float f = dizzy / 80.0;
channels_set_bg_rgb8(&channels, 0, 60 - 60 * f, 0);
ncplane_set_fg_rgb(ncp, 0xbbbbbb);
}
ncplane_set_base(ncp, " ", 0, channels);
ncplane_set_base(ncp, "", 0, channels);
ncplane_putstr(ncp, curry);
fprintf(stderr, "DIZZY (%s) %d\n", (const char*)curry, dizzy);
return 0;
}

Expand All @@ -387,6 +393,9 @@ tree_ui(struct notcurses* nc, struct nctree* tree){
if(nctree_redraw(tree)){
return -1;
}
if(notcurses_render(nc)){
return -1;
}
continue;
}
if(ni.id == 'q'){
Expand Down

0 comments on commit ff050d9

Please sign in to comment.