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_page_element.c
1#include "nuklear.h"
2#include "nuklear_internal.h"
3
4/* ===============================================================
5 *
6 * PAGE ELEMENT
7 *
8 * ===============================================================*/
9NK_LIB struct nk_page_element*
10nk_create_page_element(struct nk_context *ctx)
11{
12 struct nk_page_element *elem;
13 if (ctx->freelist) {
14 /* unlink page element from free list */
15 elem = ctx->freelist;
16 ctx->freelist = elem->next;
17 } else if (ctx->use_pool) {
18 /* allocate page element from memory pool */
19 elem = nk_pool_alloc(&ctx->pool);
20 NK_ASSERT(elem);
21 if (!elem) return 0;
22 } else {
23 /* allocate new page element from back of fixed size memory buffer */
24 NK_STORAGE const nk_size size = sizeof(struct nk_page_element);
25 NK_STORAGE const nk_size align = NK_ALIGNOF(struct nk_page_element);
26 elem = (struct nk_page_element*)nk_buffer_alloc(&ctx->memory, NK_BUFFER_BACK, size, align);
27 NK_ASSERT(elem);
28 if (!elem) return 0;
29 }
30 nk_zero_struct(*elem);
31 elem->next = 0;
32 elem->prev = 0;
33 return elem;
34}
35NK_LIB void
36nk_link_page_element_into_freelist(struct nk_context *ctx,
37 struct nk_page_element *elem)
38{
39 /* link table into freelist */
40 if (!ctx->freelist) {
41 ctx->freelist = elem;
42 } else {
43 elem->next = ctx->freelist;
44 ctx->freelist = elem;
45 }
46}
47NK_LIB void
48nk_free_page_element(struct nk_context *ctx, struct nk_page_element *elem)
49{
50 /* we have a pool so just add to free list */
51 if (ctx->use_pool) {
52 nk_link_page_element_into_freelist(ctx, elem);
53 return;
54 }
55 /* if possible remove last element from back of fixed memory buffer */
56 {void *elem_end = (void*)(elem + 1);
57 void *buffer_end = (nk_byte*)ctx->memory.memory.ptr + ctx->memory.size;
58 if (elem_end == buffer_end)
59 ctx->memory.size -= sizeof(struct nk_page_element);
60 else nk_link_page_element_into_freelist(ctx, elem);}
61}
62
main API and documentation file
struct nk_memory memory
!< memory management type
Definition nuklear.h:4193
nk_size size
!< number of allocation calls
Definition nuklear.h:4198