| Paint the tree ABI a third way: Zig and dvui 7289263 nandi 9d ago | 1 | /* libjoltzvui — the retained-tree C ABI, painted by dvui. |
| 2 | * |
| 3 | * The shape crates/jolt-vidya exports on egui and crates/jolt-tui exports over |
| 4 | * terminal cells. A caller builds a tree of nodes between frames, calls |
| 5 | * zvui_frame() to paint it, and drains what the person did with |
| 6 | * zvui_tree_poll_event(). |
| 7 | * |
| 8 | * Node ids are small positive ints; 0 is "no node". Ids are reused after a |
| 9 | * free, but widget identity is not — see src/tree.zig. |
| 10 | * |
| 11 | * Every `const char *` returned here points into one scratch slot and is valid |
| 12 | * only until the next string-returning call. Copy it if you need it longer. |
| 13 | * Nothing here calls back: events are queued and polled. |
| 14 | */ |
| 15 | #ifndef JOLTZVUI_H |
| 16 | #define JOLTZVUI_H |
| 17 | |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
| 22 | /* The window. */ |
| 23 | int zvui_open(int width, int height, const char *title); |
| 24 | void zvui_close(void); |
| 25 | int zvui_should_close(void); /* 1 once asked to quit, or with no window */ |
| 26 | void zvui_set_title(const char *title); |
| 27 | float zvui_screen_width(void); /* points, not pixels; 0 before frame one */ |
| 28 | float zvui_screen_height(void); |
| 29 | void zvui_frame(void); /* paint the whole tree once, and present */ |
| 30 | |
| 31 | /* The tree. */ |
| 32 | int zvui_tree_root(void); |
| 33 | int zvui_node_new(const char *tag); |
| 34 | void zvui_node_free(int node); /* and everything under it */ |
| 35 | int zvui_node_exists(int node); |
| 36 | const char *zvui_node_tag(int node); |
| 37 | int zvui_node_parent(int node); |
| 38 | |
| 39 | void zvui_node_set_str(int node, const char *key, const char *value); |
| 40 | void zvui_node_set_num(int node, const char *key, double value); |
| 41 | void zvui_node_set_bool(int node, const char *key, int value); |
| 42 | void zvui_node_clear_props(int node); |
| 43 | const char *zvui_node_get_str(int node, const char *key); |
| 44 | double zvui_node_get_num(int node, const char *key); |
| 45 | int zvui_node_get_bool(int node, const char *key); |
| 46 | |
| 47 | int zvui_node_child_count(int node); |
| 48 | int zvui_node_child_at(int node, int index); |
| 49 | int zvui_node_append(int parent, int child); |
| 50 | void zvui_node_remove(int parent, int child); |
| 51 | int zvui_node_insert_after(int parent, int child, int sibling); |
| 52 | int zvui_node_replace(int parent, int old_child, int new_child); |
| 53 | const char *zvui_tree_dump(int node); |
| 54 | |
| 55 | /* Events: poll until it answers 0, reading each with the accessors. */ |
| 56 | int zvui_tree_poll_event(void); |
| 57 | int zvui_tree_event_node(void); |
| 58 | const char *zvui_tree_event_name(void); /* click | change | toggled | activate */ |
| 59 | const char *zvui_tree_event_text(void); |
| 60 | double zvui_tree_event_num(void); |
| 61 | |
| 62 | #ifdef __cplusplus |
| 63 | } |
| 64 | #endif |
| 65 | #endif /* JOLTZVUI_H */ |