dorne/cursetree/tree.c

39 lines
936 B
C
Raw Normal View History

#include <stdlib.h>
#include "ncrswrap.h"
#include "tree.h"
/*
*/
static inline struct ct_node *__root_node(void) {
return __node(termdims(), bounds_none(), NULL);
}
2025-09-13 11:21:34 +10:00
int init_tree(struct ct_tree **const tree) {
*tree = (struct ct_tree *)malloc(sizeof(struct ct_tree));
(*tree)->root = __root_node();
return EXIT_SUCCESS;
}
2025-09-13 11:21:34 +10:00
void destroy_tree(struct ct_tree *const tree) {
__destroy_node(tree->root);
end_ncurses();
free(tree);
}
2025-09-13 11:21:34 +10:00
void resize_tree(struct ct_tree *const tree, struct ct_dims *const dims) {
resize_node(tree->root, dims);
}
void switch_nodes(struct ct_node **const node0, struct ct_node **const node1) {
struct ct_node *const node0ptr = *node0;
struct ct_dims *const node0dims = dup_dims((*node0)->surface->dims);
struct ct_dims *const node1dims = dup_dims((*node1)->surface->dims);
*node0 = *node1;
resize_node(*node0, node1dims);
*node1 = node0ptr;
resize_node(*node1, node0dims);
}