structure dorne cli as a binary tree

This commit is contained in:
Emile Clark-Boman 2025-09-10 22:49:24 +10:00
parent c3074a75eb
commit 79272e8421
2 changed files with 174 additions and 0 deletions

58
cli/tree.h Normal file
View file

@ -0,0 +1,58 @@
#ifndef DORNE_TREE_H
#define DORNE_TREE_H
# ifndef __NCURSES_H
typedef struct _win_st WINDOW;
# endif /* __NCURSES_H */
#define NODE_CHILD_N 2
/* MACRO:
* void NODEDIMS(struct crs_node *node, struct crs_nodedims dims);
*/
#define NODEDIMS(node, dims) (getbegyx(dims.y, dims.x); getmaxyx(dims.y, dims.x))
enum crs_nodetype {
NODE_WINDOW,
NODE_ABSTRACT,
};
/* Stores a node's starting x,y coordinates, width, & height.
* NOTE: Intended for interfunction communication.
*/
struct crs_nodedims {
int x, y, width, height;
};
enum crs_axis {
AXIS_X,
AXIS_Y,
};
struct crs_node {
enum crs_nodetype type;
// union value depends on crs_node.type
union {
WINDOW *win;
struct {
float ratio;
struct crs_node *child[NODE_CHILD_N];
};
};
};
struct crs_tree {
WINDOW *stdscr;
struct crs_node *root;
};
/* === External Interface === */
// struct crs_node *init_node_window(void);
// struct crs_node *init_node_abstract(void);
// void destroy_node(struct crs_node *node);
int init_tree(struct crs_tree **tree);
void update_tree(struct crs_tree *tree);
void destroy_tree(struct crs_tree *tree);
#endif /* DORNE_TREE_H */