Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
tree.c File Reference
#include "internal.h"
Include dependency graph for tree.c:

Go to the source code of this file.

Data Structures

struct  nctree_int_item
 
struct  nctree
 

Typedefs

typedef struct nctree_int_item nctree_int_item
 
typedef struct nctree nctree
 

Functions

 __attribute__ ((unused))
 
int nctree_add (nctree *n, const unsigned *spec, const struct nctree_item *add)
 
int nctree_del (nctree *n, const unsigned *spec)
 
nctreenctree_create (ncplane *n, const nctree_options *opts)
 
void nctree_destroy (nctree *n)
 
ncplanenctree_plane (nctree *n)
 
void * nctree_prev (nctree *n)
 
void * nctree_next (nctree *n)
 
int nctree_redraw (nctree *n)
 
bool nctree_offer_input (nctree *n, const ncinput *ni)
 
void * nctree_focused (nctree *n)
 
void * nctree_goto (nctree *n, const unsigned *spec, int *failspec)
 

Typedef Documentation

◆ nctree

typedef struct nctree nctree

◆ nctree_int_item

Function Documentation

◆ __attribute__()

__attribute__ ( (unused)  )

Definition at line 44 of file tree.c.

45 {
46 unsigned* path = malloc(sizeof(*path) * (n->maxdepth + 2));
47 path[0] = UINT_MAX;
48 nctree_debug_internal(&n->items, path, 0);
49 free(path);
50}
free(duplicated)
vopts n
Definition notcurses.h:3502
Here is the call graph for this function:

◆ nctree_add()

int nctree_add ( nctree n,
const unsigned *  spec,
const struct nctree_item add 
)

Definition at line 209 of file tree.c.

209 {
210 // it's illegal to pass an empty path for addition; one must pass { 0, UINT_MAX }
211 if(spec[0] == UINT_MAX){
212 logerror("invalid empty path");
213 return -1;
214 }
215 if(add->subs){
216 logerror("invalid subs %p", add->subs);
217 return -1;
218 }
219 if(add->subcount){
220 logerror("invalid subcount %u", add->subcount);
221 return -1;
222 }
223 if(nctree_add_internal(n, &n->items, spec, add)){
224 return -1;
225 }
226 if(n->activerow == -1){
227 n->activerow = 0;
228 n->curitem = &n->items.subs[0];
229 n->currentpath = malloc(sizeof(*n->currentpath) * 3);
230 n->currentpath[0] = 0;
231 n->currentpath[1] = UINT_MAX;
232 n->maxdepth = 1;
233 }
234 return 0;
235}
#define logerror(fmt,...)
Definition logging.h:32
unsigned subcount
Definition notcurses.h:4044
struct nctree_item * subs
Definition notcurses.h:4043

◆ nctree_create()

nctree * nctree_create ( ncplane n,
const nctree_options opts 
)

Definition at line 266 of file tree.c.

266 {
267 if(opts->flags){
268 logwarn("passed invalid flags 0x%016" PRIx64, opts->flags);
269 }
271 logerror("can't use the standard plane");
272 goto error;
273 }
274 if(opts->nctreecb == NULL){
275 logerror("can't use NULL callback");
276 goto error;
277 }
278 if(opts->indentcols < 0){
279 logerror("can't indent negative columns");
280 goto error;
281 }
282 nctree* ret = nctree_inner_create(n, opts);
283 if(ret == NULL){
284 logerror("couldn't prepare nctree");
285 goto error;
286 }
287 return ret;
288
289error:
291 return NULL;
292}
#define logwarn(fmt,...)
Definition logging.h:37
ncplane * notcurses_stdplane(notcurses *nc)
Definition notcurses.c:699
int ncplane_destroy(ncplane *ncp)
Definition notcurses.c:1018
notcurses * ncplane_notcurses(const ncplane *n)
Definition notcurses.c:2626
const struct ncplane_options * opts
Definition notcurses.h:3483
Definition tree.c:11
return NULL
Definition termdesc.h:229
Here is the call graph for this function:

◆ nctree_del()

int nctree_del ( nctree n,
const unsigned *  spec 
)

Definition at line 237 of file tree.c.

237 {
238 nctree_int_item* parent = NULL;
239 nctree_int_item* nii = &n->items;
240 const unsigned* p = spec;
241 while(*p != UINT_MAX){
242 if(*p >= nii->subcount){
243 logerror("invalid path element (%u >= %u)", *p, nii->subcount);
244 return -1;
245 }
246 parent = nii;
247 nii = &nii->subs[*p];
248 ++p;
249 }
250 free_tree_items(nii);
251 if(parent){
252 // parent can only be defined if we had at least one path element
253 unsigned lastelem = spec[-1];
254 if(lastelem != --parent->subcount){
255 memmove(&parent->subs[lastelem], &parent->subs[lastelem + 1],
256 sizeof(*parent->subs) * (parent->subcount - lastelem));
257 }
258 }
259 if(n->items.subcount == 0){
260 n->activerow = -1;
261 n->curitem = NULL;
262 }
263 return 0;
264}
unsigned subcount
Definition tree.c:7
struct nctree_int_item * subs
Definition tree.c:8

◆ nctree_destroy()

void nctree_destroy ( nctree n)

Definition at line 294 of file tree.c.

294 {
295 if(n){
296 free_tree_items(&n->items);
297 free(n->currentpath);
298 free(n);
299 }
300}
Here is the call graph for this function:

◆ nctree_focused()

void * nctree_focused ( nctree n)

Definition at line 606 of file tree.c.

606 {
607 return n->curitem->curry;
608}

◆ nctree_goto()

void * nctree_goto ( nctree n,
const unsigned *  spec,
int *  failspec 
)

Definition at line 610 of file tree.c.

610 {
611 n->activerow = 0;
612 (void)spec;
613 (void)failspec;
614 // FIXME
615 return NULL;
616}

◆ nctree_next()

void * nctree_next ( nctree n)

Definition at line 396 of file tree.c.

396 {
397 int rows = 0;
398 if(n->curitem->ncp){
399 rows = ncplane_dim_y(n->curitem->ncp);
400 }
401 nctree_int_item* tmp = nctree_next_internal(n, n->currentpath);
402 if(tmp != n->curitem){
403 n->curitem = tmp;
404 n->activerow += rows;
405 if(n->activerow >= (int)ncplane_dim_y(n->items.ncp)){
406 n->activerow = ncplane_dim_y(n->items.ncp) - 1;
407 }
408 }
409 return n->curitem->curry;
410}
void * curry
Definition tree.c:5
Here is the caller graph for this function:

◆ nctree_offer_input()

bool nctree_offer_input ( nctree n,
const ncinput ni 
)

Definition at line 579 of file tree.c.

579 {
580 if(ni->evtype == NCTYPE_RELEASE){
581 return false;
582 }
583 if(ni->id == NCKEY_UP){
584 nctree_prev(n);
585 return true;
586 }else if(ni->id == NCKEY_DOWN){
587 nctree_next(n);
588 return true;
589 }else if(ni->id == NCKEY_PGUP){
590 nctree_prev(n); // more FIXME
591 return true;
592 }else if(ni->id == NCKEY_PGDOWN){
593 nctree_next(n); // more FIXME
594 return true;
595 }else if(ni->id == NCKEY_HOME){
596 goto_first_item(n);
597 return true;
598 }else if(ni->id == NCKEY_END){
599 goto_last_item(n);
600 return true;
601 }
602 // FIXME implement left, right, +, - (expand/collapse)
603 return false;
604}
#define NCKEY_END
Definition nckeys.h:47
#define NCKEY_UP
Definition nckeys.h:37
#define NCKEY_DOWN
Definition nckeys.h:39
#define NCKEY_PGUP
Definition nckeys.h:45
#define NCKEY_HOME
Definition nckeys.h:46
#define NCKEY_PGDOWN
Definition nckeys.h:44
@ NCTYPE_RELEASE
Definition notcurses.h:1198
ncintype_e evtype
Definition notcurses.h:1218
uint32_t id
Definition notcurses.h:1210
void * nctree_prev(nctree *n)
Definition tree.c:349
void * nctree_next(nctree *n)
Definition tree.c:396
Here is the call graph for this function:

◆ nctree_plane()

ncplane * nctree_plane ( nctree n)

Definition at line 303 of file tree.c.

303 {
304 return n->items.ncp;
305}

◆ nctree_prev()

void * nctree_prev ( nctree n)

Definition at line 349 of file tree.c.

349 {
350 int rows = 0;
351 if(n->curitem->ncp){
352 rows = ncplane_dim_y(n->curitem->ncp);
353 }
354 nctree_int_item* tmp = nctree_prev_internal(n, n->currentpath);
355 if(tmp != n->curitem){
356 n->curitem = tmp;
357 n->activerow -= rows;
358 if(n->activerow < 0){
359 n->activerow = 0;
360 }
361 }
362 return n->curitem->curry;
363}
Here is the caller graph for this function:

◆ nctree_redraw()

int nctree_redraw ( nctree n)

Definition at line 568 of file tree.c.

568 {
569 unsigned* tmppath = malloc(sizeof(*tmppath) * (n->maxdepth + 2));
570 if(tmppath == NULL){
571 return -1;
572 }
573 memcpy(tmppath, n->currentpath, sizeof(*tmppath) * (n->maxdepth + 1));
574 int ret = nctree_inner_redraw(n, tmppath);
575 free(tmppath);
576 return ret;
577}
Here is the call graph for this function: