dorne/cli/tree.h

64 lines
1.5 KiB
C
Raw Normal View History

2025-09-10 22:49:24 +10:00
#ifndef DORNE_TREE_H
#define DORNE_TREE_H
2025-09-11 17:41:14 +10:00
#ifndef __NCURSES_H
2025-09-10 22:49:24 +10:00
typedef struct _win_st WINDOW;
2025-09-11 17:41:14 +10:00
#endif /* __NCURSES_H */
2025-09-10 22:49:24 +10:00
#define NODE_CHILD_N 2
/* MACRO:
2025-09-11 17:41:14 +10:00
* Get widnow node start x,y coordinates, width, & height.
2025-09-10 22:49:24 +10:00
* void NODEDIMS(struct crs_node *node, struct crs_nodedims dims);
*/
2025-09-11 17:41:14 +10:00
#define GET_WNODEDIMS(dims, node) \
(getbegyx((node)->win, dims.y, dims.x)); \
getmaxyx((node)->win, dims.y, dims.x)
2025-09-10 22:49:24 +10:00
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 {
2025-09-11 17:41:14 +10:00
enum crs_axis axis;
2025-09-10 22:49:24 +10:00
float ratio;
2025-09-11 17:41:14 +10:00
struct crs_nodedims *dims;
2025-09-10 22:49:24 +10:00
struct crs_node *child[NODE_CHILD_N];
};
};
};
struct crs_tree {
struct crs_node *root;
};
/* === External Interface === */
int ct_init(struct crs_tree **const tree);
2025-09-11 17:41:14 +10:00
void destroy_tree(struct crs_tree *const tree);
void resize_tree(struct crs_tree *const tree, struct crs_nodedims *const dims);
void ct_update(struct crs_tree *const tree);
2025-09-10 22:49:24 +10:00
void bifurcate_window_node(struct crs_node **const node,
const enum crs_axis axis, const int invert_axis,
const float ratio);
2025-09-10 22:49:24 +10:00
#endif /* DORNE_TREE_H */