1 
2 //          Copyright Mateusz Muszyński 2018.
3 // Distributed under the Boost Software License, Version 1.0.
4 //    (See accompanying file LICENSE_1_0.txt or copy at
5 //          http://www.boost.org/LICENSE_1_0.txt)
6 
7 module bindbc.nuklear.macros;
8 
9 import bindbc.nuklear.types;
10 import bindbc.nuklear.binddynamic;
11 import bindbc.nuklear.bindstatic;
12 
13 version (NK_ALL)
14 {
15     version = NK_INCLUDE_FIXED_TYPES;
16     version = NK_INCLUDE_DEFAULT_ALLOCATOR;
17     version = NK_INCLUDE_STANDARD_IO;
18     version = NK_INCLUDE_STANDARD_VARARGS;
19     version = NK_INCLUDE_VERTEX_BUFFER_OUTPUT;
20     version = NK_INCLUDE_FONT_BAKING;
21     version = NK_INCLUDE_DEFAULT_FONT;
22     version = NK_INCLUDE_COMMAND_USERDATA;
23     version = NK_BUTTON_TRIGGER_ON_RELEASE;
24     version = NK_ZERO_COMMAND_MEMORY;
25     version = NK_UINT_DRAW_INDEX;
26 }
27 
28 version (D_BetterC)
29 {
30 }
31 else
32 {
33     version = gc_and_throw;
34 }
35 
36 @nogc nothrow {
37     alias nk_command_delegate = void delegate(const(nk_command)*);
38     version(NK_INCLUDE_VERTEX_BUFFER_OUTPUT) {
39         alias nk_draw_command_delegate = void delegate(const(nk_draw_command)*);
40     }
41 }
42 
43 version(gc_and_throw) {
44     alias nk_command_delegate_gc = void delegate(const(nk_command)*);
45     version(NK_INCLUDE_VERTEX_BUFFER_OUTPUT) {
46         alias nk_draw_command_delegate_gc = void delegate(const(nk_draw_command)*);
47     }
48 }
49 
50 pragma(inline, true) {
51     @nogc nothrow
52     void nk_foreach(nk_context* ctx, nk_command_delegate block) {
53         for (auto c = nk__begin(ctx); c != null; c = nk__next(ctx, c)) {
54             block(c);
55         }
56     }
57 
58     @nogc nothrow
59     version(NK_INCLUDE_VERTEX_BUFFER_OUTPUT) {
60         void nk_draw_foreach(nk_context *ctx, const(nk_buffer) *b, nk_draw_command_delegate block) {
61             for (auto c = nk__draw_begin(ctx, b); c != null; c = nk__draw_next(c, b, ctx)) {
62                 block(c);
63             }
64         }
65     }
66     version(gc_and_throw) {
67         void nk_foreach(nk_context* ctx, nk_command_delegate_gc block) {
68             for (auto c = nk__begin(ctx); c != null; c = nk__next(ctx, c)) {
69                 block(c);
70             }
71         }
72 
73         version(NK_INCLUDE_VERTEX_BUFFER_OUTPUT) {
74             void nk_draw_foreach(nk_context *ctx, const(nk_buffer) *b, nk_draw_command_delegate_gc block) {
75                 for (auto c = nk__draw_begin(ctx, b); c != null; c = nk__draw_next(c, b, ctx)) {
76                     block(c);
77                 }
78             }
79         }
80     }
81 }
82 
83 @nogc nothrow {
84     pragma(inline, true) {
85         auto nk_tree_push(size_t line = __LINE__)(nk_context *ctx, nk_tree_type type, const(char) *title, nk_collapse_states state) {
86             return nk_tree_push_hashed(ctx, type, title, state, null, 0, line);
87         }
88 
89         auto nk_tree_push_id(nk_context *ctx, nk_tree_type type, const(char) *title, nk_collapse_states state, int id) {
90             return nk_tree_push_hashed(ctx, type, title, state, null, 0, id);
91         }
92 
93         auto nk_tree_image_push(size_t line = __LINE__)(nk_context *ctx, nk_tree_type type, nk_image img, const(char) *title, nk_collapse_states state) {
94             return nk_tree_image_push_hashed(ctx, type, img, title, state, null, 0, line);
95         }
96         auto nk_tree_image_push_id(nk_context *ctx, nk_tree_type type, nk_image img, const(char) *title, nk_collapse_states state, int id) {
97             return nk_tree_image_push_hashed(ctx, type, img, title, state, null, 0, id);
98         }
99 
100         auto nk_tree_element_push(size_t line = __LINE__)(nk_context *ctx, nk_tree_type type, const(char) *title, nk_collapse_states state, int* selected) {
101             return nk_tree_element_push_hashed(ctx, type, title, state, selected, null, 0, line);
102         }
103         auto nk_tree_element_push_id(nk_context *ctx, nk_tree_type type, const(char) *title, nk_collapse_states state, int* selected, int id) {
104             return nk_tree_element_push_hashed(ctx, type, title, state, selected, null, 0, id);
105         }
106 
107         version(NK_INCLUDE_VERTEX_BUFFER_OUTPUT) {
108             void nk_draw_list_foreach(const(nk_draw_list) *can, const(nk_buffer) *b, nk_draw_command_delegate block) {
109                 for (auto c = nk__draw_list_begin(can, b); c != null; c = nk__draw_list_next(c, b, can)) {
110                     block(c);
111                 }
112             }
113         }
114     }
115 }
116 version(gc_and_throw) {
117     pragma(inline, true) {
118         version(NK_INCLUDE_VERTEX_BUFFER_OUTPUT) {
119             void nk_draw_list_foreach(const(nk_draw_list) *can, const(nk_buffer) *b, nk_draw_command_delegate_gc block) {
120                 for (auto c = nk__draw_list_begin(can, b); c != null; c = nk__draw_list_next(c, b, can)) {
121                     block(c);
122                 }
123             }
124         }
125     }
126 }