Nuklear
This is a minimal-state, immediate-mode graphical user interface toolkit written in ANSI C and licensed under public domain. It was designed as a simple embeddable user interface for application and does not have any dependencies, a default render backend or OS window/input handling but instead provides a highly modular, library-based approach, with simple input state for input and draw commands describing primitive shapes as output. So instead of providing a layered library that tries to abstract over a number of platform and render backends, it focuses only on the actual UI.
 
Loading...
Searching...
No Matches
nuklear_table.c
1#include "nuklear.h"
2#include "nuklear_internal.h"
3
4/* ===============================================================
5 *
6 * TABLE
7 *
8 * ===============================================================*/
9NK_LIB struct nk_table*
10nk_create_table(struct nk_context *ctx)
11{
12 struct nk_page_element *elem;
13 elem = nk_create_page_element(ctx);
14 if (!elem) return 0;
15 nk_zero_struct(*elem);
16 return &elem->data.tbl;
17}
18NK_LIB void
19nk_free_table(struct nk_context *ctx, struct nk_table *tbl)
20{
21 union nk_page_data *pd = NK_CONTAINER_OF(tbl, union nk_page_data, tbl);
22 struct nk_page_element *pe = NK_CONTAINER_OF(pd, struct nk_page_element, data);
23 nk_free_page_element(ctx, pe);
24}
25NK_LIB void
26nk_push_table(struct nk_window *win, struct nk_table *tbl)
27{
28 if (!win->tables) {
29 win->tables = tbl;
30 tbl->next = 0;
31 tbl->prev = 0;
32 tbl->size = 0;
33 win->table_count = 1;
34 return;
35 }
36 win->tables->prev = tbl;
37 tbl->next = win->tables;
38 tbl->prev = 0;
39 tbl->size = 0;
40 win->tables = tbl;
41 win->table_count++;
42}
43NK_LIB void
44nk_remove_table(struct nk_window *win, struct nk_table *tbl)
45{
46 if (win->tables == tbl)
47 win->tables = tbl->next;
48 if (tbl->next)
49 tbl->next->prev = tbl->prev;
50 if (tbl->prev)
51 tbl->prev->next = tbl->next;
52 tbl->next = 0;
53 tbl->prev = 0;
54}
55NK_LIB nk_uint*
56nk_add_value(struct nk_context *ctx, struct nk_window *win,
57 nk_hash name, nk_uint value)
58{
59 NK_ASSERT(ctx);
60 NK_ASSERT(win);
61 if (!win || !ctx) return 0;
62 if (!win->tables || win->tables->size >= NK_VALUE_PAGE_CAPACITY) {
63 struct nk_table *tbl = nk_create_table(ctx);
64 NK_ASSERT(tbl);
65 if (!tbl) return 0;
66 nk_push_table(win, tbl);
67 }
68 win->tables->seq = win->seq;
69 win->tables->keys[win->tables->size] = name;
70 win->tables->values[win->tables->size] = value;
71 return &win->tables->values[win->tables->size++];
72}
73NK_LIB nk_uint*
74nk_find_value(const struct nk_window *win, nk_hash name)
75{
76 struct nk_table *iter = win->tables;
77 while (iter) {
78 unsigned int i = 0;
79 unsigned int size = iter->size;
80 for (i = 0; i < size; ++i) {
81 if (iter->keys[i] == name) {
82 iter->seq = win->seq;
83 return &iter->values[i];
84 }
85 } size = NK_VALUE_PAGE_CAPACITY;
86 iter = iter->next;
87 }
88 return 0;
89}
main API and documentation file