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 return &elem->data.tbl;
16}
17NK_LIB void
18nk_free_table(struct nk_context *ctx, struct nk_table *tbl)
19{
20 union nk_page_data *pd = NK_CONTAINER_OF(tbl, union nk_page_data, tbl);
21 struct nk_page_element *pe = NK_CONTAINER_OF(pd, struct nk_page_element, data);
22 nk_free_page_element(ctx, pe);
23}
24NK_LIB void
25nk_push_table(struct nk_window *win, struct nk_table *tbl)
26{
27 if (!win->tables) {
28 win->tables = tbl;
29 tbl->next = 0;
30 tbl->prev = 0;
31 tbl->size = 0;
32 win->table_count = 1;
33 return;
34 }
35 win->tables->prev = tbl;
36 tbl->next = win->tables;
37 tbl->prev = 0;
38 tbl->size = 0;
39 win->tables = tbl;
40 win->table_count++;
41}
42NK_LIB void
43nk_remove_table(struct nk_window *win, struct nk_table *tbl)
44{
45 if (win->tables == tbl)
46 win->tables = tbl->next;
47 if (tbl->next)
48 tbl->next->prev = tbl->prev;
49 if (tbl->prev)
50 tbl->prev->next = tbl->next;
51 tbl->next = 0;
52 tbl->prev = 0;
53}
54NK_LIB nk_uint*
55nk_add_value(struct nk_context *ctx, struct nk_window *win,
56 nk_hash name, nk_uint value)
57{
58 NK_ASSERT(ctx);
59 NK_ASSERT(win);
60 if (!win || !ctx) return 0;
61 if (!win->tables || win->tables->size >= NK_VALUE_PAGE_CAPACITY) {
62 struct nk_table *tbl = nk_create_table(ctx);
63 NK_ASSERT(tbl);
64 if (!tbl) return 0;
65 nk_push_table(win, tbl);
66 }
67 win->tables->seq = win->seq;
68 win->tables->keys[win->tables->size] = name;
69 win->tables->values[win->tables->size] = value;
70 return &win->tables->values[win->tables->size++];
71}
72NK_LIB nk_uint*
73nk_find_value(const struct nk_window *win, nk_hash name)
74{
75 struct nk_table *iter = win->tables;
76 while (iter) {
77 unsigned int i = 0;
78 unsigned int size = iter->size;
79 for (i = 0; i < size; ++i) {
80 if (iter->keys[i] == name) {
81 iter->seq = win->seq;
82 return &iter->values[i];
83 }
84 } size = NK_VALUE_PAGE_CAPACITY;
85 iter = iter->next;
86 }
87 return 0;
88}
main API and documentation file