-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfront.c
More file actions
139 lines (120 loc) · 3.58 KB
/
front.c
File metadata and controls
139 lines (120 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "front.h"
#include "data/struct/chunk_array.h"
#include "syscalls/syscalls.h"
void (*view_build_func)();
document_data default_doc_data;
gpu_rect default_canvas;
document_node* current_node;
chunk_array_t *node_stack;
document_node* uno_make_view(node_info info){
document_node *node = zalloc(sizeof(document_node));
node->info = info;
return node;
}
void uno_attach(document_node *parent, document_node *child){
if (!parent || !child) return;
if (!parent->children) parent->children = linked_list_create();
linked_list_push(parent->children, child);
}
void uno_state_push(document_node *new_node){
if (!node_stack){
node_stack = chunk_array_create(sizeof(uptr), 64);
}
if (current_node){
chunk_array_push(node_stack, ¤t_node);
}
print(">Save %llx. New %llx, %i in stack",current_node,new_node,chunk_array_count(node_stack));
current_node = new_node;
}
void uno_state_pop(){
size_t count = chunk_array_count(node_stack);
if (count){
current_node = (document_node*)*(uptr*)chunk_array_pop(node_stack);
print("< Current node now %llx",current_node);
} else print("No elements in array");
}
void uno_begin_vertical(node_info info){
info.general_type = doc_gen_layout;
info.type = doc_layout_vertical;
document_node* vert = uno_make_view(info);
if (!default_doc_data.root){
default_doc_data.root = vert;
}
if (current_node)
uno_attach(current_node, vert);
uno_state_push(vert);
}
void uno_end_vertical(){
uno_state_pop();
}
void uno_begin_horizontal(node_info info){
info.general_type = doc_gen_layout;
info.type = doc_layout_horizontal;
document_node* horiz = uno_make_view(info);
if (!default_doc_data.root){
default_doc_data.root = horiz;
}
if (current_node)
uno_attach(current_node, horiz);
uno_state_push(horiz);
}
void uno_end_horizontal(){
uno_state_pop();
}
void uno_begin_depth(node_info info){
info.general_type = doc_gen_layout;
info.type = doc_layout_depth;
document_node* horiz = uno_make_view(info);
if (!default_doc_data.root){
default_doc_data.root = horiz;
}
if (current_node)
uno_attach(current_node, horiz);
uno_state_push(horiz);
}
void uno_end_depth(){
uno_state_pop();
}
void uno_create_view(node_info info, string_slice content){
document_node* node = uno_make_view(info);
node->content = content;
if (!default_doc_data.root){
default_doc_data.root = node;
}
if (current_node)
uno_attach(current_node, node);
}
void uno_create_empty_view(node_info info){
document_node* node = uno_make_view(info);
if (!default_doc_data.root)
default_doc_data.root = node;
if (current_node)
uno_attach(current_node, node);
}
void uno_destroy_node(void *ptr){
document_node* node = ptr;
if (!node) return;
if (node->children){
// linked_list_for_each(node->children, uno_destroy_node);
// linked_list_destroy(node->children);
}
// release(node);
}
void set_document_view(void (*view_builder)(), gpu_rect canvas){
view_build_func = view_builder;
default_canvas = canvas;
trigger_document_refresh();
}
void trigger_document_refresh(){
chunk_array_reset(node_stack);
uno_destroy_node(default_doc_data.root);
default_doc_data.root = 0;
if (view_build_func) view_build_func();
refresh_document_layout();
}
void refresh_document_layout(){
layout_document(default_canvas, default_doc_data);
}
void uno_draw(draw_ctx *ctx){
render_document(ctx, default_doc_data);
}