├── .gitattributes ├── .gitignore ├── LICENSE_1_0.txt ├── README.md ├── c ├── CMakeLists.txt ├── nuklear.c └── nuklear.h ├── demo ├── .gitignore ├── dub.sdl ├── readme.md └── source │ ├── calculator.d │ ├── main.d │ ├── node_editor.d │ ├── overview.d │ └── style.d ├── dub.sdl ├── include └── .gitignore ├── lib ├── win32 │ └── nuklear.dll └── win64 │ └── nuklear.dll ├── prebuild.sh └── source └── bindbc └── nuklear ├── binddynamic.d ├── bindstatic.d ├── macros.d ├── package.d └── types.d /.gitattributes: -------------------------------------------------------------------------------- 1 | c/* linguist-vendored 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib 2 | dub.selections.json 3 | .dub 4 | nuklear/* 5 | .exe 6 | .dll 7 | .vs 8 | .sln 9 | build 10 | include 11 | -------------------------------------------------------------------------------- /LICENSE_1_0.txt: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bindbc-nuklear 2 | BindBC binding to [Nuklear](https://github.com/Immediate-Mode-UI/Nuklear). 3 | 4 | This library contains prebuild windows dll for Nuklear, on different platforms you can easily build C source code from cmake configuration in c directory. 5 | 6 | You can find original Nuklear examples ported to D inside demo directory. 7 | You can also see an example file browser at https://github.com/dukc/nuklearbrowser. 8 | -------------------------------------------------------------------------------- /c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | 3 | project(nuklear VERSION 4.10.5 DESCRIPTION "Nuklear GUI library") 4 | project(nuklear_static VERSION 4.10.5 DESCRIPTION "Nuklear GUI library") 5 | 6 | add_library(nuklear SHARED nuklear.c) 7 | add_library(nuklear_static STATIC nuklear.c) 8 | 9 | set_target_properties(nuklear PROPERTIES VERSION ${PROJECT_VERSION}) 10 | set_target_properties(nuklear_static PROPERTIES VERSION ${PROJECT_VERSION}) 11 | 12 | set_target_properties(nuklear PROPERTIES PUBLIC_HEADER nuklear.h) 13 | # shared and static version have the same header file so do not install it twice 14 | # set_target_properties(nuklear_static PROPERTIES PUBLIC_HEADER nuklear.h1) 15 | 16 | install(TARGETS nuklear nuklear_static 17 | LIBRARY DESTINATION ${CMAKE_SOURCE_DIR}/../lib 18 | ARCHIVE DESTINATION ${CMAKE_SOURCE_DIR}/../lib 19 | PUBLIC_HEADER DESTINATION ${CMAKE_SOURCE_DIR}/../include) -------------------------------------------------------------------------------- /c/nuklear.c: -------------------------------------------------------------------------------- 1 | 2 | #define NK_INCLUDE_FIXED_TYPES 3 | #define NK_INCLUDE_DEFAULT_ALLOCATOR 4 | #define NK_INCLUDE_STANDARD_IO 5 | #define NK_INCLUDE_STANDARD_VARARGS 6 | #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT 7 | #define NK_INCLUDE_FONT_BAKING 8 | #define NK_INCLUDE_DEFAULT_FONT 9 | #define NK_INCLUDE_COMMAND_USERDATA 10 | #define NK_BUTTON_TRIGGER_ON_RELEASE 11 | #define NK_ZERO_COMMAND_MEMORY 12 | #define NK_UINT_DRAW_INDEX 13 | #define NK_BOOL char 14 | 15 | //#define NK_INPUT_MAX 512 16 | 17 | #ifdef _WIN32 18 | #define NK_API __declspec(dllexport) 19 | #endif 20 | 21 | #include 22 | 23 | #define NK_IMPLEMENTATION 24 | #include "nuklear.h" 25 | -------------------------------------------------------------------------------- /demo/.gitignore: -------------------------------------------------------------------------------- 1 | /nuklear-demo 2 | -------------------------------------------------------------------------------- /demo/dub.sdl: -------------------------------------------------------------------------------- 1 | name "nuklear-demo" 2 | description "demo" 3 | authors "Mateusz Muszynski" 4 | license "BSL-1.0" 5 | dependency "bindbc-nuklear" path="./.." 6 | dependency "bindbc-opengl" version="~>1.0.3" 7 | dependency "bindbc-sdl" version="~>1.2.4" 8 | 9 | 10 | configuration "dynamic" { 11 | targetType "executable" 12 | subConfiguration "bindbc-nuklear" "dynamic" 13 | subConfiguration "bindbc-sdl" "dynamic" 14 | } 15 | 16 | configuration "static" { 17 | targetType "executable" 18 | subConfiguration "bindbc-nuklear" "static" 19 | subConfiguration "bindbc-sdl" "static" 20 | } 21 | 22 | versions "GL_30" "SDL_205" "NK_ALL" 23 | -------------------------------------------------------------------------------- /demo/readme.md: -------------------------------------------------------------------------------- 1 | # Demo of D bingings to nuklear library 2 | 3 | ## Prebuilding 4 | 5 | Before using these demo you need to build `nukear` library. On linux you can do it by running script `prebuild.sh`. This script builds `nuklear` library in `build` directory and install building artifacts into `lib` and `include` directories. These artifacts need to be built once only after project cloning. `SDL` library should be install using system package manager. 6 | 7 | ## Configurations 8 | 9 | There are two configuration: `dynamic` and `static`. The demo uses SDL and nuklear libraries. In dynamic configuration these libraries are used as shared/dynamic libraries (.so/.dll). In static configuration these libraries are used as static libraries (.a). Note: in fact SDL2 library is/could be linked statically to shared library. 10 | Dynamic configuration: 11 | ``` 12 | cd demo 13 | dub # or dub --config=dynamic 14 | ``` 15 | Static configuration: 16 | ``` 17 | cd demo 18 | dub --config=static 19 | ``` -------------------------------------------------------------------------------- /demo/source/calculator.d: -------------------------------------------------------------------------------- 1 | module calculator; 2 | 3 | import bindbc.nuklear; 4 | 5 | import core.stdc.stdio; 6 | import core.stdc.math; 7 | 8 | void 9 | calculator(nk_context *ctx) 10 | { 11 | import core.stdc.stdlib; 12 | if (nk_begin(ctx, "Calculator", nk_rect(10, 10, 180, 250), 13 | NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_MOVABLE|NK_WINDOW_TITLE)) 14 | { 15 | static int set = 0, prev = 0, op = 0; 16 | static const(char)* numbers = "789456123"; 17 | static const(char)* ops = "+-*/"; 18 | static double a = 0, b = 0; 19 | static double *current = null; 20 | 21 | if(current == null) 22 | current = &a; 23 | 24 | size_t i = 0; 25 | int solve = 0; 26 | {int len=3; char[256] buffer; 27 | nk_layout_row_dynamic(ctx, 35, 1); 28 | 29 | len = snprintf(buffer.ptr, 256, "%.2f", *current); 30 | nk_edit_string(ctx, NK_EDIT_SIMPLE, buffer.ptr, &len, 255, &nk_filter_float); 31 | 32 | buffer[len] = 0; 33 | *current = atof(buffer.ptr); 34 | } 35 | 36 | nk_layout_row_dynamic(ctx, 35, 4); 37 | for (i = 0; i < 16; ++i) { 38 | if (i >= 12 && i < 15) { 39 | if (i > 12) continue; 40 | if (nk_button_label(ctx, "C")) { 41 | a = b = op = 0; current = &a; set = 0; 42 | } if (nk_button_label(ctx, "0")) { 43 | *current = *current*10.0f; set = 0; 44 | } if (nk_button_label(ctx, "=")) { 45 | solve = 1; prev = op; op = 0; 46 | } 47 | } else if (((i+1) % 4)) { 48 | if (nk_button_text(ctx, &numbers[(i/4)*3+i%4], 1)) { 49 | *current = *current * 10.0f + numbers[(i/4)*3+i%4] - '0'; 50 | set = 0; 51 | } 52 | } else if (nk_button_text(ctx, &ops[i/4], 1)) { 53 | if (!set) { 54 | if (current != &b) { 55 | current = &b; 56 | } else { 57 | prev = op; 58 | solve = 1; 59 | } 60 | } 61 | op = ops[i/4]; 62 | set = 1; 63 | } 64 | } 65 | if (solve) { 66 | if (prev == '+') a = a + b; 67 | if (prev == '-') a = a - b; 68 | if (prev == '*') a = a * b; 69 | if (prev == '/') a = a / b; 70 | current = &a; 71 | if (set) current = &b; 72 | b = 0; set = 0; 73 | } 74 | } 75 | nk_end(ctx); 76 | } -------------------------------------------------------------------------------- /demo/source/main.d: -------------------------------------------------------------------------------- 1 | import bindbc.sdl; 2 | import bindbc.opengl; 3 | import bindbc.nuklear; 4 | 5 | import core.stdc.string; 6 | import core.stdc.stdlib; 7 | import core.stdc.math; 8 | import core.stdc.stdio; 9 | 10 | import overview; 11 | import calculator; 12 | import style; 13 | import node_editor; 14 | 15 | struct nk_sdl_device { 16 | nk_buffer cmds; 17 | nk_draw_null_texture null_; 18 | GLuint vbo, vao, ebo; 19 | GLuint prog; 20 | GLuint vert_shdr; 21 | GLuint frag_shdr; 22 | GLint attrib_pos; 23 | GLint attrib_uv; 24 | GLint attrib_col; 25 | GLint uniform_tex; 26 | GLint uniform_proj; 27 | GLuint font_tex; 28 | } 29 | 30 | struct nk_sdl_vertex { 31 | float[2] position; 32 | float[2] uv; 33 | nk_byte[4] col; 34 | }; 35 | 36 | struct nk_sdl { 37 | SDL_Window *win; 38 | nk_sdl_device ogl; 39 | nk_context ctx; 40 | nk_font_atlas atlas; 41 | } 42 | 43 | nk_sdl sdl; 44 | 45 | void 46 | nk_sdl_device_create() 47 | { 48 | GLint status; 49 | const(GLchar*) vertex_shader = 50 | q{ 51 | #version 300 es 52 | uniform mat4 ProjMtx; 53 | in vec2 Position; 54 | in vec2 TexCoord; 55 | in vec4 Color; 56 | out vec2 Frag_UV; 57 | out vec4 Frag_Color; 58 | void main() { 59 | Frag_UV = TexCoord; 60 | Frag_Color = Color; 61 | gl_Position = ProjMtx * vec4(Position.xy, 0, 1); 62 | } 63 | }; 64 | const(GLchar*) fragment_shader = 65 | q{ 66 | #version 300 es 67 | precision mediump float; 68 | uniform sampler2D Texture; 69 | in vec2 Frag_UV; 70 | in vec4 Frag_Color; 71 | out vec4 Out_Color; 72 | void main(){ 73 | Out_Color = Frag_Color * texture(Texture, Frag_UV.st); 74 | } 75 | }; 76 | 77 | nk_sdl_device *dev = &sdl.ogl; 78 | nk_buffer_init_default(&dev.cmds); 79 | dev.prog = glCreateProgram(); 80 | dev.vert_shdr = glCreateShader(GL_VERTEX_SHADER); 81 | dev.frag_shdr = glCreateShader(GL_FRAGMENT_SHADER); 82 | glShaderSource(dev.vert_shdr, 1, &vertex_shader, null); 83 | glShaderSource(dev.frag_shdr, 1, &fragment_shader, null); 84 | glCompileShader(dev.vert_shdr); 85 | glCompileShader(dev.frag_shdr); 86 | glGetShaderiv(dev.vert_shdr, GL_COMPILE_STATUS, &status); 87 | assert(status == GL_TRUE); 88 | glGetShaderiv(dev.frag_shdr, GL_COMPILE_STATUS, &status); 89 | assert(status == GL_TRUE); 90 | glAttachShader(dev.prog, dev.vert_shdr); 91 | glAttachShader(dev.prog, dev.frag_shdr); 92 | glLinkProgram(dev.prog); 93 | glGetProgramiv(dev.prog, GL_LINK_STATUS, &status); 94 | assert(status == GL_TRUE); 95 | 96 | dev.uniform_tex = glGetUniformLocation(dev.prog, "Texture"); 97 | dev.uniform_proj = glGetUniformLocation(dev.prog, "ProjMtx"); 98 | dev.attrib_pos = glGetAttribLocation(dev.prog, "Position"); 99 | dev.attrib_uv = glGetAttribLocation(dev.prog, "TexCoord"); 100 | dev.attrib_col = glGetAttribLocation(dev.prog, "Color"); 101 | 102 | { 103 | /* buffer setup */ 104 | GLsizei vs = nk_sdl_vertex.sizeof; 105 | size_t vp = nk_sdl_vertex.position.offsetof; 106 | size_t vt = nk_sdl_vertex.uv.offsetof; 107 | size_t vc = nk_sdl_vertex.col.offsetof; 108 | 109 | glGenBuffers(1, &dev.vbo); 110 | glGenBuffers(1, &dev.ebo); 111 | glGenVertexArrays(1, &dev.vao); 112 | 113 | glBindVertexArray(dev.vao); 114 | glBindBuffer(GL_ARRAY_BUFFER, dev.vbo); 115 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev.ebo); 116 | 117 | glEnableVertexAttribArray(cast(GLuint)dev.attrib_pos); 118 | glEnableVertexAttribArray(cast(GLuint)dev.attrib_uv); 119 | glEnableVertexAttribArray(cast(GLuint)dev.attrib_col); 120 | 121 | glVertexAttribPointer(cast(GLuint)dev.attrib_pos, 2, GL_FLOAT, GL_FALSE, vs, cast(void*)vp); 122 | glVertexAttribPointer(cast(GLuint)dev.attrib_uv, 2, GL_FLOAT, GL_FALSE, vs, cast(void*)vt); 123 | glVertexAttribPointer(cast(GLuint)dev.attrib_col, 4, GL_UNSIGNED_BYTE, GL_TRUE, vs, cast(void*)vc); 124 | } 125 | 126 | glBindTexture(GL_TEXTURE_2D, 0); 127 | glBindBuffer(GL_ARRAY_BUFFER, 0); 128 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 129 | glBindVertexArray(0); 130 | } 131 | 132 | void 133 | nk_sdl_device_upload_atlas(const void *image, int width, int height) 134 | { 135 | nk_sdl_device *dev = &sdl.ogl; 136 | glGenTextures(1, &dev.font_tex); 137 | glBindTexture(GL_TEXTURE_2D, dev.font_tex); 138 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 139 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 140 | glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, cast(GLsizei)width, cast(GLsizei)height, 0, 141 | GL_RGBA, GL_UNSIGNED_BYTE, image); 142 | } 143 | 144 | void 145 | nk_sdl_device_destroy() 146 | { 147 | nk_sdl_device* dev = &sdl.ogl; 148 | glDetachShader(dev.prog, dev.vert_shdr); 149 | glDetachShader(dev.prog, dev.frag_shdr); 150 | glDeleteShader(dev.vert_shdr); 151 | glDeleteShader(dev.frag_shdr); 152 | glDeleteProgram(dev.prog); 153 | glDeleteTextures(1, &dev.font_tex); 154 | glDeleteBuffers(1, &dev.vbo); 155 | glDeleteBuffers(1, &dev.ebo); 156 | nk_buffer_free(&dev.cmds); 157 | } 158 | 159 | nk_vec2 scale; 160 | int width, height; 161 | const(nk_draw_index) *offset = null; 162 | 163 | void 164 | nk_sdl_render(nk_anti_aliasing AA, int max_vertex_buffer, int max_element_buffer) 165 | { 166 | nk_sdl_device *dev = &sdl.ogl; 167 | int display_width, display_height; 168 | GLfloat[4][4] ortho = [ 169 | [2.0f, 0.0f, 0.0f, 0.0f], 170 | [0.0f,-2.0f, 0.0f, 0.0f], 171 | [0.0f, 0.0f,-1.0f, 0.0f], 172 | [-1.0f,1.0f, 0.0f, 1.0f], 173 | ]; 174 | SDL_GetWindowSize(sdl.win, &width, &height); 175 | SDL_GL_GetDrawableSize(sdl.win, &display_width, &display_height); 176 | ortho[0][0] /= cast(GLfloat)width; 177 | ortho[1][1] /= cast(GLfloat)height; 178 | 179 | scale.x = display_width/cast(float)width; 180 | scale.y = display_height/cast(float)height; 181 | 182 | /* setup global state */ 183 | glViewport(0,0,display_width,display_height); 184 | glEnable(GL_BLEND); 185 | glBlendEquation(GL_FUNC_ADD); 186 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 187 | glDisable(GL_CULL_FACE); 188 | glDisable(GL_DEPTH_TEST); 189 | glEnable(GL_SCISSOR_TEST); 190 | glActiveTexture(GL_TEXTURE0); 191 | 192 | /* setup program */ 193 | glUseProgram(dev.prog); 194 | glUniform1i(dev.uniform_tex, 0); 195 | glUniformMatrix4fv(dev.uniform_proj, 1, GL_FALSE, &ortho[0][0]); 196 | { 197 | /* convert from command queue into draw list and draw to screen */ 198 | const(nk_draw_command) *cmd; 199 | void *vertices; 200 | void *elements; 201 | offset = null; 202 | nk_buffer vbuf; 203 | nk_buffer ebuf; 204 | 205 | /* allocate vertex and element buffer */ 206 | glBindVertexArray(dev.vao); 207 | glBindBuffer(GL_ARRAY_BUFFER, dev.vbo); 208 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dev.ebo); 209 | 210 | glBufferData(GL_ARRAY_BUFFER, max_vertex_buffer, null, GL_STREAM_DRAW); 211 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, max_element_buffer, null, GL_STREAM_DRAW); 212 | 213 | /* load vertices/elements directly into vertex/element buffer */ 214 | vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_WRITE_ONLY); 215 | elements = glMapBuffer(GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY); 216 | { 217 | /* fill convert configuration */ 218 | nk_convert_config config; 219 | const(nk_draw_vertex_layout_element)[4] vertex_layout = [ 220 | {nk_draw_vertex_layout_attribute.NK_VERTEX_POSITION, nk_draw_vertex_layout_format.NK_FORMAT_FLOAT, nk_sdl_vertex.position.offsetof}, 221 | {nk_draw_vertex_layout_attribute.NK_VERTEX_TEXCOORD, nk_draw_vertex_layout_format.NK_FORMAT_FLOAT, nk_sdl_vertex.uv.offsetof}, 222 | {nk_draw_vertex_layout_attribute.NK_VERTEX_COLOR, nk_draw_vertex_layout_format.NK_FORMAT_R8G8B8A8, nk_sdl_vertex.col.offsetof}, 223 | NK_VERTEX_LAYOUT_END 224 | ]; 225 | memset(&config, 0, config.sizeof); 226 | config.vertex_layout = vertex_layout.ptr; 227 | config.vertex_size = nk_sdl_vertex.sizeof; 228 | config.vertex_alignment = nk_sdl_vertex.alignof; 229 | config.tex_null = dev.null_; 230 | config.circle_segment_count = 22; 231 | config.curve_segment_count = 22; 232 | config.arc_segment_count = 22; 233 | config.global_alpha = 1.0f; 234 | config.shape_AA = AA; 235 | config.line_AA = AA; 236 | 237 | /* setup buffers to load vertices and elements */ 238 | nk_buffer_init_fixed(&vbuf, vertices, cast(nk_size)max_vertex_buffer); 239 | nk_buffer_init_fixed(&ebuf, elements, cast(nk_size)max_element_buffer); 240 | nk_convert(&sdl.ctx, &dev.cmds, &vbuf, &ebuf, &config); 241 | } 242 | glUnmapBuffer(GL_ARRAY_BUFFER); 243 | glUnmapBuffer(GL_ELEMENT_ARRAY_BUFFER); 244 | 245 | /* iterate over and execute each draw command */ 246 | nk_draw_foreach(&sdl.ctx, &dev.cmds, (cmd) 247 | { 248 | if (!cmd.elem_count) return; 249 | glBindTexture(GL_TEXTURE_2D, cast(GLuint)cmd.texture.id); 250 | glScissor(cast(GLint)(cmd.clip_rect.x * scale.x), 251 | cast(GLint)((height - cast(GLint)(cmd.clip_rect.y + cmd.clip_rect.h)) * scale.y), 252 | cast(GLint)(cmd.clip_rect.w * scale.x), 253 | cast(GLint)(cmd.clip_rect.h * scale.y)); 254 | glDrawElements(GL_TRIANGLES, cast(GLsizei)cmd.elem_count, GL_UNSIGNED_INT, offset); 255 | offset += cmd.elem_count; 256 | }); 257 | nk_clear(&sdl.ctx); 258 | } 259 | 260 | glUseProgram(0); 261 | glBindBuffer(GL_ARRAY_BUFFER, 0); 262 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 263 | glBindVertexArray(0); 264 | glDisable(GL_BLEND); 265 | glDisable(GL_SCISSOR_TEST); 266 | } 267 | extern(C) 268 | void 269 | nk_sdl_clipboard_paste(nk_handle usr, nk_text_edit *edit) 270 | { 271 | const char *text = SDL_GetClipboardText(); 272 | if (text) nk_textedit_paste(edit, text, nk_strlen(text)); 273 | } 274 | 275 | extern(C) 276 | void 277 | nk_sdl_clipboard_copy(nk_handle usr, const(char) *text, int len) 278 | { 279 | import core.stdc.string; 280 | import core.stdc.stdlib; 281 | char *str = null; 282 | if (!len) return; 283 | str = cast(char*)malloc(cast(size_t)len+1); 284 | if (!str) return; 285 | memcpy(str, text, cast(size_t)len); 286 | str[len] = '\0'; 287 | SDL_SetClipboardText(str); 288 | free(str); 289 | } 290 | 291 | 292 | nk_context* 293 | nk_sdl_init(SDL_Window *win) 294 | { 295 | sdl.win = win; 296 | nk_init_default(&sdl.ctx, null); 297 | sdl.ctx.clip.copy = cast(nk_plugin_copy)&nk_sdl_clipboard_copy; 298 | sdl.ctx.clip.paste = cast(nk_plugin_paste)&nk_sdl_clipboard_paste; 299 | sdl.ctx.clip.userdata = nk_handle_ptr(null); 300 | nk_sdl_device_create(); 301 | return &sdl.ctx; 302 | } 303 | 304 | void 305 | nk_sdl_font_stash_begin(nk_font_atlas **atlas) 306 | { 307 | nk_font_atlas_init_default(&sdl.atlas); 308 | nk_font_atlas_begin(&sdl.atlas); 309 | *atlas = &sdl.atlas; 310 | } 311 | 312 | void 313 | nk_sdl_font_stash_end() 314 | { 315 | const(void) *image; int w; int h; 316 | image = nk_font_atlas_bake(&sdl.atlas, &w, &h, nk_font_atlas_format.NK_FONT_ATLAS_RGBA32); 317 | nk_sdl_device_upload_atlas(image, w, h); 318 | nk_font_atlas_end(&sdl.atlas, nk_handle_id(cast(int)sdl.ogl.font_tex), &sdl.ogl.null_); 319 | if (sdl.atlas.default_font) 320 | nk_style_set_font(&sdl.ctx, &sdl.atlas.default_font.handle); 321 | } 322 | 323 | int 324 | nk_sdl_handle_event(SDL_Event *evt) 325 | { 326 | nk_context *ctx = &sdl.ctx; 327 | 328 | /* optional grabbing behavior */ 329 | if (ctx.input.mouse.grab) { 330 | SDL_SetRelativeMouseMode(SDL_TRUE); 331 | ctx.input.mouse.grab = 0; 332 | } else if (ctx.input.mouse.ungrab) { 333 | int x = cast(int)ctx.input.mouse.prev.x, y = cast(int)ctx.input.mouse.prev.y; 334 | SDL_SetRelativeMouseMode(SDL_FALSE); 335 | SDL_WarpMouseInWindow(sdl.win, x, y); 336 | ctx.input.mouse.ungrab = 0; 337 | } 338 | if (evt.type == SDL_KEYUP || evt.type == SDL_KEYDOWN) { 339 | /* key events */ 340 | bool down = evt.type == SDL_KEYDOWN; 341 | const Uint8* state = SDL_GetKeyboardState(null); 342 | SDL_Keycode sym = evt.key.keysym.sym; 343 | if (sym == SDLK_RSHIFT || sym == SDLK_LSHIFT) 344 | nk_input_key(ctx, nk_keys.NK_KEY_SHIFT, down); 345 | else if (sym == SDLK_DELETE) 346 | nk_input_key(ctx, nk_keys.NK_KEY_DEL, down); 347 | else if (sym == SDLK_RETURN) 348 | nk_input_key(ctx, nk_keys.NK_KEY_ENTER, down); 349 | else if (sym == SDLK_TAB) 350 | nk_input_key(ctx, nk_keys.NK_KEY_TAB, down); 351 | else if (sym == SDLK_BACKSPACE) 352 | nk_input_key(ctx, nk_keys.NK_KEY_BACKSPACE, down); 353 | else if (sym == SDLK_HOME) { 354 | nk_input_key(ctx, nk_keys.NK_KEY_TEXT_START, down); 355 | nk_input_key(ctx, nk_keys.NK_KEY_SCROLL_START, down); 356 | } else if (sym == SDLK_END) { 357 | nk_input_key(ctx, nk_keys.NK_KEY_TEXT_END, down); 358 | nk_input_key(ctx, nk_keys.NK_KEY_SCROLL_END, down); 359 | } else if (sym == SDLK_PAGEDOWN) { 360 | nk_input_key(ctx, nk_keys.NK_KEY_SCROLL_DOWN, down); 361 | } else if (sym == SDLK_PAGEUP) { 362 | nk_input_key(ctx, nk_keys.NK_KEY_SCROLL_UP, down); 363 | } else if (sym == SDLK_z) 364 | nk_input_key(ctx, nk_keys.NK_KEY_TEXT_UNDO, down && state[SDL_SCANCODE_LCTRL]); 365 | else if (sym == SDLK_r) 366 | nk_input_key(ctx, nk_keys.NK_KEY_TEXT_REDO, down && state[SDL_SCANCODE_LCTRL]); 367 | else if (sym == SDLK_c) 368 | nk_input_key(ctx, nk_keys.NK_KEY_COPY, down && state[SDL_SCANCODE_LCTRL]); 369 | else if (sym == SDLK_v) 370 | nk_input_key(ctx, nk_keys.NK_KEY_PASTE, down && state[SDL_SCANCODE_LCTRL]); 371 | else if (sym == SDLK_x) 372 | nk_input_key(ctx, nk_keys.NK_KEY_CUT, down && state[SDL_SCANCODE_LCTRL]); 373 | else if (sym == SDLK_b) 374 | nk_input_key(ctx, nk_keys.NK_KEY_TEXT_LINE_START, down && state[SDL_SCANCODE_LCTRL]); 375 | else if (sym == SDLK_e) 376 | nk_input_key(ctx, nk_keys.NK_KEY_TEXT_LINE_END, down && state[SDL_SCANCODE_LCTRL]); 377 | else if (sym == SDLK_UP) 378 | nk_input_key(ctx, nk_keys.NK_KEY_UP, down); 379 | else if (sym == SDLK_DOWN) 380 | nk_input_key(ctx, nk_keys.NK_KEY_DOWN, down); 381 | else if (sym == SDLK_LEFT) { 382 | if (state[SDL_SCANCODE_LCTRL]) 383 | nk_input_key(ctx, nk_keys.NK_KEY_TEXT_WORD_LEFT, down); 384 | else nk_input_key(ctx, nk_keys.NK_KEY_LEFT, down); 385 | } else if (sym == SDLK_RIGHT) { 386 | if (state[SDL_SCANCODE_LCTRL]) 387 | nk_input_key(ctx, nk_keys.NK_KEY_TEXT_WORD_RIGHT, down); 388 | else nk_input_key(ctx, nk_keys.NK_KEY_RIGHT, down); 389 | } else return 0; 390 | return 1; 391 | } else if (evt.type == SDL_MOUSEBUTTONDOWN || evt.type == SDL_MOUSEBUTTONUP) { 392 | /* mouse button */ 393 | bool down = evt.type == SDL_MOUSEBUTTONDOWN; 394 | const int x = evt.button.x, y = evt.button.y; 395 | if (evt.button.button == SDL_BUTTON_LEFT) { 396 | if (evt.button.clicks > 1) 397 | nk_input_button(ctx, nk_buttons.NK_BUTTON_DOUBLE, x, y, down); 398 | nk_input_button(ctx, nk_buttons.NK_BUTTON_LEFT, x, y, down); 399 | } else if (evt.button.button == SDL_BUTTON_MIDDLE) 400 | nk_input_button(ctx, nk_buttons.NK_BUTTON_MIDDLE, x, y, down); 401 | else if (evt.button.button == SDL_BUTTON_RIGHT) 402 | nk_input_button(ctx, nk_buttons.NK_BUTTON_RIGHT, x, y, down); 403 | return 1; 404 | } else if (evt.type == SDL_MOUSEMOTION) { 405 | /* mouse motion */ 406 | if (ctx.input.mouse.grabbed) { 407 | int x = cast(int)ctx.input.mouse.prev.x, y = cast(int)ctx.input.mouse.prev.y; 408 | nk_input_motion(ctx, x + evt.motion.xrel, y + evt.motion.yrel); 409 | } else nk_input_motion(ctx, evt.motion.x, evt.motion.y); 410 | return 1; 411 | } else if (evt.type == SDL_TEXTINPUT) { 412 | /* text input */ 413 | nk_glyph glyph; 414 | memcpy(cast(void*)glyph.ptr, cast(void*)evt.text.text, NK_UTF_SIZE); 415 | nk_input_glyph(ctx, glyph.ptr); 416 | return 1; 417 | } else if (evt.type == SDL_MOUSEWHEEL) { 418 | /* mouse wheel */ 419 | nk_input_scroll(ctx,nk_vec2(cast(float)evt.wheel.x,cast(float)evt.wheel.y)); 420 | return 1; 421 | } 422 | return 0; 423 | } 424 | 425 | void nk_sdl_shutdown() 426 | { 427 | nk_font_atlas_clear(&sdl.atlas); 428 | nk_free(&sdl.ctx); 429 | nk_sdl_device_destroy(); 430 | memset(&sdl, 0, sdl.sizeof); 431 | } 432 | 433 | extern(C) int main() 434 | { 435 | int win_width= 1200; 436 | int win_height = 800; 437 | 438 | version(BindNuklear_Static) {} 439 | else 440 | { 441 | NuklearSupport nuksup = loadNuklear(); 442 | if(nuksup != NuklearSupport.Nuklear4) 443 | { 444 | printf("Error: Nuklear library is not found."); 445 | return -1; 446 | } 447 | } 448 | 449 | version(BindSDL_Static) {} 450 | else 451 | { 452 | SDLSupport sdlsup = loadSDL(); 453 | if (sdlsup != sdlSupport) 454 | { 455 | if (sdlsup == SDLSupport.badLibrary) 456 | printf("Warning: failed to load some SDL functions. It seems that you have an old version of SDL."); 457 | else 458 | { 459 | printf("Error: SDL library is not found. Please, install SDL 2.0.5"); 460 | return -1; 461 | } 462 | } 463 | } 464 | 465 | if (SDL_Init(SDL_INIT_EVERYTHING) == -1) 466 | { 467 | printf("Error: failed to init SDL: %s\n", SDL_GetError()); 468 | return -1; 469 | } 470 | 471 | 472 | SDL_GL_SetAttribute (SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); 473 | SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); 474 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); 475 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); 476 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 477 | 478 | SDL_Window *win = SDL_CreateWindow("Demo", 479 | SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 480 | 1200, 800, SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN); 481 | SDL_GLContext glContext = SDL_GL_CreateContext(win); 482 | GLSupport glsup = loadOpenGL(); 483 | if (!isOpenGLLoaded()) 484 | { 485 | printf("Error: failed to load OpenGL functions. Please, update graphics card driver and make sure it supports OpenGL"); 486 | return -1; 487 | } 488 | 489 | SDL_GL_SetSwapInterval(1); 490 | 491 | glViewport(0, 0, win_width, win_height); 492 | 493 | nk_context *ctx; 494 | nk_colorf bg; 495 | ctx = nk_sdl_init(win); 496 | 497 | nk_font_atlas *atlas; 498 | nk_sdl_font_stash_begin(&atlas); 499 | nk_sdl_font_stash_end(); 500 | 501 | style.theme them = style.theme.THEME_BLUE; 502 | style.set_style(ctx, them); 503 | 504 | bg.r = 0.10f, bg.g = 0.18f, bg.b = 0.24f, bg.a = 1.0f; 505 | enum {EASY, HARD} 506 | int op = EASY; 507 | int property = 20; 508 | 509 | bool running = true; 510 | while(running) 511 | { 512 | /* Input */ 513 | SDL_Event evt; 514 | nk_input_begin(ctx); 515 | while (SDL_PollEvent(&evt)) { 516 | if (evt.type == SDL_QUIT) 517 | { 518 | running = false; 519 | continue; 520 | } 521 | nk_sdl_handle_event(&evt); 522 | } 523 | nk_input_end(ctx); 524 | 525 | calculator.calculator(ctx); 526 | 527 | if (nk_begin(ctx, "Demo", nk_rect(50, 50, 230, 250), 528 | NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE| 529 | NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE)) 530 | { 531 | nk_layout_row_static(ctx, 30, 80, 1); 532 | if (nk_button_label(ctx, "button")) 533 | { 534 | printf("button pressed\n"); 535 | } 536 | if (nk_button_label(ctx, "style")) 537 | { 538 | them += 1; 539 | if(them > style.theme.max) 540 | them = style.theme.min; 541 | style.set_style(ctx, them); 542 | } 543 | nk_layout_row_dynamic(ctx, 30, 2); 544 | if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; 545 | if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; 546 | nk_layout_row_dynamic(ctx, 25, 1); 547 | nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); 548 | 549 | nk_layout_row_dynamic(ctx, 20, 1); 550 | nk_label(ctx, "background:", NK_TEXT_LEFT); 551 | nk_layout_row_dynamic(ctx, 25, 1); 552 | if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400))) { 553 | nk_layout_row_dynamic(ctx, 120, 1); 554 | bg = nk_color_picker(ctx, bg, NK_RGBA); 555 | nk_layout_row_dynamic(ctx, 25, 1); 556 | bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f); 557 | bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f); 558 | bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f); 559 | bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f); 560 | nk_combo_end(ctx); 561 | } 562 | } 563 | nk_end(ctx); 564 | 565 | overview.overview(ctx); 566 | node_editor.node_editor(ctx); 567 | 568 | /* Draw */ 569 | SDL_GetWindowSize(win, &win_width, &win_height); 570 | glViewport(0, 0, win_width, win_height); 571 | glClear(GL_COLOR_BUFFER_BIT); 572 | glClearColor(bg.r, bg.g, bg.b, bg.a); 573 | /* IMPORTANT: `nk_sdl_render` modifies some global OpenGL state 574 | * with blending, scissor, face culling, depth test and viewport and 575 | * defaults everything back into a default state. 576 | * Make sure to either a.) save and restore or b.) reset your own state after 577 | * rendering the UI. */ 578 | nk_sdl_render(NK_ANTI_ALIASING_ON,512*1024, 128*1024); 579 | SDL_GL_SwapWindow(win); 580 | } 581 | nk_sdl_shutdown(); 582 | SDL_GL_DeleteContext(glContext); 583 | SDL_DestroyWindow(win); 584 | SDL_Quit(); 585 | 586 | return 0; 587 | } 588 | 589 | -------------------------------------------------------------------------------- /demo/source/node_editor.d: -------------------------------------------------------------------------------- 1 | module node_editor; 2 | 3 | import bindbc.nuklear; 4 | 5 | import core.stdc.stdio; 6 | import core.stdc.stdlib; 7 | import core.stdc.string; 8 | import core.stdc.math; 9 | 10 | struct node { 11 | int ID; 12 | char[32] name; 13 | nk_rect bounds; 14 | float value; 15 | nk_color color; 16 | int input_count; 17 | int output_count; 18 | node *next; 19 | node *prev; 20 | } 21 | 22 | struct node_link { 23 | int input_id; 24 | int input_slot; 25 | int output_id; 26 | int output_slot; 27 | nk_vec2 in_; 28 | nk_vec2 out_; 29 | } 30 | 31 | struct node_linking { 32 | int active; 33 | node *node_; 34 | int input_id; 35 | int input_slot; 36 | } 37 | 38 | struct node_editor_ { 39 | int initialized; 40 | node[32] node_buf; 41 | node_link[64] links; 42 | node *begin; 43 | node *end; 44 | int node_count; 45 | int link_count; 46 | nk_rect bounds; 47 | node *selected; 48 | int show_grid; 49 | nk_vec2 scrolling; 50 | node_linking linking; 51 | } 52 | 53 | node_editor_ nodeEditor; 54 | 55 | static void 56 | node_editor_push(node_editor_ *editor, node *node) 57 | { 58 | if (!editor.begin) { 59 | node.next = null; 60 | node.prev = null; 61 | editor.begin = node; 62 | editor.end = node; 63 | } else { 64 | node.prev = editor.end; 65 | if (editor.end) 66 | editor.end.next = node; 67 | node.next = null; 68 | editor.end = node; 69 | } 70 | } 71 | 72 | static void 73 | node_editor_pop(node_editor_ *editor, node *node) 74 | { 75 | if (node.next) 76 | node.next.prev = node.prev; 77 | if (node.prev) 78 | node.prev.next = node.next; 79 | if (editor.end == node) 80 | editor.end = node.prev; 81 | if (editor.begin == node) 82 | editor.begin = node.next; 83 | node.next = null; 84 | node.prev = null; 85 | } 86 | 87 | static node* 88 | node_editor_find(node_editor_ *editor, int ID) 89 | { 90 | node *iter = editor.begin; 91 | while (iter) { 92 | if (iter.ID == ID) 93 | return iter; 94 | iter = iter.next; 95 | } 96 | return null; 97 | } 98 | 99 | static void 100 | node_editor_add(node_editor_ *editor, const(char) *name, nk_rect bounds, 101 | nk_color col, int in_count, int out_count) 102 | { 103 | static int IDs = 0; 104 | node *node; 105 | assert(cast(nk_size)editor.node_count < editor.node_buf.length); 106 | node = &editor.node_buf[editor.node_count++]; 107 | node.ID = IDs++; 108 | node.value = 0; 109 | node.color = nk_rgb(255, 0, 0); 110 | node.input_count = in_count; 111 | node.output_count = out_count; 112 | node.color = col; 113 | node.bounds = bounds; 114 | strcpy(node.name.ptr, name); 115 | node_editor_push(editor, node); 116 | } 117 | 118 | static void 119 | node_editor_link(node_editor_ *editor, int in_id, int in_slot, 120 | int out_id, int out_slot) 121 | { 122 | node_link *link; 123 | assert(cast(nk_size)editor.link_count < editor.links.length); 124 | link = &editor.links[editor.link_count++]; 125 | link.input_id = in_id; 126 | link.input_slot = in_slot; 127 | link.output_id = out_id; 128 | link.output_slot = out_slot; 129 | } 130 | 131 | static void 132 | node_editor_init(node_editor_ *editor) 133 | { 134 | memset(editor, 0, (*editor).sizeof); 135 | editor.begin = null; 136 | editor.end = null; 137 | node_editor_add(editor, "Source", nk_rect(40, 10, 180, 220), nk_rgb(255, 0, 0), 0, 1); 138 | node_editor_add(editor, "Source", nk_rect(40, 260, 180, 220), nk_rgb(0, 255, 0), 0, 1); 139 | node_editor_add(editor, "Combine", nk_rect(400, 100, 180, 220), nk_rgb(0,0,255), 2, 2); 140 | node_editor_link(editor, 0, 0, 2, 0); 141 | node_editor_link(editor, 1, 0, 2, 1); 142 | editor.show_grid = nk_true; 143 | } 144 | 145 | static int 146 | node_editor(nk_context *ctx) 147 | { 148 | int n = 0; 149 | nk_rect total_space; 150 | const(nk_input) *in_ = &ctx.input; 151 | nk_command_buffer *canvas; 152 | node *updated = null; 153 | node_editor_ *nodedit = &nodeEditor; 154 | 155 | if (!nodeEditor.initialized) { 156 | node_editor_init(&nodeEditor); 157 | nodeEditor.initialized = 1; 158 | } 159 | 160 | if (nk_begin(ctx, "NodeEdit", nk_rect(0, 0, 800, 600), 161 | NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) 162 | { 163 | /* allocate complete window space */ 164 | canvas = nk_window_get_canvas(ctx); 165 | total_space = nk_window_get_content_region(ctx); 166 | nk_layout_space_begin(ctx, NK_STATIC, total_space.h, nodedit.node_count); 167 | { 168 | node *it = nodedit.begin; 169 | nk_rect size = nk_layout_space_bounds(ctx); 170 | nk_panel *node_panel = null; 171 | 172 | if (nodedit.show_grid) { 173 | /* display grid */ 174 | float x, y; 175 | const float grid_size = 32.0f; 176 | const nk_color grid_color = nk_rgb(50, 50, 50); 177 | for (x = cast(float)fmod(size.x - nodedit.scrolling.x, grid_size); x < size.w; x += grid_size) 178 | nk_stroke_line(canvas, x+size.x, size.y, x+size.x, size.y+size.h, 1.0f, grid_color); 179 | for (y = cast(float)fmod(size.y - nodedit.scrolling.y, grid_size); y < size.h; y += grid_size) 180 | nk_stroke_line(canvas, size.x, y+size.y, size.x+size.w, y+size.y, 1.0f, grid_color); 181 | } 182 | 183 | /* execute each node as a movable group */ 184 | while (it) { 185 | /* calculate scrolled node window position and size */ 186 | nk_layout_space_push(ctx, nk_rect(it.bounds.x - nodedit.scrolling.x, 187 | it.bounds.y - nodedit.scrolling.y, it.bounds.w, it.bounds.h)); 188 | 189 | /* execute node window */ 190 | if (nk_group_begin(ctx, it.name.ptr, NK_WINDOW_MOVABLE|NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_TITLE)) 191 | { 192 | /* always have last selected node on top */ 193 | 194 | node_panel = nk_window_get_panel(ctx); 195 | if (nk_input_mouse_clicked(in_, NK_BUTTON_LEFT, node_panel.bounds) && 196 | (!(it.prev && nk_input_mouse_clicked(in_, NK_BUTTON_LEFT, 197 | nk_layout_space_rect_to_screen(ctx, node_panel.bounds)))) && 198 | nodedit.end != it) 199 | { 200 | updated = it; 201 | } 202 | 203 | /* ================= NODE CONTENT =====================*/ 204 | nk_layout_row_dynamic(ctx, 25, 1); 205 | nk_button_color(ctx, it.color); 206 | it.color.r = cast(nk_byte)nk_propertyi(ctx, "#R:", 0, it.color.r, 255, 1,1); 207 | it.color.g = cast(nk_byte)nk_propertyi(ctx, "#G:", 0, it.color.g, 255, 1,1); 208 | it.color.b = cast(nk_byte)nk_propertyi(ctx, "#B:", 0, it.color.b, 255, 1,1); 209 | it.color.a = cast(nk_byte)nk_propertyi(ctx, "#A:", 0, it.color.a, 255, 1,1); 210 | /* ====================================================*/ 211 | nk_group_end(ctx); 212 | } 213 | { 214 | /* node connector and linking */ 215 | float space; 216 | nk_rect bounds; 217 | bounds = nk_layout_space_rect_to_local(ctx, node_panel.bounds); 218 | bounds.x += nodedit.scrolling.x; 219 | bounds.y += nodedit.scrolling.y; 220 | it.bounds = bounds; 221 | 222 | /* output connector */ 223 | space = node_panel.bounds.h / cast(float)((it.output_count) + 1); 224 | for (n = 0; n < it.output_count; ++n) { 225 | nk_rect circle; 226 | circle.x = node_panel.bounds.x + node_panel.bounds.w-4; 227 | circle.y = node_panel.bounds.y + space * cast(float)(n+1); 228 | circle.w = 8; circle.h = 8; 229 | nk_fill_circle(canvas, circle, nk_rgb(100, 100, 100)); 230 | 231 | /* start linking process */ 232 | if (nk_input_has_mouse_click_down_in_rect(in_, NK_BUTTON_LEFT, circle, nk_true)) { 233 | nodedit.linking.active = nk_true; 234 | nodedit.linking.node_ = it; 235 | nodedit.linking.input_id = it.ID; 236 | nodedit.linking.input_slot = n; 237 | } 238 | 239 | /* draw curve from linked node slot to mouse position */ 240 | if (nodedit.linking.active && nodedit.linking.node_ == it && 241 | nodedit.linking.input_slot == n) { 242 | nk_vec2 l0 = nk_vec2(circle.x + 3, circle.y + 3); 243 | nk_vec2 l1 = in_.mouse.pos; 244 | nk_stroke_curve(canvas, l0.x, l0.y, l0.x + 50.0f, l0.y, 245 | l1.x - 50.0f, l1.y, l1.x, l1.y, 1.0f, nk_rgb(100, 100, 100)); 246 | } 247 | } 248 | 249 | /* input connector */ 250 | space = node_panel.bounds.h / cast(float)((it.input_count) + 1); 251 | for (n = 0; n < it.input_count; ++n) { 252 | nk_rect circle; 253 | circle.x = node_panel.bounds.x-4; 254 | circle.y = node_panel.bounds.y + space * cast(float)(n+1); 255 | circle.w = 8; circle.h = 8; 256 | nk_fill_circle(canvas, circle, nk_rgb(100, 100, 100)); 257 | if (nk_input_is_mouse_released(in_, NK_BUTTON_LEFT) && 258 | nk_input_is_mouse_hovering_rect(in_, circle) && 259 | nodedit.linking.active && nodedit.linking.node_ != it) { 260 | nodedit.linking.active = nk_false; 261 | node_editor_link(nodedit, nodedit.linking.input_id, 262 | nodedit.linking.input_slot, it.ID, n); 263 | } 264 | } 265 | } 266 | it = it.next; 267 | } 268 | 269 | /* reset linking connection */ 270 | if (nodedit.linking.active && nk_input_is_mouse_released(in_, NK_BUTTON_LEFT)) { 271 | nodedit.linking.active = nk_false; 272 | nodedit.linking.node_ = null; 273 | fprintf(stdout, "linking failed\n"); 274 | } 275 | 276 | /* draw each link */ 277 | for (n = 0; n < nodedit.link_count; ++n) { 278 | node_link *link = &nodedit.links[n]; 279 | node *ni = node_editor_find(nodedit, link.input_id); 280 | node *no = node_editor_find(nodedit, link.output_id); 281 | float spacei = node_panel.bounds.h / cast(float)((ni.output_count) + 1); 282 | float spaceo = node_panel.bounds.h / cast(float)((no.input_count) + 1); 283 | nk_vec2 l0 = nk_layout_space_to_screen(ctx, 284 | nk_vec2(ni.bounds.x + ni.bounds.w, 3.0f + ni.bounds.y + spacei * cast(float)(link.input_slot+1))); 285 | nk_vec2 l1 = nk_layout_space_to_screen(ctx, 286 | nk_vec2(no.bounds.x, 3.0f + no.bounds.y + spaceo * cast(float)(link.output_slot+1))); 287 | 288 | l0.x -= nodedit.scrolling.x; 289 | l0.y -= nodedit.scrolling.y; 290 | l1.x -= nodedit.scrolling.x; 291 | l1.y -= nodedit.scrolling.y; 292 | nk_stroke_curve(canvas, l0.x, l0.y, l0.x + 50.0f, l0.y, 293 | l1.x - 50.0f, l1.y, l1.x, l1.y, 1.0f, nk_rgb(100, 100, 100)); 294 | } 295 | 296 | if (updated) { 297 | /* reshuffle nodes to have least recently selected node on top */ 298 | node_editor_pop(nodedit, updated); 299 | node_editor_push(nodedit, updated); 300 | } 301 | 302 | /* node selection */ 303 | if (nk_input_mouse_clicked(in_, NK_BUTTON_LEFT, nk_layout_space_bounds(ctx))) { 304 | it = nodedit.begin; 305 | nodedit.selected = null; 306 | nodedit.bounds = nk_rect(in_.mouse.pos.x, in_.mouse.pos.y, 100, 200); 307 | while (it) { 308 | nk_rect b = nk_layout_space_rect_to_screen(ctx, it.bounds); 309 | b.x -= nodedit.scrolling.x; 310 | b.y -= nodedit.scrolling.y; 311 | if (nk_input_is_mouse_hovering_rect(in_, b)) 312 | nodedit.selected = it; 313 | it = it.next; 314 | } 315 | } 316 | 317 | /* contextual menu */ 318 | if (nk_contextual_begin(ctx, 0, nk_vec2(100, 220), nk_window_get_bounds(ctx))) { 319 | const(char) *[2]grid_option = ["Show Grid", "Hide Grid"]; 320 | nk_layout_row_dynamic(ctx, 25, 1); 321 | if (nk_contextual_item_label(ctx, "New", NK_TEXT_CENTERED)) 322 | node_editor_add(nodedit, "New", nk_rect(400, 260, 180, 220), 323 | nk_rgb(255, 255, 255), 1, 2); 324 | if (nk_contextual_item_label(ctx, grid_option[nodedit.show_grid],NK_TEXT_CENTERED)) 325 | nodedit.show_grid = !nodedit.show_grid; 326 | nk_contextual_end(ctx); 327 | } 328 | } 329 | nk_layout_space_end(ctx); 330 | 331 | /* window content scrolling */ 332 | if (nk_input_is_mouse_hovering_rect(in_, nk_window_get_bounds(ctx)) && 333 | nk_input_is_mouse_down(in_, NK_BUTTON_MIDDLE)) { 334 | nodedit.scrolling.x += in_.mouse.delta.x; 335 | nodedit.scrolling.y += in_.mouse.delta.y; 336 | } 337 | } 338 | nk_end(ctx); 339 | return !nk_window_is_closed(ctx, "NodeEdit"); 340 | } 341 | -------------------------------------------------------------------------------- /demo/source/overview.d: -------------------------------------------------------------------------------- 1 | module overview; 2 | 3 | import bindbc.nuklear; 4 | 5 | import core.stdc.string; 6 | import core.stdc.stdlib; 7 | import core.stdc.stdio; 8 | import core.stdc.math; 9 | 10 | int 11 | overview(nk_context *ctx) 12 | { 13 | /* window flags */ 14 | static bool show_menu = nk_true; 15 | static bool titlebar = nk_true; 16 | static bool border = nk_true; 17 | static bool resize = nk_true; 18 | static bool movable = nk_true; 19 | static bool no_scrollbar = nk_false; 20 | static bool scale_left = nk_false; 21 | static nk_flags window_flags = 0; 22 | static bool minimizable = nk_true; 23 | 24 | /* popups */ 25 | static enum nk_style_header_align header_align = NK_HEADER_RIGHT; 26 | static int show_app_about = nk_false; 27 | 28 | /* window flags */ 29 | window_flags = 0; 30 | ctx.style.window.header.align_ = header_align; 31 | if (border) window_flags |= NK_WINDOW_BORDER; 32 | if (resize) window_flags |= NK_WINDOW_SCALABLE; 33 | if (movable) window_flags |= NK_WINDOW_MOVABLE; 34 | if (no_scrollbar) window_flags |= NK_WINDOW_NO_SCROLLBAR; 35 | if (scale_left) window_flags |= NK_WINDOW_SCALE_LEFT; 36 | if (minimizable) window_flags |= NK_WINDOW_MINIMIZABLE; 37 | 38 | if (nk_begin(ctx, "Overview", nk_rect(10, 10, 400, 600), window_flags)) 39 | { 40 | if (show_menu) 41 | { 42 | /* menubar */ 43 | enum menu_states {MENU_DEFAULT, MENU_WINDOWS} 44 | static nk_size mprog = 60; 45 | static int mslider = 10; 46 | static bool mcheck = nk_true; 47 | nk_menubar_begin(ctx); 48 | 49 | /* menu #1 */ 50 | nk_layout_row_begin(ctx, NK_STATIC, 25, 5); 51 | nk_layout_row_push(ctx, 45); 52 | if (nk_menu_begin_label(ctx, "MENU", NK_TEXT_LEFT, nk_vec2(120, 200))) 53 | { 54 | static size_t prog = 40; 55 | static int slider = 10; 56 | static bool check = nk_true; 57 | nk_layout_row_dynamic(ctx, 25, 1); 58 | if (nk_menu_item_label(ctx, "Hide", NK_TEXT_LEFT)) 59 | show_menu = nk_false; 60 | if (nk_menu_item_label(ctx, "About", NK_TEXT_LEFT)) 61 | show_app_about = nk_true; 62 | nk_progress(ctx, &prog, 100, NK_MODIFIABLE); 63 | nk_slider_int(ctx, 0, &slider, 16, 1); 64 | nk_checkbox_label(ctx, "check", &check); 65 | nk_menu_end(ctx); 66 | } 67 | /* menu #2 */ 68 | nk_layout_row_push(ctx, 60); 69 | if (nk_menu_begin_label(ctx, "ADVANCED", NK_TEXT_LEFT, nk_vec2(200, 600))) 70 | { 71 | enum menu_state {MENU_NONE,MENU_FILE, MENU_EDIT,MENU_VIEW,MENU_CHART} 72 | static menu_state menu_state_ = menu_state.MENU_NONE; 73 | nk_collapse_states state; 74 | 75 | state = (menu_state_ == menu_state.MENU_FILE) ? NK_MAXIMIZED: NK_MINIMIZED; 76 | if (nk_tree_state_push(ctx, NK_TREE_TAB, "FILE", &state)) { 77 | menu_state_ =menu_state. MENU_FILE; 78 | nk_menu_item_label(ctx, "New", NK_TEXT_LEFT); 79 | nk_menu_item_label(ctx, "Open", NK_TEXT_LEFT); 80 | nk_menu_item_label(ctx, "Save", NK_TEXT_LEFT); 81 | nk_menu_item_label(ctx, "Close", NK_TEXT_LEFT); 82 | nk_menu_item_label(ctx, "Exit", NK_TEXT_LEFT); 83 | nk_tree_pop(ctx); 84 | } else menu_state_ = (menu_state_ == menu_state.MENU_FILE) ? menu_state.MENU_NONE: menu_state_; 85 | 86 | state = (menu_state_ == menu_state.MENU_EDIT) ? NK_MAXIMIZED: NK_MINIMIZED; 87 | if (nk_tree_state_push(ctx, NK_TREE_TAB, "EDIT", &state)) { 88 | menu_state_ = menu_state.MENU_EDIT; 89 | nk_menu_item_label(ctx, "Copy", NK_TEXT_LEFT); 90 | nk_menu_item_label(ctx, "Delete", NK_TEXT_LEFT); 91 | nk_menu_item_label(ctx, "Cut", NK_TEXT_LEFT); 92 | nk_menu_item_label(ctx, "Paste", NK_TEXT_LEFT); 93 | nk_tree_pop(ctx); 94 | } else menu_state_ = (menu_state_ == menu_state.MENU_EDIT) ? menu_state.MENU_NONE: menu_state_; 95 | 96 | state = (menu_state_ == menu_state.MENU_VIEW) ? NK_MAXIMIZED: NK_MINIMIZED; 97 | if (nk_tree_state_push(ctx, NK_TREE_TAB, "VIEW", &state)) { 98 | menu_state_ = menu_state.MENU_VIEW; 99 | nk_menu_item_label(ctx, "About", NK_TEXT_LEFT); 100 | nk_menu_item_label(ctx, "Options", NK_TEXT_LEFT); 101 | nk_menu_item_label(ctx, "Customize", NK_TEXT_LEFT); 102 | nk_tree_pop(ctx); 103 | } else menu_state_ = (menu_state_ == menu_state.MENU_VIEW) ? menu_state.MENU_NONE: menu_state_; 104 | 105 | state = (menu_state_ == menu_state.MENU_CHART) ? NK_MAXIMIZED: NK_MINIMIZED; 106 | if (nk_tree_state_push(ctx, NK_TREE_TAB, "CHART", &state)) { 107 | size_t i = 0; 108 | const(float)[12] values=[26.0f,13.0f,30.0f,15.0f,25.0f,10.0f,20.0f,40.0f,12.0f,8.0f,22.0f,28.0f]; 109 | menu_state_ = menu_state.MENU_CHART; 110 | nk_layout_row_dynamic(ctx, 150, 1); 111 | nk_chart_begin(ctx, NK_CHART_COLUMN, cast(int)values.length, 0, 50); 112 | for (i = 0; i < values.length; ++i) 113 | nk_chart_push(ctx, values[i]); 114 | nk_chart_end(ctx); 115 | nk_tree_pop(ctx); 116 | } else menu_state_ = (menu_state_ == menu_state.MENU_CHART) ? menu_state.MENU_NONE: menu_state_; 117 | nk_menu_end(ctx); 118 | } 119 | /* menu widgets */ 120 | nk_layout_row_push(ctx, 70); 121 | nk_progress(ctx, &mprog, 100, NK_MODIFIABLE); 122 | nk_slider_int(ctx, 0, &mslider, 16, 1); 123 | nk_checkbox_label(ctx, "check", &mcheck); 124 | nk_menubar_end(ctx); 125 | } 126 | 127 | if (show_app_about) 128 | { 129 | /* about popup */ 130 | static nk_rect s = {20, 100, 300, 190}; 131 | if (nk_popup_begin(ctx, NK_POPUP_STATIC, "About", NK_WINDOW_CLOSABLE, s)) 132 | { 133 | nk_layout_row_dynamic(ctx, 20, 1); 134 | nk_label(ctx, "Nuklear", NK_TEXT_LEFT); 135 | nk_label(ctx, "By Micha Mettke", NK_TEXT_LEFT); 136 | nk_label(ctx, "nuklear is licensed under the public domain License.", NK_TEXT_LEFT); 137 | nk_popup_end(ctx); 138 | } else show_app_about = nk_false; 139 | } 140 | 141 | // window flags 142 | if (nk_tree_push(ctx, NK_TREE_TAB, "Window", NK_MINIMIZED)) { 143 | nk_layout_row_dynamic(ctx, 30, 2); 144 | nk_checkbox_label(ctx, "Titlebar", &titlebar); 145 | nk_checkbox_label(ctx, "Menu", &show_menu); 146 | nk_checkbox_label(ctx, "Border", &border); 147 | nk_checkbox_label(ctx, "Resizable", &resize); 148 | nk_checkbox_label(ctx, "Movable", &movable); 149 | nk_checkbox_label(ctx, "No Scrollbar", &no_scrollbar); 150 | nk_checkbox_label(ctx, "Minimizable", &minimizable); 151 | nk_checkbox_label(ctx, "Scale Left", &scale_left); 152 | nk_tree_pop(ctx); 153 | } 154 | 155 | if (nk_tree_push(ctx, NK_TREE_TAB, "Widgets", NK_MINIMIZED)) 156 | { 157 | enum options {A,B,C} 158 | static bool checkbox; 159 | static int option; 160 | if (nk_tree_push(ctx, NK_TREE_NODE, "Text", NK_MINIMIZED)) 161 | { 162 | // Text Widgets 163 | nk_layout_row_dynamic(ctx, 20, 1); 164 | nk_label(ctx, "Label aligned left", NK_TEXT_LEFT); 165 | nk_label(ctx, "Label aligned centered", NK_TEXT_CENTERED); 166 | nk_label(ctx, "Label aligned right", NK_TEXT_RIGHT); 167 | nk_label_colored(ctx, "Blue text", NK_TEXT_LEFT, nk_rgb(0,0,255)); 168 | nk_label_colored(ctx, "Yellow text", NK_TEXT_LEFT, nk_rgb(255,255,0)); 169 | nk_text(ctx, "Text without /0", 15, NK_TEXT_RIGHT); 170 | 171 | nk_layout_row_static(ctx, 100, 200, 1); 172 | nk_label_wrap(ctx, "This is a very long line to hopefully get this text to be wrapped into multiple lines to show line wrapping"); 173 | nk_layout_row_dynamic(ctx, 100, 1); 174 | nk_label_wrap(ctx, "This is another long text to show dynamic window changes on multiline text"); 175 | nk_tree_pop(ctx); 176 | } 177 | 178 | if (nk_tree_push(ctx, NK_TREE_NODE, "Button", NK_MINIMIZED)) 179 | { 180 | // Buttons Widgets 181 | nk_layout_row_static(ctx, 30, 100, 3); 182 | if (nk_button_label(ctx, "Button")) 183 | fprintf(stdout, "Button pressed!\n"); 184 | nk_button_set_behavior(ctx, NK_BUTTON_REPEATER); 185 | if (nk_button_label(ctx, "Repeater")) 186 | fprintf(stdout, "Repeater is being pressed!\n"); 187 | nk_button_set_behavior(ctx, NK_BUTTON_DEFAULT); 188 | nk_button_color(ctx, nk_rgb(0,0,255)); 189 | 190 | nk_layout_row_static(ctx, 25, 25, 8); 191 | nk_button_symbol(ctx, NK_SYMBOL_CIRCLE_SOLID); 192 | nk_button_symbol(ctx, NK_SYMBOL_CIRCLE_OUTLINE); 193 | nk_button_symbol(ctx, NK_SYMBOL_RECT_SOLID); 194 | nk_button_symbol(ctx, NK_SYMBOL_RECT_OUTLINE); 195 | nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_UP); 196 | nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_DOWN); 197 | nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_LEFT); 198 | nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_RIGHT); 199 | 200 | nk_layout_row_static(ctx, 30, 100, 2); 201 | nk_button_symbol_label(ctx, NK_SYMBOL_TRIANGLE_LEFT, "prev", NK_TEXT_RIGHT); 202 | nk_button_symbol_label(ctx, NK_SYMBOL_TRIANGLE_RIGHT, "next", NK_TEXT_LEFT); 203 | nk_tree_pop(ctx); 204 | } 205 | 206 | if (nk_tree_push(ctx, NK_TREE_NODE, "Basic", NK_MINIMIZED)) 207 | { 208 | // Basic widgets 209 | static int int_slider = 5; 210 | static float float_slider = 2.5f; 211 | static size_t prog_value = 40; 212 | static float property_float = 2; 213 | static int property_int = 10; 214 | static int property_neg = 10; 215 | 216 | static float range_float_min = 0; 217 | static float range_float_max = 100; 218 | static float range_float_value = 50; 219 | static int range_int_min = 0; 220 | static int range_int_value = 2048; 221 | static int range_int_max = 4096; 222 | static const(float)[2] ratio = [120, 150]; 223 | 224 | nk_layout_row_static(ctx, 30, 100, 1); 225 | nk_checkbox_label(ctx, "Checkbox", &checkbox); 226 | 227 | nk_layout_row_static(ctx, 30, 80, 3); 228 | option = nk_option_label(ctx, "optionA", option == options.A) ? options.A : option; 229 | option = nk_option_label(ctx, "optionB", option == options.B) ? options.B : option; 230 | option = nk_option_label(ctx, "optionC", option == options.C) ? options.C : option; 231 | 232 | nk_layout_row(ctx, NK_STATIC, 30, 2, ratio.ptr); 233 | nk_labelf(ctx, NK_TEXT_LEFT, "Slider int"); 234 | nk_slider_int(ctx, 0, &int_slider, 10, 1); 235 | 236 | nk_label(ctx, "Slider float", NK_TEXT_LEFT); 237 | nk_slider_float(ctx, 0, &float_slider, 5.0, 0.5f); 238 | nk_labelf(ctx, NK_TEXT_LEFT, "Progressbar: %zu" , prog_value); 239 | nk_progress(ctx, &prog_value, 100, NK_MODIFIABLE); 240 | 241 | nk_layout_row(ctx, NK_STATIC, 25, 2, ratio.ptr); 242 | nk_label(ctx, "Property float:", NK_TEXT_LEFT); 243 | nk_property_float(ctx, "Float:", 0, &property_float, 64.0f, 0.1f, 0.2f); 244 | nk_label(ctx, "Property int:", NK_TEXT_LEFT); 245 | nk_property_int(ctx, "Int:", 0, &property_int, 100, 1, 1); 246 | nk_label(ctx, "Property neg:", NK_TEXT_LEFT); 247 | nk_property_int(ctx, "Neg:", -10, &property_neg, 10, 1, 1); 248 | 249 | nk_layout_row_dynamic(ctx, 25, 1); 250 | nk_label(ctx, "Range:", NK_TEXT_LEFT); 251 | nk_layout_row_dynamic(ctx, 25, 3); 252 | nk_property_float(ctx, "#min:", 0, &range_float_min, range_float_max, 1.0f, 0.2f); 253 | nk_property_float(ctx, "#float:", range_float_min, &range_float_value, range_float_max, 1.0f, 0.2f); 254 | nk_property_float(ctx, "#max:", range_float_min, &range_float_max, 100, 1.0f, 0.2f); 255 | 256 | nk_property_int(ctx, "#min:", int.min, &range_int_min, range_int_max, 1, 10); 257 | nk_property_int(ctx, "#neg:", range_int_min, &range_int_value, range_int_max, 1, 10); 258 | nk_property_int(ctx, "#max:", range_int_min, &range_int_max, int.max, 1, 10); 259 | 260 | nk_tree_pop(ctx); 261 | } 262 | 263 | if (nk_tree_push(ctx, NK_TREE_NODE, "Inactive", NK_MINIMIZED)) 264 | { 265 | static bool inactive = 1; 266 | nk_layout_row_dynamic(ctx, 30, 1); 267 | nk_checkbox_label(ctx, "Inactive", &inactive); 268 | 269 | nk_layout_row_static(ctx, 30, 80, 1); 270 | if (inactive) { 271 | nk_style_button button; 272 | button = ctx.style.button; 273 | ctx.style.button.normal = nk_style_item_color(nk_rgb(40,40,40)); 274 | ctx.style.button.hover = nk_style_item_color(nk_rgb(40,40,40)); 275 | ctx.style.button.active = nk_style_item_color(nk_rgb(40,40,40)); 276 | ctx.style.button.border_color = nk_rgb(60,60,60); 277 | ctx.style.button.text_background = nk_rgb(60,60,60); 278 | ctx.style.button.text_normal = nk_rgb(60,60,60); 279 | ctx.style.button.text_hover = nk_rgb(60,60,60); 280 | ctx.style.button.text_active = nk_rgb(60,60,60); 281 | nk_button_label(ctx, "button"); 282 | ctx.style.button = button; 283 | } else if (nk_button_label(ctx, "button")) 284 | fprintf(stdout, "button pressed\n"); 285 | nk_tree_pop(ctx); 286 | } 287 | 288 | 289 | if (nk_tree_push(ctx, NK_TREE_NODE, "Selectable", NK_MINIMIZED)) 290 | { 291 | if (nk_tree_push(ctx, NK_TREE_NODE, "List", NK_MINIMIZED)) 292 | { 293 | static bool[4] selected = [nk_false, nk_false, nk_true, nk_false]; 294 | nk_layout_row_static(ctx, 18, 100, 1); 295 | nk_selectable_label(ctx, "Selectable", NK_TEXT_LEFT, &selected[0]); 296 | nk_selectable_label(ctx, "Selectable", NK_TEXT_LEFT, &selected[1]); 297 | nk_label(ctx, "Not Selectable", NK_TEXT_LEFT); 298 | nk_selectable_label(ctx, "Selectable", NK_TEXT_LEFT, &selected[2]); 299 | nk_selectable_label(ctx, "Selectable", NK_TEXT_LEFT, &selected[3]); 300 | nk_tree_pop(ctx); 301 | } 302 | if (nk_tree_push(ctx, NK_TREE_NODE, "Grid", NK_MINIMIZED)) 303 | { 304 | int i; 305 | static bool[16] selected2 = [1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1]; 306 | nk_layout_row_static(ctx, 50, 50, 4); 307 | for (i = 0; i < 16; ++i) { 308 | if (nk_selectable_label(ctx, "Z", NK_TEXT_CENTERED, &selected2[i])) { 309 | int x = (i % 4), y = i / 4; 310 | if (x > 0) selected2[i - 1] ^= 1; 311 | if (x < 3) selected2[i + 1] ^= 1; 312 | if (y > 0) selected2[i - 4] ^= 1; 313 | if (y < 3) selected2[i + 4] ^= 1; 314 | } 315 | } 316 | nk_tree_pop(ctx); 317 | } 318 | nk_tree_pop(ctx); 319 | } 320 | 321 | if (nk_tree_push(ctx, NK_TREE_NODE, "Combo", NK_MINIMIZED)) 322 | { 323 | /* Combobox Widgets 324 | * In this library comboboxes are not limited to being a popup 325 | * list of selectable text. Instead it is a abstract concept of 326 | * having something that is *selected* or displayed, a popup window 327 | * which opens if something needs to be modified and the content 328 | * of the popup which causes the *selected* or displayed value to 329 | * change or if wanted close the combobox. 330 | * 331 | * While strange at first handling comboboxes in a abstract way 332 | * solves the problem of overloaded window content. For example 333 | * changing a color value requires 4 value modifier (slider, property,...) 334 | * for RGBA then you need a label and ways to display the current color. 335 | * If you want to go fancy you even add rgb and hsv ratio boxes. 336 | * While fine for one color if you have a lot of them it because 337 | * tedious to look at and quite wasteful in space. You could add 338 | * a popup which modifies the color but this does not solve the 339 | * fact that it still requires a lot of cluttered space to do. 340 | * 341 | * In these kind of instance abstract comboboxes are quite handy. All 342 | * value modifiers are hidden inside the combobox popup and only 343 | * the color is shown if not open. This combines the clarity of the 344 | * popup with the ease of use of just using the space for modifiers. 345 | * 346 | * Other instances are for example time and especially date picker, 347 | * which only show the currently activated time/data and hide the 348 | * selection logic inside the combobox popup.*/ 349 | 350 | static float chart_selection = 8.0f; 351 | static int current_weapon = 0; 352 | static bool[5] check_values; 353 | static float[3] position; 354 | static nk_color combo_color = {130, 50, 50, 255}; 355 | static nk_colorf combo_color2 = {0.509f, 0.705f, 0.2f, 1.0f}; 356 | static size_t prog_a = 20, prog_b = 40, prog_c = 10, prog_d = 90; 357 | static const(char)*[5] weapons = ["Fist","Pistol","Shotgun","Plasma","BFG"]; 358 | 359 | char[64] buffer; 360 | size_t sum = 0; 361 | 362 | // default combobox 363 | nk_layout_row_static(ctx, 25, 200, 1); 364 | current_weapon = nk_combo(ctx, weapons.ptr, cast(int)weapons.length, current_weapon, 25, nk_vec2(200,200)); 365 | 366 | // slider color combobox 367 | if (nk_combo_begin_color(ctx, combo_color, nk_vec2(200,200))) { 368 | float[2] ratios = [0.15f, 0.85f]; 369 | nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratios.ptr); 370 | nk_label(ctx, "R:", NK_TEXT_LEFT); 371 | combo_color.r = cast(nk_byte)nk_slide_int(ctx, 0, combo_color.r, 255, 5); 372 | nk_label(ctx, "G:", NK_TEXT_LEFT); 373 | combo_color.g = cast(nk_byte)nk_slide_int(ctx, 0, combo_color.g, 255, 5); 374 | nk_label(ctx, "B:", NK_TEXT_LEFT); 375 | combo_color.b = cast(nk_byte)nk_slide_int(ctx, 0, combo_color.b, 255, 5); 376 | nk_label(ctx, "A:", NK_TEXT_LEFT); 377 | combo_color.a = cast(nk_byte)nk_slide_int(ctx, 0, combo_color.a , 255, 5); 378 | nk_combo_end(ctx); 379 | } 380 | // complex color combobox 381 | if (nk_combo_begin_color(ctx, nk_rgb_cf(combo_color2), nk_vec2(200,400))) { 382 | enum color_mode {COL_RGB, COL_HSV} 383 | static int col_mode = color_mode.COL_RGB; 384 | //#ifndef DEMO_DO_NOT_USE_COLOR_PICKER 385 | nk_layout_row_dynamic(ctx, 120, 1); 386 | combo_color2 = nk_color_picker(ctx, combo_color2, NK_RGBA); 387 | //#endif 388 | 389 | nk_layout_row_dynamic(ctx, 25, 2); 390 | col_mode = nk_option_label(ctx, "RGB", col_mode == color_mode.COL_RGB) ? color_mode.COL_RGB : col_mode; 391 | col_mode = nk_option_label(ctx, "HSV", col_mode == color_mode.COL_HSV) ? color_mode.COL_HSV : col_mode; 392 | 393 | nk_layout_row_dynamic(ctx, 25, 1); 394 | if (col_mode == color_mode.COL_RGB) { 395 | combo_color2.r = nk_propertyf(ctx, "#R:", 0, combo_color2.r, 1.0f, 0.01f,0.005f); 396 | combo_color2.g = nk_propertyf(ctx, "#G:", 0, combo_color2.g, 1.0f, 0.01f,0.005f); 397 | combo_color2.b = nk_propertyf(ctx, "#B:", 0, combo_color2.b, 1.0f, 0.01f,0.005f); 398 | combo_color2.a = nk_propertyf(ctx, "#A:", 0, combo_color2.a, 1.0f, 0.01f,0.005f); 399 | } else { 400 | float[4] hsva; 401 | nk_colorf_hsva_fv(hsva.ptr, combo_color2); 402 | hsva[0] = nk_propertyf(ctx, "#H:", 0, hsva[0], 1.0f, 0.01f,0.05f); 403 | hsva[1] = nk_propertyf(ctx, "#S:", 0, hsva[1], 1.0f, 0.01f,0.05f); 404 | hsva[2] = nk_propertyf(ctx, "#V:", 0, hsva[2], 1.0f, 0.01f,0.05f); 405 | hsva[3] = nk_propertyf(ctx, "#A:", 0, hsva[3], 1.0f, 0.01f,0.05f); 406 | combo_color2 = nk_hsva_colorfv(hsva.ptr); 407 | } 408 | nk_combo_end(ctx); 409 | } 410 | // progressbar combobox 411 | sum = prog_a + prog_b + prog_c + prog_d; 412 | sprintf(buffer.ptr, "%lu", sum); 413 | if (nk_combo_begin_label(ctx, buffer.ptr, nk_vec2(200,200))) { 414 | nk_layout_row_dynamic(ctx, 30, 1); 415 | nk_progress(ctx, &prog_a, 100, NK_MODIFIABLE); 416 | nk_progress(ctx, &prog_b, 100, NK_MODIFIABLE); 417 | nk_progress(ctx, &prog_c, 100, NK_MODIFIABLE); 418 | nk_progress(ctx, &prog_d, 100, NK_MODIFIABLE); 419 | nk_combo_end(ctx); 420 | } 421 | 422 | // checkbox combobox 423 | sum = cast(size_t)(check_values[0] + check_values[1] + check_values[2] + check_values[3] + check_values[4]); 424 | sprintf(buffer.ptr, "%lu", sum); 425 | if (nk_combo_begin_label(ctx, buffer.ptr, nk_vec2(200,200))) { 426 | nk_layout_row_dynamic(ctx, 30, 1); 427 | nk_checkbox_label(ctx, weapons[0], &check_values[0]); 428 | nk_checkbox_label(ctx, weapons[1], &check_values[1]); 429 | nk_checkbox_label(ctx, weapons[2], &check_values[2]); 430 | nk_checkbox_label(ctx, weapons[3], &check_values[3]); 431 | nk_combo_end(ctx); 432 | } 433 | 434 | // complex text combobox 435 | sprintf(buffer.ptr, "%.2f, %.2f, %.2f", position[0], position[1],position[2]); 436 | if (nk_combo_begin_label(ctx, buffer.ptr, nk_vec2(200,200))) { 437 | nk_layout_row_dynamic(ctx, 25, 1); 438 | nk_property_float(ctx, "#X:", -1024.0f, &position[0], 1024.0f, 1,0.5f); 439 | nk_property_float(ctx, "#Y:", -1024.0f, &position[1], 1024.0f, 1,0.5f); 440 | nk_property_float(ctx, "#Z:", -1024.0f, &position[2], 1024.0f, 1,0.5f); 441 | nk_combo_end(ctx); 442 | } 443 | 444 | // chart combobox 445 | sprintf(buffer.ptr, "%.1f", chart_selection); 446 | if (nk_combo_begin_label(ctx, buffer.ptr, nk_vec2(200,250))) { 447 | size_t i = 0; 448 | static const(float)[13] values=[26.0f,13.0f,30.0f,15.0f,25.0f,10.0f,20.0f,40.0f, 12.0f, 8.0f, 22.0f, 28.0f, 5.0f]; 449 | nk_layout_row_dynamic(ctx, 150, 1); 450 | nk_chart_begin(ctx, NK_CHART_COLUMN, cast(int)values.length, 0, 50); 451 | for (i = 0; i < values.length; ++i) { 452 | nk_flags res = nk_chart_push(ctx, values[i]); 453 | if (res & NK_CHART_CLICKED) { 454 | chart_selection = values[i]; 455 | nk_combo_close(ctx); 456 | } 457 | } 458 | nk_chart_end(ctx); 459 | nk_combo_end(ctx); 460 | } 461 | nk_tree_pop(ctx); 462 | } 463 | 464 | if (nk_tree_push(ctx, NK_TREE_NODE, "Input", NK_MINIMIZED)) 465 | { 466 | static const(float)[2] ratio2 = [120, 150]; 467 | static char[64] field_buffer; 468 | static char[9][64] text; 469 | static int[9] text_len; 470 | static char[512] box_buffer; 471 | static int field_len; 472 | static int box_len; 473 | nk_flags active; 474 | 475 | nk_layout_row(ctx, NK_STATIC, 25, 2, ratio2.ptr); 476 | nk_label(ctx, "Default:", NK_TEXT_LEFT); 477 | 478 | nk_edit_string(ctx, NK_EDIT_SIMPLE, text[0].ptr, &text_len[0], 64, nk_filter_default_fptr); 479 | nk_label(ctx, "Int:", NK_TEXT_LEFT); 480 | nk_edit_string(ctx, NK_EDIT_SIMPLE, text[1].ptr, &text_len[1], 64, nk_filter_decimal_fptr); 481 | nk_label(ctx, "Float:", NK_TEXT_LEFT); 482 | nk_edit_string(ctx, NK_EDIT_SIMPLE, text[2].ptr, &text_len[2], 64, nk_filter_float_fptr); 483 | nk_label(ctx, "Hex:", NK_TEXT_LEFT); 484 | nk_edit_string(ctx, NK_EDIT_SIMPLE, text[4].ptr, &text_len[4], 64, nk_filter_hex_fptr); 485 | nk_label(ctx, "Octal:", NK_TEXT_LEFT); 486 | nk_edit_string(ctx, NK_EDIT_SIMPLE, text[5].ptr, &text_len[5], 64, nk_filter_oct_fptr); 487 | nk_label(ctx, "Binary:", NK_TEXT_LEFT); 488 | nk_edit_string(ctx, NK_EDIT_SIMPLE, text[6].ptr, &text_len[6], 64, nk_filter_binary_fptr); 489 | 490 | nk_label(ctx, "Password:", NK_TEXT_LEFT); 491 | { 492 | int i = 0; 493 | int old_len = text_len[8]; 494 | char[64] buffer; 495 | for (i = 0; i < text_len[8]; ++i) buffer[i] = '*'; 496 | nk_edit_string(ctx, NK_EDIT_FIELD, buffer.ptr, &text_len[8], 64, nk_filter_default_fptr); 497 | if (old_len < text_len[8]) 498 | memcpy(&text[8][old_len], &buffer[old_len], cast(nk_size)(text_len[8] - old_len)); 499 | } 500 | 501 | nk_label(ctx, "Field:", NK_TEXT_LEFT); 502 | nk_edit_string(ctx, NK_EDIT_FIELD, field_buffer.ptr, &field_len, 64, nk_filter_default_fptr); 503 | 504 | nk_label(ctx, "Box:", NK_TEXT_LEFT); 505 | nk_layout_row_static(ctx, 180, 278, 1); 506 | nk_edit_string(ctx, NK_EDIT_BOX, box_buffer.ptr, &box_len, 512, nk_filter_default_fptr); 507 | 508 | nk_layout_row(ctx, NK_STATIC, 25, 2, ratio2.ptr); 509 | active = nk_edit_string(ctx, NK_EDIT_FIELD|NK_EDIT_SIG_ENTER, text[7].ptr, &text_len[7], 64, nk_filter_ascii_fptr); 510 | if (nk_button_label(ctx, "Submit") || 511 | (active & NK_EDIT_COMMITED)) 512 | { 513 | text[7][text_len[7]] = '\n'; 514 | text_len[7]++; 515 | memcpy(&box_buffer[box_len], &text[7], cast(nk_size)text_len[7]); 516 | box_len += text_len[7]; 517 | text_len[7] = 0; 518 | } 519 | nk_tree_pop(ctx); 520 | } 521 | 522 | nk_tree_pop(ctx); 523 | } 524 | 525 | 526 | 527 | if (nk_tree_push(ctx, NK_TREE_TAB, "Chart", NK_MINIMIZED)) 528 | { 529 | /* Chart Widgets 530 | * This library has two different rather simple charts. The line and the 531 | * column chart. Both provide a simple way of visualizing values and 532 | * have a retained mode and immediate mode API version. For the retain 533 | * mode version `nk_plot` and `nk_plot_function` you either provide 534 | * an array or a callback to call to handle drawing the graph. 535 | * For the immediate mode version you start by calling `nk_chart_begin` 536 | * and need to provide min and max values for scaling on the Y-axis. 537 | * and then call `nk_chart_push` to push values into the chart. 538 | * Finally `nk_chart_end` needs to be called to end the process.*/ 539 | float id = 0; 540 | static int col_index = -1; 541 | static int line_index = -1; 542 | float step = (2*3.141592654f) / 32; 543 | 544 | int i; 545 | int index = -1; 546 | nk_rect bounds; 547 | 548 | // line chart 549 | id = 0; 550 | index = -1; 551 | nk_layout_row_dynamic(ctx, 100, 1); 552 | bounds = nk_widget_bounds(ctx); 553 | if (nk_chart_begin(ctx, NK_CHART_LINES, 32, -1.0f, 1.0f)) { 554 | for (i = 0; i < 32; ++i) { 555 | nk_flags res = nk_chart_push(ctx, cast(float)cos(id)); 556 | if (res & NK_CHART_HOVERING) 557 | index = cast(int)i; 558 | if (res & NK_CHART_CLICKED) 559 | line_index = cast(int)i; 560 | id += step; 561 | } 562 | nk_chart_end(ctx); 563 | } 564 | 565 | if (index != -1) 566 | nk_tooltipf(ctx, "Value: %.2f", cast(float)cos(cast(float)index*step)); 567 | if (line_index != -1) { 568 | nk_layout_row_dynamic(ctx, 20, 1); 569 | nk_labelf(ctx, NK_TEXT_LEFT, "Selected value: %.2f",cast(float)cos(cast(float)index*step)); 570 | } 571 | 572 | // column chart 573 | nk_layout_row_dynamic(ctx, 100, 1); 574 | bounds = nk_widget_bounds(ctx); 575 | if (nk_chart_begin(ctx, NK_CHART_COLUMN, 32, 0.0f, 1.0f)) { 576 | for (i = 0; i < 32; ++i) { 577 | nk_flags res = nk_chart_push(ctx, cast(float)fabs(sin(id))); 578 | if (res & NK_CHART_HOVERING) 579 | index = cast(int)i; 580 | if (res & NK_CHART_CLICKED) 581 | col_index = cast(int)i; 582 | id += step; 583 | } 584 | nk_chart_end(ctx); 585 | } 586 | if (index != -1) 587 | nk_tooltipf(ctx, "Value: %.2f", cast(float)fabs(sin(step * cast(float)index))); 588 | if (col_index != -1) { 589 | nk_layout_row_dynamic(ctx, 20, 1); 590 | nk_labelf(ctx, NK_TEXT_LEFT, "Selected value: %.2f", cast(float)fabs(sin(step * cast(float)col_index))); 591 | } 592 | 593 | // mixed chart 594 | nk_layout_row_dynamic(ctx, 100, 1); 595 | bounds = nk_widget_bounds(ctx); 596 | if (nk_chart_begin(ctx, NK_CHART_COLUMN, 32, 0.0f, 1.0f)) { 597 | nk_chart_add_slot(ctx, NK_CHART_LINES, 32, -1.0f, 1.0f); 598 | nk_chart_add_slot(ctx, NK_CHART_LINES, 32, -1.0f, 1.0f); 599 | for (id = 0, i = 0; i < 32; ++i) { 600 | nk_chart_push_slot(ctx,cast (float)fabs(sin(id)), 0); 601 | nk_chart_push_slot(ctx, cast(float)cos(id), 1); 602 | nk_chart_push_slot(ctx, cast(float)sin(id), 2); 603 | id += step; 604 | } 605 | } 606 | nk_chart_end(ctx); 607 | 608 | //* mixed colored chart 609 | nk_layout_row_dynamic(ctx, 100, 1); 610 | bounds = nk_widget_bounds(ctx); 611 | if (nk_chart_begin_colored(ctx, NK_CHART_LINES, nk_rgb(255,0,0), nk_rgb(150,0,0), 32, 0.0f, 1.0f)) { 612 | nk_chart_add_slot_colored(ctx, NK_CHART_LINES, nk_rgb(0,0,255), nk_rgb(0,0,150),32, -1.0f, 1.0f); 613 | nk_chart_add_slot_colored(ctx, NK_CHART_LINES, nk_rgb(0,255,0), nk_rgb(0,150,0), 32, -1.0f, 1.0f); 614 | for (id = 0, i = 0; i < 32; ++i) { 615 | nk_chart_push_slot(ctx, cast(float)fabs(sin(id)), 0); 616 | nk_chart_push_slot(ctx, cast(float)cos(id), 1); 617 | nk_chart_push_slot(ctx, cast(float)sin(id), 2); 618 | id += step; 619 | } 620 | } 621 | nk_chart_end(ctx); 622 | nk_tree_pop(ctx); 623 | } 624 | 625 | if (nk_tree_push(ctx, NK_TREE_TAB, "Popup", NK_MINIMIZED)) 626 | { 627 | static nk_color color = {255,0,0, 255}; 628 | static bool[4] select; 629 | static int popup_active; 630 | const(nk_input) *in_ = &ctx.input; 631 | nk_rect bounds; 632 | 633 | //* menu contextual 634 | nk_layout_row_static(ctx, 30, 160, 1); 635 | bounds = nk_widget_bounds(ctx); 636 | nk_label(ctx, "Right click me for menu", NK_TEXT_LEFT); 637 | 638 | if (nk_contextual_begin(ctx, 0, nk_vec2(100, 300), bounds)) { 639 | static size_t prog2 = 40; 640 | static int slider2 = 10; 641 | 642 | nk_layout_row_dynamic(ctx, 25, 1); 643 | nk_checkbox_label(ctx, "Menu", &show_menu); 644 | nk_progress(ctx, &prog2, 100, NK_MODIFIABLE); 645 | nk_slider_int(ctx, 0, &slider2, 16, 1); 646 | if (nk_contextual_item_label(ctx, "About", NK_TEXT_CENTERED)) 647 | show_app_about = nk_true; 648 | nk_selectable_label(ctx, select[0]?"Unselect":"Select", NK_TEXT_LEFT, &select[0]); 649 | nk_selectable_label(ctx, select[1]?"Unselect":"Select", NK_TEXT_LEFT, &select[1]); 650 | nk_selectable_label(ctx, select[2]?"Unselect":"Select", NK_TEXT_LEFT, &select[2]); 651 | nk_selectable_label(ctx, select[3]?"Unselect":"Select", NK_TEXT_LEFT, &select[3]); 652 | nk_contextual_end(ctx); 653 | } 654 | 655 | //* color contextual 656 | nk_layout_row_begin(ctx, NK_STATIC, 30, 2); 657 | nk_layout_row_push(ctx, 100); 658 | nk_label(ctx, "Right Click here:", NK_TEXT_LEFT); 659 | nk_layout_row_push(ctx, 50); 660 | bounds = nk_widget_bounds(ctx); 661 | nk_button_color(ctx, color); 662 | nk_layout_row_end(ctx); 663 | 664 | if (nk_contextual_begin(ctx, 0, nk_vec2(350, 60), bounds)) { 665 | nk_layout_row_dynamic(ctx, 30, 4); 666 | color.r = cast(nk_byte)nk_propertyi(ctx, "#r", 0, color.r, 255, 1, 1); 667 | color.g = cast(nk_byte)nk_propertyi(ctx, "#g", 0, color.g, 255, 1, 1); 668 | color.b = cast(nk_byte)nk_propertyi(ctx, "#b", 0, color.b, 255, 1, 1); 669 | color.a = cast(nk_byte)nk_propertyi(ctx, "#a", 0, color.a, 255, 1, 1); 670 | nk_contextual_end(ctx); 671 | } 672 | 673 | //* popup 674 | nk_layout_row_begin(ctx, NK_STATIC, 30, 2); 675 | nk_layout_row_push(ctx, 100); 676 | nk_label(ctx, "Popup:", NK_TEXT_LEFT); 677 | nk_layout_row_push(ctx, 50); 678 | if (nk_button_label(ctx, "Popup")) 679 | popup_active = 1; 680 | nk_layout_row_end(ctx); 681 | 682 | if (popup_active) 683 | { 684 | static nk_rect s2 = {20, 100, 220, 90}; 685 | if (nk_popup_begin(ctx, NK_POPUP_STATIC, "Error", 0, s2)) 686 | { 687 | nk_layout_row_dynamic(ctx, 25, 1); 688 | nk_label(ctx, "A terrible error as occured", NK_TEXT_LEFT); 689 | nk_layout_row_dynamic(ctx, 25, 2); 690 | if (nk_button_label(ctx, "OK")) { 691 | popup_active = 0; 692 | nk_popup_close(ctx); 693 | } 694 | if (nk_button_label(ctx, "Cancel")) { 695 | popup_active = 0; 696 | nk_popup_close(ctx); 697 | } 698 | nk_popup_end(ctx); 699 | } else popup_active = nk_false; 700 | } 701 | 702 | //* tooltip 703 | nk_layout_row_static(ctx, 30, 150, 1); 704 | bounds = nk_widget_bounds(ctx); 705 | nk_label(ctx, "Hover me for tooltip", NK_TEXT_LEFT); 706 | if (nk_input_is_mouse_hovering_rect(in_, bounds)) 707 | nk_tooltip(ctx, "This is a tooltip"); 708 | 709 | nk_tree_pop(ctx); 710 | } 711 | 712 | if (nk_tree_push(ctx, NK_TREE_TAB, "Layout", NK_MINIMIZED)) 713 | { 714 | if (nk_tree_push(ctx, NK_TREE_NODE, "Widget", NK_MINIMIZED)) 715 | { 716 | float[3] ratio_two = [0.2f, 0.6f, 0.2f]; 717 | float[3] width_two = [100, 200, 50]; 718 | 719 | nk_layout_row_dynamic(ctx, 30, 1); 720 | nk_label(ctx, "Dynamic fixed column layout with generated position and size:", NK_TEXT_LEFT); 721 | nk_layout_row_dynamic(ctx, 30, 3); 722 | nk_button_label(ctx, "button"); 723 | nk_button_label(ctx, "button"); 724 | nk_button_label(ctx, "button"); 725 | 726 | nk_layout_row_dynamic(ctx, 30, 1); 727 | nk_label(ctx, "static fixed column layout with generated position and size:", NK_TEXT_LEFT); 728 | nk_layout_row_static(ctx, 30, 100, 3); 729 | nk_button_label(ctx, "button"); 730 | nk_button_label(ctx, "button"); 731 | nk_button_label(ctx, "button"); 732 | 733 | nk_layout_row_dynamic(ctx, 30, 1); 734 | nk_label(ctx, "Dynamic array-based custom column layout with generated position and custom size:",NK_TEXT_LEFT); 735 | nk_layout_row(ctx, NK_DYNAMIC, 30, 3, ratio_two.ptr); 736 | nk_button_label(ctx, "button"); 737 | nk_button_label(ctx, "button"); 738 | nk_button_label(ctx, "button"); 739 | 740 | nk_layout_row_dynamic(ctx, 30, 1); 741 | nk_label(ctx, "Static array-based custom column layout with generated position and custom size:",NK_TEXT_LEFT ); 742 | nk_layout_row(ctx, NK_STATIC, 30, 3, width_two.ptr); 743 | nk_button_label(ctx, "button"); 744 | nk_button_label(ctx, "button"); 745 | nk_button_label(ctx, "button"); 746 | 747 | nk_layout_row_dynamic(ctx, 30, 1); 748 | nk_label(ctx, "Dynamic immediate mode custom column layout with generated position and custom size:",NK_TEXT_LEFT); 749 | nk_layout_row_begin(ctx, NK_DYNAMIC, 30, 3); 750 | nk_layout_row_push(ctx, 0.2f); 751 | nk_button_label(ctx, "button"); 752 | nk_layout_row_push(ctx, 0.6f); 753 | nk_button_label(ctx, "button"); 754 | nk_layout_row_push(ctx, 0.2f); 755 | nk_button_label(ctx, "button"); 756 | nk_layout_row_end(ctx); 757 | 758 | nk_layout_row_dynamic(ctx, 30, 1); 759 | nk_label(ctx, "Static immediate mode custom column layout with generated position and custom size:", NK_TEXT_LEFT); 760 | nk_layout_row_begin(ctx, NK_STATIC, 30, 3); 761 | nk_layout_row_push(ctx, 100); 762 | nk_button_label(ctx, "button"); 763 | nk_layout_row_push(ctx, 200); 764 | nk_button_label(ctx, "button"); 765 | nk_layout_row_push(ctx, 50); 766 | nk_button_label(ctx, "button"); 767 | nk_layout_row_end(ctx); 768 | 769 | nk_layout_row_dynamic(ctx, 30, 1); 770 | nk_label(ctx, "Static free space with custom position and custom size:", NK_TEXT_LEFT); 771 | nk_layout_space_begin(ctx, NK_STATIC, 60, 4); 772 | nk_layout_space_push(ctx, nk_rect(100, 0, 100, 30)); 773 | nk_button_label(ctx, "button"); 774 | nk_layout_space_push(ctx, nk_rect(0, 15, 100, 30)); 775 | nk_button_label(ctx, "button"); 776 | nk_layout_space_push(ctx, nk_rect(200, 15, 100, 30)); 777 | nk_button_label(ctx, "button"); 778 | nk_layout_space_push(ctx, nk_rect(100, 30, 100, 30)); 779 | nk_button_label(ctx, "button"); 780 | nk_layout_space_end(ctx); 781 | 782 | nk_layout_row_dynamic(ctx, 30, 1); 783 | nk_label(ctx, "Row template:", NK_TEXT_LEFT); 784 | nk_layout_row_template_begin(ctx, 30); 785 | nk_layout_row_template_push_dynamic(ctx); 786 | nk_layout_row_template_push_variable(ctx, 80); 787 | nk_layout_row_template_push_static(ctx, 80); 788 | nk_layout_row_template_end(ctx); 789 | nk_button_label(ctx, "button"); 790 | nk_button_label(ctx, "button"); 791 | nk_button_label(ctx, "button"); 792 | 793 | nk_tree_pop(ctx); 794 | } 795 | 796 | if (nk_tree_push(ctx, NK_TREE_NODE, "Group", NK_MINIMIZED)) 797 | { 798 | static bool group_titlebar = nk_false; 799 | static bool group_border = nk_true; 800 | static bool group_no_scrollbar = nk_false; 801 | static int group_width = 320; 802 | static int group_height = 200; 803 | 804 | nk_flags group_flags = 0; 805 | if (group_border) group_flags |= NK_WINDOW_BORDER; 806 | if (group_no_scrollbar) group_flags |= NK_WINDOW_NO_SCROLLBAR; 807 | if (group_titlebar) group_flags |= NK_WINDOW_TITLE; 808 | 809 | nk_layout_row_dynamic(ctx, 30, 3); 810 | nk_checkbox_label(ctx, "Titlebar", &group_titlebar); 811 | nk_checkbox_label(ctx, "Border", &group_border); 812 | nk_checkbox_label(ctx, "No Scrollbar", &group_no_scrollbar); 813 | 814 | nk_layout_row_begin(ctx, NK_STATIC, 22, 3); 815 | nk_layout_row_push(ctx, 50); 816 | nk_label(ctx, "size:", NK_TEXT_LEFT); 817 | nk_layout_row_push(ctx, 130); 818 | nk_property_int(ctx, "#Width:", 100, &group_width, 500, 10, 1); 819 | nk_layout_row_push(ctx, 130); 820 | nk_property_int(ctx, "#Height:", 100, &group_height, 500, 10, 1); 821 | nk_layout_row_end(ctx); 822 | 823 | nk_layout_row_static(ctx, cast(float)group_height, group_width, 2); 824 | if (nk_group_begin(ctx, "Group", group_flags)) { 825 | int i = 0; 826 | static bool[16] selected3; 827 | nk_layout_row_static(ctx, 18, 100, 1); 828 | for (i = 0; i < 16; ++i) 829 | nk_selectable_label(ctx, (selected3[i]) ? "Selected": "Unselected", NK_TEXT_CENTERED, &selected3[i]); 830 | nk_group_end(ctx); 831 | } 832 | nk_tree_pop(ctx); 833 | } 834 | if (nk_tree_push(ctx, NK_TREE_NODE, "Tree", NK_MINIMIZED)) 835 | { 836 | static int root_selected = 0; 837 | int sel = root_selected; 838 | 839 | if (nk_tree_element_push(ctx, NK_TREE_NODE, "Root", NK_MINIMIZED, &sel)) { 840 | static bool[8] selected0; 841 | int i = 0, node_select = selected0[0]; 842 | if (sel != root_selected) { 843 | root_selected = sel; 844 | for (i = 0; i < 8; ++i) 845 | selected0[i] = cast(bool)sel; 846 | } 847 | if (nk_tree_element_push(ctx, NK_TREE_NODE, "Node", NK_MINIMIZED, &node_select)) { 848 | int j = 0; 849 | static bool[4] sel_nodes; 850 | if (node_select != selected0[0]) { 851 | selected0[0] = cast(bool)node_select; 852 | for (i = 0; i < 4; ++i) 853 | sel_nodes[i] = cast(bool)node_select; 854 | } 855 | nk_layout_row_static(ctx, 18, 100, 1); 856 | for (j = 0; j < 4; ++j) 857 | nk_selectable_symbol_label(ctx, NK_SYMBOL_CIRCLE_SOLID, (sel_nodes[j]) ? "Selected": "Unselected", NK_TEXT_RIGHT, &sel_nodes[j]); 858 | nk_tree_element_pop(ctx); 859 | } 860 | nk_layout_row_static(ctx, 18, 100, 1); 861 | for (i = 1; i < 8; ++i) 862 | nk_selectable_symbol_label(ctx, NK_SYMBOL_CIRCLE_SOLID, (selected0[i]) ? "Selected": "Unselected", NK_TEXT_RIGHT, &selected0[i]); 863 | nk_tree_element_pop(ctx); 864 | } 865 | nk_tree_pop(ctx); 866 | 867 | } 868 | if (nk_tree_push(ctx, NK_TREE_NODE, "Notebook", NK_MINIMIZED)) 869 | { 870 | static int current_tab = 0; 871 | nk_rect bounds; 872 | float step = (2*3.141592654f) / 32; 873 | enum chart_type {CHART_LINE, CHART_HISTO, CHART_MIXED} 874 | const(char) *[3]names = ["Lines", "Columns", "Mixed"]; 875 | float id = 0; 876 | int i; 877 | 878 | //* Header 879 | nk_style_push_vec2(ctx, &ctx.style.window.spacing, nk_vec2(0,0)); 880 | nk_style_push_float(ctx, &ctx.style.button.rounding, 0); 881 | nk_layout_row_begin(ctx, NK_STATIC, 20, 3); 882 | for (i = 0; i < 3; ++i) { 883 | //* make sure button perfectly fits text 884 | const(nk_user_font) *f = ctx.style.font; 885 | float text_width = 80;// f.width(f.userdata, f.height, names[i], nk_strlen(names[i])); 886 | float widget_width = text_width + 3 * ctx.style.button.padding.x; 887 | nk_layout_row_push(ctx, widget_width); 888 | if (current_tab == i) { 889 | //* active tab gets highlighted 890 | nk_style_item button_color = ctx.style.button.normal; 891 | ctx.style.button.normal = ctx.style.button.active; 892 | current_tab = nk_button_label(ctx, names[i]) ? i: current_tab; 893 | ctx.style.button.normal = button_color; 894 | } else current_tab = nk_button_label(ctx, names[i]) ? i: current_tab; 895 | } 896 | nk_style_pop_float(ctx); 897 | 898 | //* Body 899 | nk_layout_row_dynamic(ctx, 140, 1); 900 | if (nk_group_begin(ctx, "Notebook", NK_WINDOW_BORDER)) 901 | { 902 | nk_style_pop_vec2(ctx); 903 | switch (current_tab) { 904 | default: break; 905 | case chart_type.CHART_LINE: 906 | nk_layout_row_dynamic(ctx, 100, 1); 907 | bounds = nk_widget_bounds(ctx); 908 | if (nk_chart_begin_colored(ctx, NK_CHART_LINES, nk_rgb(255,0,0), nk_rgb(150,0,0), 32, 0.0f, 1.0f)) { 909 | nk_chart_add_slot_colored(ctx, NK_CHART_LINES, nk_rgb(0,0,255), nk_rgb(0,0,150),32, -1.0f, 1.0f); 910 | for (i = 0, id = 0; i < 32; ++i) { 911 | nk_chart_push_slot(ctx,cast (float)fabs(sin(id)), 0); 912 | nk_chart_push_slot(ctx, cast(float)cos(id), 1); 913 | id += step; 914 | } 915 | } 916 | nk_chart_end(ctx); 917 | break; 918 | case chart_type.CHART_HISTO: 919 | nk_layout_row_dynamic(ctx, 100, 1); 920 | bounds = nk_widget_bounds(ctx); 921 | if (nk_chart_begin_colored(ctx, NK_CHART_COLUMN, nk_rgb(255,0,0), nk_rgb(150,0,0), 32, 0.0f, 1.0f)) { 922 | for (i = 0, id = 0; i < 32; ++i) { 923 | nk_chart_push_slot(ctx, cast(float)fabs(sin(id)), 0); 924 | id += step; 925 | } 926 | } 927 | nk_chart_end(ctx); 928 | break; 929 | case chart_type.CHART_MIXED: 930 | nk_layout_row_dynamic(ctx, 100, 1); 931 | bounds = nk_widget_bounds(ctx); 932 | if (nk_chart_begin_colored(ctx, NK_CHART_LINES, nk_rgb(255,0,0), nk_rgb(150,0,0), 32, 0.0f, 1.0f)) { 933 | nk_chart_add_slot_colored(ctx, NK_CHART_LINES, nk_rgb(0,0,255), nk_rgb(0,0,150),32, -1.0f, 1.0f); 934 | nk_chart_add_slot_colored(ctx, NK_CHART_COLUMN, nk_rgb(0,255,0), nk_rgb(0,150,0), 32, 0.0f, 1.0f); 935 | for (i = 0, id = 0; i < 32; ++i) { 936 | nk_chart_push_slot(ctx, cast(float)fabs(sin(id)), 0); 937 | nk_chart_push_slot(ctx, cast(float)fabs(cos(id)), 1); 938 | nk_chart_push_slot(ctx, cast(float)fabs(sin(id)), 2); 939 | id += step; 940 | } 941 | } 942 | nk_chart_end(ctx); 943 | break; 944 | } 945 | nk_group_end(ctx); 946 | } else nk_style_pop_vec2(ctx); 947 | nk_tree_pop(ctx); 948 | } 949 | 950 | if (nk_tree_push(ctx, NK_TREE_NODE, "Simple", NK_MINIMIZED)) 951 | { 952 | nk_layout_row_dynamic(ctx, 300, 2); 953 | if (nk_group_begin(ctx, "Group_Without_Border", 0)) { 954 | int i = 0; 955 | char[64] buffer; 956 | nk_layout_row_static(ctx, 18, 150, 1); 957 | for (i = 0; i < 64; ++i) { 958 | sprintf(buffer.ptr, "0x%02x", i); 959 | nk_labelf(ctx, NK_TEXT_LEFT, "%s: scrollable region", buffer.ptr); 960 | } 961 | nk_group_end(ctx); 962 | } 963 | if (nk_group_begin(ctx, "Group_With_Border", NK_WINDOW_BORDER)) { 964 | int i = 0; 965 | char[64] buffer; 966 | nk_layout_row_dynamic(ctx, 25, 2); 967 | for (i = 0; i < 64; ++i) { 968 | sprintf(buffer.ptr, "%08d", ((((i%7)*10)^32))+(64+(i%2)*2)); 969 | nk_button_label(ctx, buffer.ptr); 970 | } 971 | nk_group_end(ctx); 972 | } 973 | nk_tree_pop(ctx); 974 | } 975 | 976 | if (nk_tree_push(ctx, NK_TREE_NODE, "Complex", NK_MINIMIZED)) 977 | { 978 | int i; 979 | nk_layout_space_begin(ctx, NK_STATIC, 500, 64); 980 | nk_layout_space_push(ctx, nk_rect(0,0,150,500)); 981 | if (nk_group_begin(ctx, "Group_left", NK_WINDOW_BORDER)) { 982 | static bool[32] selected4; 983 | nk_layout_row_static(ctx, 18, 100, 1); 984 | for (i = 0; i < 32; ++i) 985 | nk_selectable_label(ctx, (selected4[i]) ? "Selected": "Unselected", NK_TEXT_CENTERED, &selected4[i]); 986 | nk_group_end(ctx); 987 | } 988 | 989 | nk_layout_space_push(ctx, nk_rect(160,0,150,240)); 990 | if (nk_group_begin(ctx, "Group_top", NK_WINDOW_BORDER)) { 991 | nk_layout_row_dynamic(ctx, 25, 1); 992 | nk_button_label(ctx, "#FFAA"); 993 | nk_button_label(ctx, "#FFBB"); 994 | nk_button_label(ctx, "#FFCC"); 995 | nk_button_label(ctx, "#FFDD"); 996 | nk_button_label(ctx, "#FFEE"); 997 | nk_button_label(ctx, "#FFFF"); 998 | nk_group_end(ctx); 999 | } 1000 | 1001 | nk_layout_space_push(ctx, nk_rect(160,250,150,250)); 1002 | if (nk_group_begin(ctx, "Group_buttom", NK_WINDOW_BORDER)) { 1003 | nk_layout_row_dynamic(ctx, 25, 1); 1004 | nk_button_label(ctx, "#FFAA"); 1005 | nk_button_label(ctx, "#FFBB"); 1006 | nk_button_label(ctx, "#FFCC"); 1007 | nk_button_label(ctx, "#FFDD"); 1008 | nk_button_label(ctx, "#FFEE"); 1009 | nk_button_label(ctx, "#FFFF"); 1010 | nk_group_end(ctx); 1011 | } 1012 | 1013 | nk_layout_space_push(ctx, nk_rect(320,0,150,150)); 1014 | if (nk_group_begin(ctx, "Group_right_top", NK_WINDOW_BORDER)) { 1015 | static bool[4] selected5; 1016 | nk_layout_row_static(ctx, 18, 100, 1); 1017 | for (i = 0; i < 4; ++i) 1018 | nk_selectable_label(ctx, (selected5[i]) ? "Selected": "Unselected", NK_TEXT_CENTERED, &selected5[i]); 1019 | nk_group_end(ctx); 1020 | } 1021 | 1022 | nk_layout_space_push(ctx, nk_rect(320,160,150,150)); 1023 | if (nk_group_begin(ctx, "Group_right_center", NK_WINDOW_BORDER)) { 1024 | static bool[4] selected6; 1025 | nk_layout_row_static(ctx, 18, 100, 1); 1026 | for (i = 0; i < 4; ++i) 1027 | nk_selectable_label(ctx, (selected6[i]) ? "Selected": "Unselected", NK_TEXT_CENTERED, &selected6[i]); 1028 | nk_group_end(ctx); 1029 | } 1030 | 1031 | nk_layout_space_push(ctx, nk_rect(320,320,150,150)); 1032 | if (nk_group_begin(ctx, "Group_right_bottom", NK_WINDOW_BORDER)) { 1033 | static bool[4] selected7; 1034 | nk_layout_row_static(ctx, 18, 100, 1); 1035 | for (i = 0; i < 4; ++i) 1036 | nk_selectable_label(ctx, (selected7[i]) ? "Selected": "Unselected", NK_TEXT_CENTERED, &selected7[i]); 1037 | nk_group_end(ctx); 1038 | } 1039 | nk_layout_space_end(ctx); 1040 | nk_tree_pop(ctx); 1041 | } 1042 | 1043 | if (nk_tree_push(ctx, NK_TREE_NODE, "Splitter", NK_MINIMIZED)) 1044 | { 1045 | const(nk_input) *in_ = &ctx.input; 1046 | nk_layout_row_static(ctx, 20, 320, 1); 1047 | nk_label(ctx, "Use slider and spinner to change tile size", NK_TEXT_LEFT); 1048 | nk_label(ctx, "Drag the space between tiles to change tile ratio", NK_TEXT_LEFT); 1049 | 1050 | if (nk_tree_push(ctx, NK_TREE_NODE, "Vertical", NK_MINIMIZED)) 1051 | { 1052 | static float a = 100, b = 100, c = 100; 1053 | nk_rect bounds; 1054 | 1055 | float[5] row_layout; 1056 | row_layout[0] = a; 1057 | row_layout[1] = 8; 1058 | row_layout[2] = b; 1059 | row_layout[3] = 8; 1060 | row_layout[4] = c; 1061 | 1062 | //* header 1063 | nk_layout_row_static(ctx, 30, 100, 2); 1064 | nk_label(ctx, "left:", NK_TEXT_LEFT); 1065 | nk_slider_float(ctx, 10.0f, &a, 200.0f, 10.0f); 1066 | 1067 | nk_label(ctx, "middle:", NK_TEXT_LEFT); 1068 | nk_slider_float(ctx, 10.0f, &b, 200.0f, 10.0f); 1069 | 1070 | nk_label(ctx, "right:", NK_TEXT_LEFT); 1071 | nk_slider_float(ctx, 10.0f, &c, 200.0f, 10.0f); 1072 | 1073 | //* tiles 1074 | nk_layout_row(ctx, NK_STATIC, 200, 5, row_layout.ptr); 1075 | 1076 | //* left space 1077 | if (nk_group_begin(ctx, "left", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) { 1078 | nk_layout_row_dynamic(ctx, 25, 1); 1079 | nk_button_label(ctx, "#FFAA"); 1080 | nk_button_label(ctx, "#FFBB"); 1081 | nk_button_label(ctx, "#FFCC"); 1082 | nk_button_label(ctx, "#FFDD"); 1083 | nk_button_label(ctx, "#FFEE"); 1084 | nk_button_label(ctx, "#FFFF"); 1085 | nk_group_end(ctx); 1086 | } 1087 | 1088 | //* scaler 1089 | bounds = nk_widget_bounds(ctx); 1090 | nk_spacing(ctx, 1); 1091 | if ((nk_input_is_mouse_hovering_rect(in_, bounds) || 1092 | nk_input_is_mouse_prev_hovering_rect(in_, bounds)) && 1093 | nk_input_is_mouse_down(in_, NK_BUTTON_LEFT)) 1094 | { 1095 | a = row_layout[0] + in_.mouse.delta.x; 1096 | b = row_layout[2] - in_.mouse.delta.x; 1097 | } 1098 | 1099 | //* middle space 1100 | if (nk_group_begin(ctx, "center", NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) { 1101 | nk_layout_row_dynamic(ctx, 25, 1); 1102 | nk_button_label(ctx, "#FFAA"); 1103 | nk_button_label(ctx, "#FFBB"); 1104 | nk_button_label(ctx, "#FFCC"); 1105 | nk_button_label(ctx, "#FFDD"); 1106 | nk_button_label(ctx, "#FFEE"); 1107 | nk_button_label(ctx, "#FFFF"); 1108 | nk_group_end(ctx); 1109 | } 1110 | 1111 | //* scaler 1112 | bounds = nk_widget_bounds(ctx); 1113 | nk_spacing(ctx, 1); 1114 | if ((nk_input_is_mouse_hovering_rect(in_, bounds) || 1115 | nk_input_is_mouse_prev_hovering_rect(in_, bounds)) && 1116 | nk_input_is_mouse_down(in_, NK_BUTTON_LEFT)) 1117 | { 1118 | b = (row_layout[2] + in_.mouse.delta.x); 1119 | c = (row_layout[4] - in_.mouse.delta.x); 1120 | } 1121 | 1122 | //* right space 1123 | if (nk_group_begin(ctx, "right", NK_WINDOW_BORDER|NK_WINDOW_NO_SCROLLBAR)) { 1124 | nk_layout_row_dynamic(ctx, 25, 1); 1125 | nk_button_label(ctx, "#FFAA"); 1126 | nk_button_label(ctx, "#FFBB"); 1127 | nk_button_label(ctx, "#FFCC"); 1128 | nk_button_label(ctx, "#FFDD"); 1129 | nk_button_label(ctx, "#FFEE"); 1130 | nk_button_label(ctx, "#FFFF"); 1131 | nk_group_end(ctx); 1132 | } 1133 | 1134 | nk_tree_pop(ctx); 1135 | } 1136 | 1137 | if (nk_tree_push(ctx, NK_TREE_NODE, "Horizontal", NK_MINIMIZED)) 1138 | { 1139 | static float a2 = 100, b2 = 100, c2 = 100; 1140 | nk_rect bounds; 1141 | 1142 | //* header 1143 | nk_layout_row_static(ctx, 30, 100, 2); 1144 | nk_label(ctx, "top:", NK_TEXT_LEFT); 1145 | nk_slider_float(ctx, 10.0f, &a2, 200.0f, 10.0f); 1146 | 1147 | nk_label(ctx, "middle:", NK_TEXT_LEFT); 1148 | nk_slider_float(ctx, 10.0f, &b2, 200.0f, 10.0f); 1149 | 1150 | nk_label(ctx, "bottom:", NK_TEXT_LEFT); 1151 | nk_slider_float(ctx, 10.0f, &c2, 200.0f, 10.0f); 1152 | 1153 | //* top space 1154 | nk_layout_row_dynamic(ctx, a2, 1); 1155 | if (nk_group_begin(ctx, "top", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) { 1156 | nk_layout_row_dynamic(ctx, 25, 3); 1157 | nk_button_label(ctx, "#FFAA"); 1158 | nk_button_label(ctx, "#FFBB"); 1159 | nk_button_label(ctx, "#FFCC"); 1160 | nk_button_label(ctx, "#FFDD"); 1161 | nk_button_label(ctx, "#FFEE"); 1162 | nk_button_label(ctx, "#FFFF"); 1163 | nk_group_end(ctx); 1164 | } 1165 | 1166 | //* scaler 1167 | nk_layout_row_dynamic(ctx, 8, 1); 1168 | bounds = nk_widget_bounds(ctx); 1169 | nk_spacing(ctx, 1); 1170 | if ((nk_input_is_mouse_hovering_rect(in_, bounds) || 1171 | nk_input_is_mouse_prev_hovering_rect(in_, bounds)) && 1172 | nk_input_is_mouse_down(in_, NK_BUTTON_LEFT)) 1173 | { 1174 | a2 = a2 + in_.mouse.delta.y; 1175 | b2 = b2 - in_.mouse.delta.y; 1176 | } 1177 | 1178 | //* middle space 1179 | nk_layout_row_dynamic(ctx, b2, 1); 1180 | if (nk_group_begin(ctx, "middle", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) { 1181 | nk_layout_row_dynamic(ctx, 25, 3); 1182 | nk_button_label(ctx, "#FFAA"); 1183 | nk_button_label(ctx, "#FFBB"); 1184 | nk_button_label(ctx, "#FFCC"); 1185 | nk_button_label(ctx, "#FFDD"); 1186 | nk_button_label(ctx, "#FFEE"); 1187 | nk_button_label(ctx, "#FFFF"); 1188 | nk_group_end(ctx); 1189 | } 1190 | 1191 | { 1192 | //* scaler 1193 | nk_layout_row_dynamic(ctx, 8, 1); 1194 | bounds = nk_widget_bounds(ctx); 1195 | if ((nk_input_is_mouse_hovering_rect(in_, bounds) || 1196 | nk_input_is_mouse_prev_hovering_rect(in_, bounds)) && 1197 | nk_input_is_mouse_down(in_, NK_BUTTON_LEFT)) 1198 | { 1199 | b2 = b2 + in_.mouse.delta.y; 1200 | c2 = c2 - in_.mouse.delta.y; 1201 | } 1202 | } 1203 | 1204 | //* bottom space 1205 | nk_layout_row_dynamic(ctx, c2, 1); 1206 | if (nk_group_begin(ctx, "bottom", NK_WINDOW_NO_SCROLLBAR|NK_WINDOW_BORDER)) { 1207 | nk_layout_row_dynamic(ctx, 25, 3); 1208 | nk_button_label(ctx, "#FFAA"); 1209 | nk_button_label(ctx, "#FFBB"); 1210 | nk_button_label(ctx, "#FFCC"); 1211 | nk_button_label(ctx, "#FFDD"); 1212 | nk_button_label(ctx, "#FFEE"); 1213 | nk_button_label(ctx, "#FFFF"); 1214 | nk_group_end(ctx); 1215 | } 1216 | nk_tree_pop(ctx); 1217 | } 1218 | nk_tree_pop(ctx); 1219 | } 1220 | nk_tree_pop(ctx); 1221 | } 1222 | 1223 | } 1224 | nk_end(ctx); 1225 | return !nk_window_is_closed(ctx, "Overview"); 1226 | } 1227 | -------------------------------------------------------------------------------- /demo/source/style.d: -------------------------------------------------------------------------------- 1 | module style; 2 | 3 | import bindbc.nuklear; 4 | 5 | enum theme { THEME_BLACK, THEME_WHITE, THEME_RED, THEME_BLUE, THEME_DARK } 6 | 7 | void 8 | set_style(nk_context *ctx, theme theme) 9 | { 10 | nk_color[NK_COLOR_COUNT] table; 11 | if (theme == theme.THEME_WHITE) { 12 | table[NK_COLOR_TEXT] = nk_rgba(70, 70, 70, 255); 13 | table[NK_COLOR_WINDOW] = nk_rgba(175, 175, 175, 255); 14 | table[NK_COLOR_HEADER] = nk_rgba(175, 175, 175, 255); 15 | table[NK_COLOR_BORDER] = nk_rgba(0, 0, 0, 255); 16 | table[NK_COLOR_BUTTON] = nk_rgba(185, 185, 185, 255); 17 | table[NK_COLOR_BUTTON_HOVER] = nk_rgba(170, 170, 170, 255); 18 | table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(160, 160, 160, 255); 19 | table[NK_COLOR_TOGGLE] = nk_rgba(150, 150, 150, 255); 20 | table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(120, 120, 120, 255); 21 | table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(175, 175, 175, 255); 22 | table[NK_COLOR_SELECT] = nk_rgba(190, 190, 190, 255); 23 | table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(175, 175, 175, 255); 24 | table[NK_COLOR_SLIDER] = nk_rgba(190, 190, 190, 255); 25 | table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(80, 80, 80, 255); 26 | table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(70, 70, 70, 255); 27 | table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(60, 60, 60, 255); 28 | table[NK_COLOR_PROPERTY] = nk_rgba(175, 175, 175, 255); 29 | table[NK_COLOR_EDIT] = nk_rgba(150, 150, 150, 255); 30 | table[NK_COLOR_EDIT_CURSOR] = nk_rgba(0, 0, 0, 255); 31 | table[NK_COLOR_COMBO] = nk_rgba(175, 175, 175, 255); 32 | table[NK_COLOR_CHART] = nk_rgba(160, 160, 160, 255); 33 | table[NK_COLOR_CHART_COLOR] = nk_rgba(45, 45, 45, 255); 34 | table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255); 35 | table[NK_COLOR_SCROLLBAR] = nk_rgba(180, 180, 180, 255); 36 | table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(140, 140, 140, 255); 37 | table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(150, 150, 150, 255); 38 | table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(160, 160, 160, 255); 39 | table[NK_COLOR_TAB_HEADER] = nk_rgba(180, 180, 180, 255); 40 | nk_style_from_table(ctx, table.ptr); 41 | } else if (theme == theme.THEME_RED) { 42 | table[NK_COLOR_TEXT] = nk_rgba(190, 190, 190, 255); 43 | table[NK_COLOR_WINDOW] = nk_rgba(30, 33, 40, 215); 44 | table[NK_COLOR_HEADER] = nk_rgba(181, 45, 69, 220); 45 | table[NK_COLOR_BORDER] = nk_rgba(51, 55, 67, 255); 46 | table[NK_COLOR_BUTTON] = nk_rgba(181, 45, 69, 255); 47 | table[NK_COLOR_BUTTON_HOVER] = nk_rgba(190, 50, 70, 255); 48 | table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(195, 55, 75, 255); 49 | table[NK_COLOR_TOGGLE] = nk_rgba(51, 55, 67, 255); 50 | table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 60, 60, 255); 51 | table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(181, 45, 69, 255); 52 | table[NK_COLOR_SELECT] = nk_rgba(51, 55, 67, 255); 53 | table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(181, 45, 69, 255); 54 | table[NK_COLOR_SLIDER] = nk_rgba(51, 55, 67, 255); 55 | table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(181, 45, 69, 255); 56 | table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(186, 50, 74, 255); 57 | table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(191, 55, 79, 255); 58 | table[NK_COLOR_PROPERTY] = nk_rgba(51, 55, 67, 255); 59 | table[NK_COLOR_EDIT] = nk_rgba(51, 55, 67, 225); 60 | table[NK_COLOR_EDIT_CURSOR] = nk_rgba(190, 190, 190, 255); 61 | table[NK_COLOR_COMBO] = nk_rgba(51, 55, 67, 255); 62 | table[NK_COLOR_CHART] = nk_rgba(51, 55, 67, 255); 63 | table[NK_COLOR_CHART_COLOR] = nk_rgba(170, 40, 60, 255); 64 | table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255); 65 | table[NK_COLOR_SCROLLBAR] = nk_rgba(30, 33, 40, 255); 66 | table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255); 67 | table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255); 68 | table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255); 69 | table[NK_COLOR_TAB_HEADER] = nk_rgba(181, 45, 69, 220); 70 | nk_style_from_table(ctx, table.ptr); 71 | } else if (theme == theme.THEME_BLUE) { 72 | table[NK_COLOR_TEXT] = nk_rgba(20, 20, 20, 255); 73 | table[NK_COLOR_WINDOW] = nk_rgba(202, 212, 214, 215); 74 | table[NK_COLOR_HEADER] = nk_rgba(137, 182, 224, 220); 75 | table[NK_COLOR_BORDER] = nk_rgba(140, 159, 173, 255); 76 | table[NK_COLOR_BUTTON] = nk_rgba(137, 182, 224, 255); 77 | table[NK_COLOR_BUTTON_HOVER] = nk_rgba(142, 187, 229, 255); 78 | table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(147, 192, 234, 255); 79 | table[NK_COLOR_TOGGLE] = nk_rgba(177, 210, 210, 255); 80 | table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(182, 215, 215, 255); 81 | table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(137, 182, 224, 255); 82 | table[NK_COLOR_SELECT] = nk_rgba(177, 210, 210, 255); 83 | table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(137, 182, 224, 255); 84 | table[NK_COLOR_SLIDER] = nk_rgba(177, 210, 210, 255); 85 | table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(137, 182, 224, 245); 86 | table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(142, 188, 229, 255); 87 | table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(147, 193, 234, 255); 88 | table[NK_COLOR_PROPERTY] = nk_rgba(210, 210, 210, 255); 89 | table[NK_COLOR_EDIT] = nk_rgba(210, 210, 210, 225); 90 | table[NK_COLOR_EDIT_CURSOR] = nk_rgba(20, 20, 20, 255); 91 | table[NK_COLOR_COMBO] = nk_rgba(210, 210, 210, 255); 92 | table[NK_COLOR_CHART] = nk_rgba(210, 210, 210, 255); 93 | table[NK_COLOR_CHART_COLOR] = nk_rgba(137, 182, 224, 255); 94 | table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255); 95 | table[NK_COLOR_SCROLLBAR] = nk_rgba(190, 200, 200, 255); 96 | table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(64, 84, 95, 255); 97 | table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(70, 90, 100, 255); 98 | table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(75, 95, 105, 255); 99 | table[NK_COLOR_TAB_HEADER] = nk_rgba(156, 193, 220, 255); 100 | nk_style_from_table(ctx, table.ptr); 101 | } else if (theme == theme.THEME_DARK) { 102 | table[NK_COLOR_TEXT] = nk_rgba(210, 210, 210, 255); 103 | table[NK_COLOR_WINDOW] = nk_rgba(57, 67, 71, 215); 104 | table[NK_COLOR_HEADER] = nk_rgba(51, 51, 56, 220); 105 | table[NK_COLOR_BORDER] = nk_rgba(46, 46, 46, 255); 106 | table[NK_COLOR_BUTTON] = nk_rgba(48, 83, 111, 255); 107 | table[NK_COLOR_BUTTON_HOVER] = nk_rgba(58, 93, 121, 255); 108 | table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(63, 98, 126, 255); 109 | table[NK_COLOR_TOGGLE] = nk_rgba(50, 58, 61, 255); 110 | table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(45, 53, 56, 255); 111 | table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(48, 83, 111, 255); 112 | table[NK_COLOR_SELECT] = nk_rgba(57, 67, 61, 255); 113 | table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(48, 83, 111, 255); 114 | table[NK_COLOR_SLIDER] = nk_rgba(50, 58, 61, 255); 115 | table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(48, 83, 111, 245); 116 | table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255); 117 | table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255); 118 | table[NK_COLOR_PROPERTY] = nk_rgba(50, 58, 61, 255); 119 | table[NK_COLOR_EDIT] = nk_rgba(50, 58, 61, 225); 120 | table[NK_COLOR_EDIT_CURSOR] = nk_rgba(210, 210, 210, 255); 121 | table[NK_COLOR_COMBO] = nk_rgba(50, 58, 61, 255); 122 | table[NK_COLOR_CHART] = nk_rgba(50, 58, 61, 255); 123 | table[NK_COLOR_CHART_COLOR] = nk_rgba(48, 83, 111, 255); 124 | table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba(255, 0, 0, 255); 125 | table[NK_COLOR_SCROLLBAR] = nk_rgba(50, 58, 61, 255); 126 | table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(48, 83, 111, 255); 127 | table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(53, 88, 116, 255); 128 | table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(58, 93, 121, 255); 129 | table[NK_COLOR_TAB_HEADER] = nk_rgba(48, 83, 111, 255); 130 | nk_style_from_table(ctx, table.ptr); 131 | } else { 132 | nk_style_default(ctx); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /dub.sdl: -------------------------------------------------------------------------------- 1 | name "bindbc-nuklear" 2 | description "Dynamic and static bindings to nuklear, compatible with -betterC, @nogc, and nothrow." 3 | homepage "" 4 | authors "Mateusz Muszynski" 5 | license "Boost" 6 | 7 | targetType "staticLibrary" 8 | targetPath "lib" 9 | targetName "BindBC_nuklear" 10 | 11 | configuration "dynamic" { 12 | dependency "bindbc-loader" version=">=1.0.1" 13 | copyFiles "lib/win32/nuklear.dll" platform="windows-x86" 14 | copyFiles "lib/win64/nuklear.dll" platform="windows-x86_64" 15 | } 16 | 17 | configuration "dynamicBC" { 18 | dependency "bindbc-loader" version=">=1.0.1" 19 | subConfiguration "bindbc-loader" "yesBC" 20 | copyFiles "lib/win32/nuklear.dll" platform="windows-x86" 21 | copyFiles "lib/win64/nuklear.dll" platform="windows-x86_64" 22 | } 23 | 24 | configuration "static" { 25 | versions "BindNuklear_Static" 26 | excludedSourceFiles "source/bindbc/nuklear/binddynamic.d" 27 | lflags "-L$PACKAGE_DIR/lib" "-lnuklear_static" "-lSDL2" platform="posix" 28 | lflags "-L$PACKAGE_DIR/lib" "-lnuklear_static" "-lSDL2" platform="macos" 29 | } 30 | 31 | configuration "staticBC" { 32 | dflags "-betterC" 33 | versions "BindNuklear_Static" 34 | excludedSourceFiles "source/bindbc/nuklear/binddynamic.d" 35 | lflags "-L$PACKAGE_DIR/lib" "-lnuklear_static" "-lSDL2" platform="posix" 36 | lflags "-L$PACKAGE_DIR/lib" "-lnuklear_static" "-lSDL2" platform="macos" 37 | } 38 | -------------------------------------------------------------------------------- /include/.gitignore: -------------------------------------------------------------------------------- 1 | /nuklear.h 2 | -------------------------------------------------------------------------------- /lib/win32/nuklear.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Timu5/bindbc-nuklear/a6a5dca24051218dbae96ae322c00f15a7d516b2/lib/win32/nuklear.dll -------------------------------------------------------------------------------- /lib/win64/nuklear.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Timu5/bindbc-nuklear/a6a5dca24051218dbae96ae322c00f15a7d516b2/lib/win64/nuklear.dll -------------------------------------------------------------------------------- /prebuild.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 4 | 5 | cd ${DIR} 6 | install -d build 7 | cd build 8 | cmake ../c 9 | 10 | PROC_COUNT=`getconf _NPROCESSORS_ONLN` 11 | 12 | make -j${PROC_COUNT} install 13 | 14 | echo "Done" 15 | -------------------------------------------------------------------------------- /source/bindbc/nuklear/bindstatic.d: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Mateusz Muszyński 2019. 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.bindstatic; 8 | 9 | version(BindNuklear_Static): 10 | 11 | import bindbc.nuklear.types; 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(NK_INCLUDE_STANDARD_VARARGS) { 29 | import core.stdc.stdarg; 30 | } 31 | 32 | extern(C) @nogc nothrow { 33 | version(NK_INCLUDE_DEFAULT_ALLOCATOR) { 34 | bool nk_init_default(nk_context*, const(nk_user_font)*); 35 | } 36 | bool nk_init_fixed(nk_context*, void* memory, nk_size size, const(nk_user_font)*); 37 | bool nk_init(nk_context*, nk_allocator*, const(nk_user_font)*); 38 | bool nk_init_custom(nk_context*, nk_buffer* cmds, nk_buffer* pool, const(nk_user_font)*); 39 | void nk_clear(nk_context*); 40 | void nk_free(nk_context*); 41 | version(NK_INCLUDE_COMMAND_USERDATA) { 42 | void nk_set_user_data(nk_context*, nk_handle handle); 43 | } 44 | void nk_input_begin(nk_context*); 45 | void nk_input_motion(nk_context*, int x, int y); 46 | void nk_input_key(nk_context*, nk_keys, bool down); 47 | void nk_input_button(nk_context*, nk_buttons, int x, int y, bool down); 48 | void nk_input_scroll(nk_context*, nk_vec2 val); 49 | void nk_input_char(nk_context*, char); 50 | void nk_input_glyph(nk_context*, const(char)*); 51 | void nk_input_unicode(nk_context*, nk_rune); 52 | void nk_input_end(nk_context*); 53 | const(nk_command)* nk__begin(nk_context*); 54 | const(nk_command)* nk__next(nk_context*, const(nk_command)*); 55 | version(NK_INCLUDE_VERTEX_BUFFER_OUTPUT) { 56 | nk_flags nk_convert(nk_context*, nk_buffer* cmds, nk_buffer* vertices, nk_buffer* elements, const(nk_convert_config)*); 57 | const(nk_draw_command)* nk__draw_begin(const(nk_context)*, const(nk_buffer)*); 58 | const(nk_draw_command)* nk__draw_end(const(nk_context)*, const(nk_buffer)*); 59 | const(nk_draw_command)* nk__draw_next(const(nk_draw_command)*, const(nk_buffer)*, const(nk_context)*); 60 | } 61 | bool nk_begin(nk_context* ctx, const(char)* title, nk_rect bounds, nk_flags flags); 62 | bool nk_begin_titled(nk_context* ctx, const(char)* name, const(char)* title, nk_rect bounds, nk_flags flags); 63 | void nk_end(nk_context* ctx); 64 | nk_window* nk_window_find(nk_context* ctx, const(char)* name); 65 | nk_rect nk_window_get_bounds(const(nk_context)* ctx); 66 | nk_vec2 nk_window_get_position(const(nk_context)* ctx); 67 | nk_vec2 nk_window_get_size(const(nk_context)*); 68 | float nk_window_get_width(const(nk_context)*); 69 | float nk_window_get_height(const(nk_context)*); 70 | nk_panel* nk_window_get_panel(nk_context*); 71 | nk_rect nk_window_get_content_region(nk_context*); 72 | nk_vec2 nk_window_get_content_region_min(nk_context*); 73 | nk_vec2 nk_window_get_content_region_max(nk_context*); 74 | nk_vec2 nk_window_get_content_region_size(nk_context*); 75 | nk_command_buffer* nk_window_get_canvas(nk_context*); 76 | void nk_window_get_scroll(nk_context*, nk_uint* offset_x, nk_uint* offset_y); // 4.01.0 77 | bool nk_window_has_focus(const(nk_context)*); 78 | bool nk_window_is_hovered(nk_context*); 79 | bool nk_window_is_collapsed(nk_context* ctx, const(char)* name); 80 | bool nk_window_is_closed(nk_context*, const(char)*); 81 | bool nk_window_is_hidden(nk_context*, const(char)*); 82 | bool nk_window_is_active(nk_context*, const(char)*); 83 | bool nk_window_is_any_hovered(nk_context*); 84 | bool nk_item_is_any_active(nk_context*); 85 | void nk_window_set_bounds(nk_context*, const(char)* name, nk_rect bounds); 86 | void nk_window_set_position(nk_context*, const(char)* name, nk_vec2 pos); 87 | void nk_window_set_size(nk_context*, const(char)* name, nk_vec2); 88 | void nk_window_set_focus(nk_context*, const(char)* name); 89 | void nk_window_set_scroll(nk_context*, nk_uint offset_x, nk_uint offset_y); // 4.01.0 90 | void nk_window_close(nk_context* ctx, const(char)* name); 91 | void nk_window_collapse(nk_context*, const(char)* name, nk_collapse_states state); 92 | void nk_window_collapse_if(nk_context*, const(char)* name, nk_collapse_states, int cond); 93 | void nk_window_show(nk_context*, const(char)* name, nk_show_states); 94 | void nk_window_show_if(nk_context*, const(char)* name, nk_show_states, int cond); 95 | void nk_layout_set_min_row_height(nk_context*, float height); 96 | void nk_layout_reset_min_row_height(nk_context*); 97 | nk_rect nk_layout_widget_bounds(nk_context*); 98 | float nk_layout_ratio_from_pixel(nk_context*, float pixel_width); 99 | void nk_layout_row_dynamic(nk_context* ctx, float height, int cols); 100 | void nk_layout_row_static(nk_context* ctx, float height, int item_width, int cols); 101 | void nk_layout_row_begin(nk_context* ctx, nk_layout_format fmt, float row_height, int cols); 102 | void nk_layout_row_push(nk_context*, float value); 103 | void nk_layout_row_end(nk_context*); 104 | void nk_layout_row(nk_context*, nk_layout_format, float height, int cols, const(float)* ratio); 105 | void nk_layout_row_template_begin(nk_context*, float row_height); 106 | void nk_layout_row_template_push_dynamic(nk_context*); 107 | void nk_layout_row_template_push_variable(nk_context*, float min_width); 108 | void nk_layout_row_template_push_static(nk_context*, float width); 109 | void nk_layout_row_template_end(nk_context*); 110 | void nk_layout_space_begin(nk_context*, nk_layout_format, float height, int widget_count); 111 | void nk_layout_space_push(nk_context*, nk_rect bounds); 112 | void nk_layout_space_end(nk_context*); 113 | nk_rect nk_layout_space_bounds(nk_context*); 114 | nk_vec2 nk_layout_space_to_screen(nk_context*, nk_vec2); 115 | nk_vec2 nk_layout_space_to_local(nk_context*, nk_vec2); 116 | nk_rect nk_layout_space_rect_to_screen(nk_context*, nk_rect); 117 | nk_rect nk_layout_space_rect_to_local(nk_context*, nk_rect); 118 | void nk_spacer(nk_context*); 119 | bool nk_group_begin(nk_context*, const(char)* title, nk_flags); 120 | bool nk_group_begin_titled(nk_context*, const(char)* name, const(char)* title, nk_flags); 121 | void nk_group_end(nk_context*); 122 | bool nk_group_scrolled_offset_begin(nk_context*, nk_uint* x_offset, nk_uint* y_offset, const(char)* title, nk_flags flags); 123 | bool nk_group_scrolled_begin(nk_context*, nk_scroll* off, const(char)* title, nk_flags); 124 | void nk_group_scrolled_end(nk_context*); 125 | void nk_group_get_scroll(nk_context*, const(char)* id, nk_uint *x_offset, nk_uint *y_offset); // 4.01.0 126 | void nk_group_set_scroll(nk_context*, const(char)* id, nk_uint x_offset, nk_uint y_offset); // 4.01.0 127 | bool nk_tree_push_hashed(nk_context*, nk_tree_type, const(char)* title, nk_collapse_states initial_state, const(char)* hash, int len, int seed); 128 | bool nk_tree_image_push_hashed(nk_context*, nk_tree_type, nk_image, const(char)* title, nk_collapse_states initial_state, const(char)* hash, int len, int seed); 129 | void nk_tree_pop(nk_context*); 130 | bool nk_tree_state_push(nk_context*, nk_tree_type, const(char)* title, nk_collapse_states* state); 131 | bool nk_tree_state_image_push(nk_context*, nk_tree_type, nk_image, const(char)* title, nk_collapse_states* state); 132 | void nk_tree_state_pop(nk_context*); 133 | bool nk_tree_element_push_hashed(nk_context*, nk_tree_type, const(char)* title, nk_collapse_states initial_state, int* selected, const(char)* hash, int len, int seed); 134 | bool nk_tree_element_image_push_hashed(nk_context*, nk_tree_type, nk_image, const(char)* title, nk_collapse_states initial_state, int* selected, const(char)* hash, int len, int seed); 135 | void nk_tree_element_pop(nk_context*); 136 | bool nk_list_view_begin(nk_context*, nk_list_view* out_, const(char)* id, nk_flags, int row_height, int row_count); 137 | void nk_list_view_end(nk_list_view*); 138 | nk_widget_layout_states nk_widget(nk_rect*, const(nk_context)*); 139 | nk_widget_layout_states nk_widget_fitting(nk_rect*, nk_context*, nk_vec2); 140 | nk_rect nk_widget_bounds(nk_context*); 141 | nk_vec2 nk_widget_position(nk_context*); 142 | nk_vec2 nk_widget_size(nk_context*); 143 | float nk_widget_width(nk_context*); 144 | float nk_widget_height(nk_context*); 145 | bool nk_widget_is_hovered(nk_context*); 146 | bool nk_widget_is_mouse_clicked(nk_context*, nk_buttons); 147 | bool nk_widget_has_mouse_click_down(nk_context*, nk_buttons, bool down); 148 | void nk_spacing(nk_context*, int cols); 149 | void nk_text(nk_context*, const(char)*, int, nk_flags); 150 | void nk_text_colored(nk_context*, const(char)*, int, nk_flags, nk_color); 151 | void nk_text_wrap(nk_context*, const(char)*, int); 152 | void nk_text_wrap_colored(nk_context*, const(char)*, int, nk_color); 153 | void nk_label(nk_context*, const(char)*, nk_flags align__); 154 | void nk_label_colored(nk_context*, const(char)*, nk_flags align__, nk_color); 155 | void nk_label_wrap(nk_context*, const(char)*); 156 | void nk_label_colored_wrap(nk_context*, const(char)*, nk_color); 157 | pragma(mangle, "nk_image") 158 | void nk_image_(nk_context*, nk_image); 159 | void nk_image_color(nk_context*, nk_image, nk_color); 160 | version(NK_INCLUDE_STANDARD_VARARGS) { 161 | void nk_labelf(nk_context*, nk_flags, const(char)*, ...); 162 | void nk_labelf_colored(nk_context*, nk_flags, nk_color, const(char)*, ...); 163 | void nk_labelf_wrap(nk_context*, const(char)*, ...); 164 | void nk_labelf_colored_wrap(nk_context*, nk_color, const(char)*, ...); 165 | void nk_labelfv(nk_context*, nk_flags, const(char)*, va_list); 166 | void nk_labelfv_colored(nk_context*, nk_flags, nk_color, const(char)*, va_list); 167 | void nk_labelfv_wrap(nk_context*, const(char)*, va_list); 168 | void nk_labelfv_colored_wrap(nk_context*, nk_color, const(char)*, va_list); 169 | void nk_value_bool(nk_context*, const(char)* prefix, int); 170 | void nk_value_int(nk_context*, const(char)* prefix, int); 171 | void nk_value_uint(nk_context*, const(char)* prefix, uint); 172 | void nk_value_float(nk_context*, const(char)* prefix, float); 173 | void nk_value_color_byte(nk_context*, const(char)* prefix, nk_color); 174 | void nk_value_color_float(nk_context*, const(char)* prefix, nk_color); 175 | void nk_value_color_hex(nk_context*, const(char)* prefix, nk_color); 176 | } 177 | bool nk_button_text(nk_context*, const(char)* title, int len); 178 | bool nk_button_label(nk_context*, const(char)* title); 179 | bool nk_button_color(nk_context*, nk_color); 180 | bool nk_button_symbol(nk_context*, nk_symbol_type); 181 | bool nk_button_image(nk_context*, nk_image img); 182 | bool nk_button_symbol_label(nk_context*, nk_symbol_type, const(char)*, nk_flags text_alignment); 183 | bool nk_button_symbol_text(nk_context*, nk_symbol_type, const(char)*, int, nk_flags align_ment); 184 | bool nk_button_image_label(nk_context*, nk_image img, const(char)*, nk_flags text_alignment); 185 | bool nk_button_image_text(nk_context*, nk_image img, const(char)*, int, nk_flags align_ment); 186 | bool nk_button_text_styled(nk_context*, const(nk_style_button)*, const(char)* title, int len); 187 | bool nk_button_label_styled(nk_context*, const(nk_style_button)*, const(char)* title); 188 | bool nk_button_symbol_styled(nk_context*, const(nk_style_button)*, nk_symbol_type); 189 | bool nk_button_image_styled(nk_context*, const(nk_style_button)*, nk_image img); 190 | bool nk_button_symbol_text_styled(nk_context*, const(nk_style_button)*, nk_symbol_type, const(char)*, int, nk_flags align_ment); 191 | bool nk_button_symbol_label_styled(nk_context* ctx, const(nk_style_button)* style, nk_symbol_type symbol, const(char)* title, nk_flags align_); 192 | bool nk_button_image_label_styled(nk_context*, const(nk_style_button)*, nk_image img, const(char)*, nk_flags text_alignment); 193 | bool nk_button_image_text_styled(nk_context*, const(nk_style_button)*, nk_image img, const(char)*, int, nk_flags align_ment); 194 | void nk_button_set_behavior(nk_context*, nk_button_behavior); 195 | bool nk_button_push_behavior(nk_context*, nk_button_behavior); 196 | bool nk_button_pop_behavior(nk_context*); 197 | bool nk_check_label(nk_context*, const(char)*, bool active); 198 | bool nk_check_text(nk_context*, const(char)*, int, bool active); 199 | uint nk_check_flags_label(nk_context*, const(char)*, uint flags, uint value); 200 | uint nk_check_flags_text(nk_context*, const(char)*, int, uint flags, uint value); 201 | bool nk_checkbox_label(nk_context*, const(char)*, bool* active); 202 | bool nk_checkbox_text(nk_context*, const(char)*, int, bool* active); 203 | bool nk_checkbox_flags_label(nk_context*, const(char)*, uint* flags, uint value); 204 | bool nk_checkbox_flags_text(nk_context*, const(char)*, int, uint* flags, uint value); 205 | bool nk_radio_label(nk_context*, const(char)*, bool* active); 206 | bool nk_radio_text(nk_context*, const(char)*, int, bool* active); 207 | bool nk_option_label(nk_context*, const(char)*, bool active); 208 | bool nk_option_text(nk_context*, const(char)*, int, bool active); 209 | bool nk_selectable_label(nk_context*, const(char)*, nk_flags align_, bool* value); 210 | bool nk_selectable_text(nk_context*, const(char)*, int, nk_flags align_, bool* value); 211 | bool nk_selectable_image_label(nk_context*, nk_image, const(char)*, nk_flags align_, bool* value); 212 | bool nk_selectable_image_text(nk_context*, nk_image, const(char)*, int, nk_flags align_, bool* value); 213 | bool nk_selectable_symbol_label(nk_context*, nk_symbol_type, const(char)*, nk_flags align_, bool* value); 214 | bool nk_selectable_symbol_text(nk_context*, nk_symbol_type, const(char)*, int, nk_flags align_, bool* value); 215 | bool nk_select_label(nk_context*, const(char)*, nk_flags align_, bool value); 216 | bool nk_select_text(nk_context*, const(char)*, int, nk_flags align_, bool value); 217 | bool nk_select_image_label(nk_context*, nk_image, const(char)*, nk_flags align_, bool value); 218 | bool nk_select_image_text(nk_context*, nk_image, const(char)*, int, nk_flags align_, bool value); 219 | bool nk_select_symbol_label(nk_context*, nk_symbol_type, const(char)*, nk_flags align_, bool value); 220 | bool nk_select_symbol_text(nk_context*, nk_symbol_type, const(char)*, int, nk_flags align_, bool value); 221 | float nk_slide_float(nk_context*, float min, float val, float max, float step); 222 | int nk_slide_int(nk_context*, int min, int val, int max, int step); 223 | bool nk_slider_float(nk_context*, float min, float* val, float max, float step); 224 | bool nk_slider_int(nk_context*, int min, int* val, int max, int step); 225 | bool nk_progress(nk_context*, nk_size* cur, nk_size max, bool modifyable); 226 | nk_size nk_prog(nk_context*, nk_size cur, nk_size max, bool modifyable); 227 | nk_colorf nk_color_picker(nk_context*, nk_colorf, nk_color_format); 228 | int nk_color_pick(nk_context*, nk_colorf*, nk_color_format); 229 | void nk_property_int(nk_context*, const(char)* name, int min, int* val, int max, int step, float inc_per_pixel); 230 | void nk_property_float(nk_context*, const(char)* name, float min, float* val, float max, float step, float inc_per_pixel); 231 | void nk_property_double(nk_context*, const(char)* name, double min, double* val, double max, double step, float inc_per_pixel); 232 | int nk_propertyi(nk_context*, const(char)* name, int min, int val, int max, int step, float inc_per_pixel); 233 | float nk_propertyf(nk_context*, const(char)* name, float min, float val, float max, float step, float inc_per_pixel); 234 | double nk_propertyd(nk_context*, const(char)* name, double min, double val, double max, double step, float inc_per_pixel); 235 | nk_flags nk_edit_string(nk_context*, nk_flags, char* buffer, int* len, int max, nk_plugin_filter); 236 | nk_flags nk_edit_string_zero_terminated(nk_context*, nk_flags, char* buffer, int max, nk_plugin_filter); 237 | nk_flags nk_edit_buffer(nk_context*, nk_flags, nk_text_edit*, nk_plugin_filter); 238 | void nk_edit_focus(nk_context*, nk_flags flags); 239 | void nk_edit_unfocus(nk_context*); 240 | bool nk_chart_begin(nk_context*, nk_chart_type, int num, float min, float max); 241 | bool nk_chart_begin_colored(nk_context*, nk_chart_type, nk_color, nk_color active, int num, float min, float max); 242 | void nk_chart_add_slot(nk_context* ctx, const(nk_chart_type), int count, float min_value, float max_value); 243 | void nk_chart_add_slot_colored(nk_context* ctx, const(nk_chart_type), nk_color, nk_color active, int count, float min_value, float max_value); 244 | nk_flags nk_chart_push(nk_context*, float); 245 | nk_flags nk_chart_push_slot(nk_context*, float, int); 246 | void nk_chart_end(nk_context*); 247 | void nk_plot(nk_context*, nk_chart_type, const(float)* values, int count, int offset); 248 | void nk_plot_function(nk_context*, nk_chart_type, void *userdata, float function(void* user, int index), int count, int offset); 249 | bool nk_popup_begin(nk_context*, nk_popup_type, const(char)*, nk_flags, nk_rect bounds); 250 | void nk_popup_close(nk_context*); 251 | void nk_popup_end(nk_context*); 252 | void nk_popup_get_scroll(nk_context*, nk_uint *offset_x, nk_uint *offset_y); // 4.01.0 253 | void nk_popup_set_scroll(nk_context*, nk_uint offset_x, nk_uint offset_y); // 4.01.0 254 | int nk_combo(nk_context*, const(char)** items, int count, int selected, int item_height, nk_vec2 size); 255 | void nk_combo_separator(nk_context*, const(char)* items_separated_by_separator, int separator, int selected, int count, int item_height, nk_vec2 size); 256 | void nk_combo_string(nk_context*, const(char)* items_separated_by_zeros, int selected, int count, int item_height, nk_vec2 size); 257 | void nk_combo_callback(nk_context*, void function(void*, int, const(char) **), void *userdata, int selected, int count, int item_height, nk_vec2 size); 258 | void nk_combobox(nk_context*, const(char)** items, int count, int* selected, int item_height, nk_vec2 size); 259 | void nk_combobox_string(nk_context*, const(char)* items_separated_by_zeros, int* selected, int count, int item_height, nk_vec2 size); 260 | void nk_combobox_separator(nk_context*, const(char)* items_separated_by_separator, int separator, int* selected, int count, int item_height, nk_vec2 size); 261 | void nk_combobox_callback(nk_context*, void function(void*, int, const(char) **), void*, int *selected, int count, int item_height, nk_vec2 size); 262 | bool nk_combo_begin_text(nk_context*, const(char)* selected, int, nk_vec2 size); 263 | bool nk_combo_begin_label(nk_context*, const(char)* selected, nk_vec2 size); 264 | bool nk_combo_begin_color(nk_context*, nk_color color, nk_vec2 size); 265 | bool nk_combo_begin_symbol(nk_context*, nk_symbol_type, nk_vec2 size); 266 | bool nk_combo_begin_symbol_label(nk_context*, const(char)* selected, nk_symbol_type, nk_vec2 size); 267 | bool nk_combo_begin_symbol_text(nk_context*, const(char)* selected, int, nk_symbol_type, nk_vec2 size); 268 | bool nk_combo_begin_image(nk_context*, nk_image img, nk_vec2 size); 269 | bool nk_combo_begin_image_label(nk_context*, const(char)* selected, nk_image, nk_vec2 size); 270 | bool nk_combo_begin_image_text(nk_context*, const(char)* selected, int, nk_image, nk_vec2 size); 271 | bool nk_combo_item_label(nk_context*, const(char)*, nk_flags align_ment); 272 | bool nk_combo_item_text(nk_context*, const(char)*, int, nk_flags align_ment); 273 | bool nk_combo_item_image_label(nk_context*, nk_image, const(char)*, nk_flags align_ment); 274 | bool nk_combo_item_image_text(nk_context*, nk_image, const(char)*, int, nk_flags align_ment); 275 | bool nk_combo_item_symbol_label(nk_context*, nk_symbol_type, const(char)*, nk_flags align_ment); 276 | bool nk_combo_item_symbol_text(nk_context*, nk_symbol_type, const(char)*, int, nk_flags align_ment); 277 | void nk_combo_close(nk_context*); 278 | void nk_combo_end(nk_context*); 279 | bool nk_contextual_begin(nk_context*, nk_flags, nk_vec2, nk_rect trigger_bounds); 280 | bool nk_contextual_item_text(nk_context*, const(char)*, int, nk_flags align_); 281 | bool nk_contextual_item_label(nk_context*, const(char)*, nk_flags align_); 282 | bool nk_contextual_item_image_label(nk_context*, nk_image, const(char)*, nk_flags align_ment); 283 | bool nk_contextual_item_image_text(nk_context*, nk_image, const(char)*, int len, nk_flags align_ment); 284 | bool nk_contextual_item_symbol_label(nk_context*, nk_symbol_type, const(char)*, nk_flags align_ment); 285 | bool nk_contextual_item_symbol_text(nk_context*, nk_symbol_type, const(char)*, int, nk_flags align_ment); 286 | void nk_contextual_close(nk_context*); 287 | void nk_contextual_end(nk_context*); 288 | void nk_tooltip(nk_context*, const(char)*); 289 | version(NK_INCLUDE_STANDARD_VARARGS) { 290 | void nk_tooltipf(nk_context*, const(char)*, ...); 291 | void nk_tooltipfv(nk_context*, const(char)*, va_list); 292 | } 293 | bool nk_tooltip_begin(nk_context*, float width); 294 | void nk_tooltip_end(nk_context*); 295 | void nk_menubar_begin(nk_context*); 296 | void nk_menubar_end(nk_context*); 297 | bool nk_menu_begin_text(nk_context*, const(char)* title, int title_len, nk_flags align_, nk_vec2 size); 298 | bool nk_menu_begin_label(nk_context*, const(char)*, nk_flags align_, nk_vec2 size); 299 | bool nk_menu_begin_image(nk_context*, const(char)*, nk_image, nk_vec2 size); 300 | bool nk_menu_begin_image_text(nk_context*, const(char)*, int, nk_flags align_, nk_image, nk_vec2 size); 301 | bool nk_menu_begin_image_label(nk_context*, const(char)*, nk_flags align_, nk_image, nk_vec2 size); 302 | bool nk_menu_begin_symbol(nk_context*, const(char)*, nk_symbol_type, nk_vec2 size); 303 | bool nk_menu_begin_symbol_text(nk_context*, const(char)*, int, nk_flags align_, nk_symbol_type, nk_vec2 size); 304 | bool nk_menu_begin_symbol_label(nk_context*, const(char)*, nk_flags align_, nk_symbol_type, nk_vec2 size); 305 | bool nk_menu_item_text(nk_context*, const(char)*, int, nk_flags align_); 306 | bool nk_menu_item_label(nk_context*, const(char)*, nk_flags align_ment); 307 | bool nk_menu_item_image_label(nk_context*, nk_image, const(char)*, nk_flags align_ment); 308 | bool nk_menu_item_image_text(nk_context*, nk_image, const(char)*, int len, nk_flags align_ment); 309 | bool nk_menu_item_symbol_text(nk_context*, nk_symbol_type, const(char)*, int, nk_flags align_ment); 310 | bool nk_menu_item_symbol_label(nk_context*, nk_symbol_type, const(char)*, nk_flags align_ment); 311 | void nk_menu_close(nk_context*); 312 | void nk_menu_end(nk_context*); 313 | void nk_style_default(nk_context*); 314 | void nk_style_from_table(nk_context*, const(nk_color)*); 315 | void nk_style_load_cursor(nk_context*, nk_style_cursor, const(nk_cursor)*); 316 | void nk_style_load_all_cursors(nk_context*, nk_cursor*); 317 | const(char)* nk_style_get_color_by_name(nk_style_colors); 318 | void nk_style_set_font(nk_context*, const(nk_user_font)*); 319 | bool nk_style_set_cursor(nk_context*, nk_style_cursor); 320 | void nk_style_show_cursor(nk_context*); 321 | void nk_style_hide_cursor(nk_context*); 322 | bool nk_style_push_font(nk_context*, const(nk_user_font)*); 323 | bool nk_style_push_float(nk_context*, float*, float); 324 | bool nk_style_push_vec2(nk_context*, nk_vec2*, nk_vec2); 325 | bool nk_style_push_style_item(nk_context*, nk_style_item*, nk_style_item); 326 | bool nk_style_push_flags(nk_context*, nk_flags*, nk_flags); 327 | bool nk_style_push_color(nk_context*, nk_color*, nk_color); 328 | bool nk_style_pop_font(nk_context*); 329 | bool nk_style_pop_float(nk_context*); 330 | bool nk_style_pop_vec2(nk_context*); 331 | bool nk_style_pop_style_item(nk_context*); 332 | bool nk_style_pop_flags(nk_context*); 333 | bool nk_style_pop_color(nk_context*); 334 | nk_color nk_rgb(int r, int g, int b); 335 | nk_color nk_rgb_iv(const(int)* rgb); 336 | nk_color nk_rgb_bv(const(nk_byte)* rgb); 337 | nk_color nk_rgb_f(float r, float g, float b); 338 | nk_color nk_rgb_fv(const(float)* rgb); 339 | nk_color nk_rgb_cf(nk_colorf c); 340 | nk_color nk_rgb_hex(const(char)* rgb); 341 | nk_color nk_rgba(int r, int g, int b, int a); 342 | nk_color nk_rgba_u32(nk_uint); 343 | nk_color nk_rgba_iv(const(int)* rgba); 344 | nk_color nk_rgba_bv(const(nk_byte)* rgba); 345 | nk_color nk_rgba_f(float r, float g, float b, float a); 346 | nk_color nk_rgba_fv(const(float)* rgba); 347 | nk_color nk_rgba_cf(nk_colorf c); 348 | nk_color nk_rgba_hex(const(char)* rgb); 349 | nk_colorf nk_hsva_colorf(float h, float s, float v, float a); 350 | nk_colorf nk_hsva_colorfv(float* c); 351 | void nk_colorf_hsva_f(float* out_h, float* out_s, float* out_v, float* out_a, nk_colorf in_); 352 | void nk_colorf_hsva_fv(float* hsva, nk_colorf in_); 353 | nk_color nk_hsv(int h, int s, int v); 354 | nk_color nk_hsv_iv(const(int)* hsv); 355 | nk_color nk_hsv_bv(const(nk_byte)* hsv); 356 | nk_color nk_hsv_f(float h, float s, float v); 357 | nk_color nk_hsv_fv(const(float)* hsv); 358 | nk_color nk_hsva(int h, int s, int v, int a); 359 | nk_color nk_hsva_iv(const(int)* hsva); 360 | nk_color nk_hsva_bv(const(nk_byte)* hsva); 361 | nk_color nk_hsva_f(float h, float s, float v, float a); 362 | nk_color nk_hsva_fv(const(float)* hsva); 363 | void nk_color_f(float* r, float* g, float* b, float* a, nk_color); 364 | void nk_color_fv(float* rgba_out, nk_color); 365 | nk_colorf nk_color_cf(nk_color); 366 | void nk_color_d(double* r, double* g, double* b, double* a, nk_color); 367 | void nk_color_dv(double* rgba_out, nk_color); 368 | nk_uint nk_color_u32(nk_color); 369 | void nk_color_hex_rgba(char* output, nk_color); 370 | void nk_color_hex_rgb(char* output, nk_color); 371 | void nk_color_hsv_i(int* out_h, int* out_s, int* out_v, nk_color); 372 | void nk_color_hsv_b(nk_byte* out_h, nk_byte* out_s, nk_byte* out_v, nk_color); 373 | void nk_color_hsv_iv(int* hsv_out, nk_color); 374 | void nk_color_hsv_bv(nk_byte* hsv_out, nk_color); 375 | void nk_color_hsv_f(float* out_h, float* out_s, float* out_v, nk_color); 376 | void nk_color_hsv_fv(float* hsv_out, nk_color); 377 | void nk_color_hsva_i(int* h, int* s, int* v, int* a, nk_color); 378 | void nk_color_hsva_b(nk_byte* h, nk_byte* s, nk_byte* v, nk_byte* a, nk_color); 379 | void nk_color_hsva_iv(int* hsva_out, nk_color); 380 | void nk_color_hsva_bv(nk_byte* hsva_out, nk_color); 381 | void nk_color_hsva_f(float* out_h, float* out_s, float* out_v, float* out_a, nk_color); 382 | void nk_color_hsva_fv(float* hsva_out, nk_color); 383 | nk_handle nk_handle_ptr(void*); 384 | nk_handle nk_handle_id(int); 385 | nk_image nk_image_handle(nk_handle); 386 | nk_image nk_image_ptr(void*); 387 | nk_image nk_image_id(int); 388 | bool nk_image_is_subimage(const(nk_image)* img); 389 | nk_image nk_subimage_ptr(void*, ushort w, ushort h, nk_rect sub_region); 390 | nk_image nk_subimage_id(int, ushort w, ushort h, nk_rect sub_region); 391 | nk_image nk_subimage_handle(nk_handle, ushort w, ushort h, nk_rect sub_region); 392 | //slice here 393 | 394 | 395 | nk_nine_slice nk_nine_slice_handle(nk_handle, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); 396 | nk_nine_slice nk_nine_slice_ptr(void*, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); 397 | nk_nine_slice nk_nine_slice_id(int, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); 398 | int nk_nine_slice_is_sub9slice(const(nk_nine_slice)* img); 399 | nk_nine_slice nk_sub9slice_ptr(void*, nk_ushort w, nk_ushort h, nk_rect sub_region, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); 400 | nk_nine_slice nk_sub9slice_id(int, nk_ushort w, nk_ushort h, nk_rect sub_region, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); 401 | nk_nine_slice nk_sub9slice_handle(nk_handle, nk_ushort w, nk_ushort h, nk_rect sub_region, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); 402 | 403 | nk_hash nk_murmur_hash(const(void)* key, int len, nk_hash seed); 404 | void nk_triangle_from_direction(nk_vec2* result, nk_rect r, float pad_x, float pad_y, nk_heading); 405 | pragma(mangle, "nk_vec2") 406 | nk_vec2 nk_vec2_(float x, float y); 407 | pragma(mangle, "nk_vec2i") 408 | nk_vec2 nk_vec2i_(int x, int y); 409 | nk_vec2 nk_vec2v(const(float)* xy); 410 | nk_vec2 nk_vec2iv(const(int)* xy); 411 | nk_rect nk_get_null_rect(); 412 | pragma(mangle, "nk_rect") 413 | nk_rect nk_rect_(float x, float y, float w, float h); 414 | nk_rect nk_recti(int x, int y, int w, int h); 415 | nk_rect nk_recta(nk_vec2 pos, nk_vec2 size); 416 | nk_rect nk_rectv(const(float)* xywh); 417 | nk_rect nk_rectiv(const(int)* xywh); 418 | nk_vec2 nk_rect_pos(nk_rect); 419 | nk_vec2 nk_rect_size(nk_rect); 420 | int nk_strlen(const(char)* str); 421 | int nk_stricmp(const(char)* s1, const(char)* s2); 422 | int nk_stricmpn(const(char)* s1, const(char)* s2, int n); 423 | int nk_strtoi(const(char)* str, const(char)** endptr); 424 | float nk_strtof(const(char)* str, const(char)** endptr); 425 | double nk_strtod(const(char)* str, const(char)** endptr); 426 | int nk_strfilter(const(char)* text, const(char)* regexp); 427 | int nk_strmatch_fuzzy_string(const(char)* str, const(char)* pattern, int* out_score); 428 | int nk_strmatch_fuzzy_text(const(char)* txt, int txt_len, const(char)* pattern, int* out_score); 429 | int nk_utf_decode(const(char)*, nk_rune*, int); 430 | int nk_utf_encode(nk_rune, char*, int); 431 | int nk_utf_len(const(char)*, int byte_len); 432 | const(char)* nk_utf_at(const(char)* buffer, int length, int index, nk_rune* unicode, int* len); 433 | version(NK_INCLUDE_FONT_BAKING) { 434 | const(nk_rune)* nk_font_default_glyph_ranges(); 435 | const(nk_rune)* nk_font_chinese_glyph_ranges(); 436 | const(nk_rune)* nk_font_cyrillic_glyph_ranges(); 437 | const(nk_rune)* nk_font_korean_glyph_ranges(); 438 | version(NK_INCLUDE_DEFAULT_ALLOCATOR) { 439 | void nk_font_atlas_init_default(nk_font_atlas*); 440 | } 441 | void nk_font_atlas_init(nk_font_atlas*, nk_allocator*); 442 | void nk_font_atlas_init_custom(nk_font_atlas*, nk_allocator* persistent, nk_allocator* transient); 443 | void nk_font_atlas_begin(nk_font_atlas*); 444 | pragma(mangle, "nk_font_config") 445 | nk_font_config nk_font_config_(float pixel_height); 446 | nk_font* nk_font_atlas_add(nk_font_atlas*, const(nk_font_config)*); 447 | version(NK_INCLUDE_DEFAULT_FONT) { 448 | nk_font* nk_font_atlas_add_default(nk_font_atlas*, float height, const(nk_font_config)*); 449 | } 450 | nk_font* nk_font_atlas_add_from_memory(nk_font_atlas* atlas, void* memory, nk_size size, float height, const(nk_font_config)* config); 451 | version(NK_INCLUDE_STANDARD_IO) { 452 | nk_font* nk_font_atlas_add_from_file(nk_font_atlas* atlas, const(char)* file_path, float height, const(nk_font_config)*); 453 | } 454 | nk_font* nk_font_atlas_add_compressed(nk_font_atlas*, void* memory, nk_size size, float height, const(nk_font_config)*); 455 | nk_font* nk_font_atlas_add_compressed_base85(nk_font_atlas*, const(char)* data, float height, const(nk_font_config)* config); 456 | const(void)* nk_font_atlas_bake(nk_font_atlas*, int* width, int* height, nk_font_atlas_format); 457 | void nk_font_atlas_end(nk_font_atlas*, nk_handle tex, nk_draw_null_texture*); 458 | const(nk_font_glyph)* nk_font_find_glyph(nk_font*, nk_rune unicode); 459 | void nk_font_atlas_cleanup(nk_font_atlas* atlas); 460 | void nk_font_atlas_clear(nk_font_atlas*); 461 | } 462 | version(NK_INCLUDE_DEFAULT_ALLOCATOR) { 463 | void nk_buffer_init_default(nk_buffer*); 464 | } 465 | void nk_buffer_init(nk_buffer*, const(nk_allocator)*, nk_size size); 466 | void nk_buffer_init_fixed(nk_buffer*, void* memory, nk_size size); 467 | void nk_buffer_info(nk_memory_status*, nk_buffer*); 468 | void nk_buffer_push(nk_buffer*, nk_buffer_allocation_type type, const(void)* memory, nk_size size, nk_size align_); 469 | void nk_buffer_mark(nk_buffer*, nk_buffer_allocation_type type); 470 | void nk_buffer_reset(nk_buffer*, nk_buffer_allocation_type type); 471 | void nk_buffer_clear(nk_buffer*); 472 | void nk_buffer_free(nk_buffer*); 473 | void* nk_buffer_memory(nk_buffer*); 474 | const(void)* nk_buffer_memory_const(const(nk_buffer)*); 475 | nk_size nk_buffer_total(nk_buffer*); 476 | version(NK_INCLUDE_DEFAULT_ALLOCATOR) { 477 | void nk_str_init_default(nk_str*); 478 | } 479 | void nk_str_init(nk_str*, const(nk_allocator)*, nk_size size); 480 | void nk_str_init_fixed(nk_str*, void* memory, nk_size size); 481 | void nk_str_clear(nk_str*); 482 | void nk_str_free(nk_str*); 483 | int nk_str_append_text_char(nk_str*, const(char)*, int); 484 | int nk_str_append_str_char(nk_str*, const(char)*); 485 | int nk_str_append_text_utf8(nk_str*, const(char)*, int); 486 | int nk_str_append_str_utf8(nk_str*, const(char)*); 487 | int nk_str_append_text_runes(nk_str*, const(nk_rune)*, int); 488 | int nk_str_append_str_runes(nk_str*, const(nk_rune)*); 489 | int nk_str_insert_at_char(nk_str*, int pos, const(char)*, int); 490 | int nk_str_insert_at_rune(nk_str*, int pos, const(char)*, int); 491 | int nk_str_insert_text_char(nk_str*, int pos, const(char)*, int); 492 | int nk_str_insert_str_char(nk_str*, int pos, const(char)*); 493 | int nk_str_insert_text_utf8(nk_str*, int pos, const(char)*, int); 494 | int nk_str_insert_str_utf8(nk_str*, int pos, const(char)*); 495 | int nk_str_insert_text_runes(nk_str*, int pos, const(nk_rune)*, int); 496 | int nk_str_insert_str_runes(nk_str*, int pos, const(nk_rune)*); 497 | void nk_str_remove_chars(nk_str*, int len); 498 | void nk_str_remove_runes(nk_str* str, int len); 499 | void nk_str_delete_chars(nk_str*, int pos, int len); 500 | void nk_str_delete_runes(nk_str*, int pos, int len); 501 | char* nk_str_at_char(nk_str*, int pos); 502 | char* nk_str_at_rune(nk_str*, int pos, nk_rune* unicode, int* len); 503 | nk_rune nk_str_rune_at(const(nk_str)*, int pos); 504 | const(char)* nk_str_at_char_const(const(nk_str)*, int pos); 505 | const(char)* nk_str_at_const(const(nk_str)*, int pos, nk_rune* unicode, int* len); 506 | char* nk_str_get(nk_str*); 507 | const(char)* nk_str_get_const(const(nk_str)*); 508 | int nk_str_len(nk_str*); 509 | int nk_str_len_char(nk_str*); 510 | bool nk_filter_default(const(nk_text_edit)*, nk_rune unicode); 511 | bool nk_filter_ascii(const(nk_text_edit)*, nk_rune unicode); 512 | bool nk_filter_float(const(nk_text_edit)*, nk_rune unicode); 513 | bool nk_filter_decimal(const(nk_text_edit)*, nk_rune unicode); 514 | bool nk_filter_hex(const(nk_text_edit)*, nk_rune unicode); 515 | bool nk_filter_oct(const(nk_text_edit)*, nk_rune unicode); 516 | bool nk_filter_binary(const(nk_text_edit)*, nk_rune unicode); 517 | 518 | auto nk_filter_default_fptr = &nk_filter_default; 519 | auto nk_filter_ascii_fptr = &nk_filter_ascii; 520 | auto nk_filter_float_fptr = &nk_filter_float; 521 | auto nk_filter_decimal_fptr = &nk_filter_decimal; 522 | auto nk_filter_hex_fptr = &nk_filter_hex; 523 | auto nk_filter_oct_fptr = &nk_filter_oct; 524 | auto nk_filter_binary_fptr = &nk_filter_binary; 525 | 526 | version(NK_INCLUDE_DEFAULT_ALLOCATOR) { 527 | void nk_textedit_init_default(nk_text_edit*); 528 | } 529 | void nk_textedit_init(nk_text_edit*, nk_allocator*, nk_size size); 530 | void nk_textedit_init_fixed(nk_text_edit*, void* memory, nk_size size); 531 | void nk_textedit_free(nk_text_edit*); 532 | void nk_textedit_text(nk_text_edit*, const(char)*, int total_len); 533 | void nk_textedit_delete(nk_text_edit*, int where, int len); 534 | void nk_textedit_delete_selection(nk_text_edit*); 535 | void nk_textedit_select_all(nk_text_edit*); 536 | bool nk_textedit_cut(nk_text_edit*); 537 | bool nk_textedit_paste(nk_text_edit*, const(char)*, int len); 538 | void nk_textedit_undo(nk_text_edit*); 539 | void nk_textedit_redo(nk_text_edit*); 540 | void nk_stroke_line(nk_command_buffer* b, float x0, float y0, float x1, float y1, float line_thickness, nk_color); 541 | void nk_stroke_curve(nk_command_buffer*, float, float, float, float, float, float, float, float, float line_thickness, nk_color); 542 | void nk_stroke_rect(nk_command_buffer*, nk_rect, float rounding, float line_thickness, nk_color); 543 | void nk_stroke_circle(nk_command_buffer*, nk_rect, float line_thickness, nk_color); 544 | void nk_stroke_arc(nk_command_buffer*, float cx, float cy, float radius, float a_min, float a_max, float line_thickness, nk_color); 545 | void nk_stroke_triangle(nk_command_buffer*, float, float, float, float, float, float, float line_thichness, nk_color); 546 | void nk_stroke_polyline(nk_command_buffer*, float* points, int point_count, float line_thickness, nk_color col); 547 | void nk_stroke_polygon(nk_command_buffer*, float*, int point_count, float line_thickness, nk_color); 548 | void nk_fill_rect(nk_command_buffer*, nk_rect, float rounding, nk_color); 549 | void nk_fill_rect_multi_color(nk_command_buffer*, nk_rect, nk_color left, nk_color top, nk_color right, nk_color bottom); 550 | void nk_fill_circle(nk_command_buffer*, nk_rect, nk_color); 551 | void nk_fill_arc(nk_command_buffer*, float cx, float cy, float radius, float a_min, float a_max, nk_color); 552 | void nk_fill_triangle(nk_command_buffer*, float x0, float y0, float x1, float y1, float x2, float y2, nk_color); 553 | void nk_fill_polygon(nk_command_buffer*, float*, int point_count, nk_color); 554 | void nk_draw_image(nk_command_buffer*, nk_rect, const(nk_image)*, nk_color); 555 | void nk_draw_text(nk_command_buffer*, nk_rect, const(char)* text, int len, const(nk_user_font)*, nk_color, nk_color); 556 | void nk_push_scissor(nk_command_buffer*, nk_rect); 557 | void nk_push_custom(nk_command_buffer*, nk_rect, nk_command_custom_callback, nk_handle usr); 558 | bool nk_input_has_mouse_click(const(nk_input)*, nk_buttons); 559 | bool nk_input_has_mouse_click_in_rect(const(nk_input)*, nk_buttons, nk_rect); 560 | bool nk_input_has_mouse_click_in_button_rect(const(nk_input)*, nk_buttons, nk_rect); 561 | bool nk_input_has_mouse_click_down_in_rect(const(nk_input)*, nk_buttons, nk_rect, bool down); 562 | bool nk_input_is_mouse_click_in_rect(const(nk_input)*, nk_buttons, nk_rect); 563 | bool nk_input_is_mouse_click_down_in_rect(const(nk_input)* i, nk_buttons id, nk_rect b, bool down); 564 | bool nk_input_any_mouse_click_in_rect(const(nk_input)*, nk_rect); 565 | bool nk_input_is_mouse_prev_hovering_rect(const(nk_input)*, nk_rect); 566 | bool nk_input_is_mouse_hovering_rect(const(nk_input)*, nk_rect); 567 | bool nk_input_mouse_clicked(const(nk_input)*, nk_buttons, nk_rect); 568 | bool nk_input_is_mouse_down(const(nk_input)*, nk_buttons); 569 | bool nk_input_is_mouse_pressed(const(nk_input)*, nk_buttons); 570 | bool nk_input_is_mouse_released(const(nk_input)*, nk_buttons); 571 | bool nk_input_is_key_pressed(const(nk_input)*, nk_keys); 572 | bool nk_input_is_key_released(const(nk_input)*, nk_keys); 573 | bool nk_input_is_key_down(const(nk_input)*, nk_keys); 574 | version(NK_INCLUDE_VERTEX_BUFFER_OUTPUT) { 575 | void nk_draw_list_init(nk_draw_list*); 576 | void nk_draw_list_setup(nk_draw_list*, const(nk_convert_config)*, nk_buffer* cmds, nk_buffer* vertices, nk_buffer* elements, nk_anti_aliasing line_aa, nk_anti_aliasing shape_aa); 577 | const(nk_draw_command)* nk__draw_list_begin(const(nk_draw_list)*, const(nk_buffer)*); 578 | const(nk_draw_command)* nk__draw_list_next(const(nk_draw_command)*, const(nk_buffer)*, const(nk_draw_list)*); 579 | const(nk_draw_command)* nk__draw_list_end(const(nk_draw_list)*, const(nk_buffer)*); 580 | void nk_draw_list_path_clear(nk_draw_list*); 581 | void nk_draw_list_path_line_to(nk_draw_list*, nk_vec2 pos); 582 | void nk_draw_list_path_arc_to_fast(nk_draw_list*, nk_vec2 center, float radius, int a_min, int a_max); 583 | void nk_draw_list_path_arc_to(nk_draw_list*, nk_vec2 center, float radius, float a_min, float a_max, uint segments); 584 | void nk_draw_list_path_rect_to(nk_draw_list*, nk_vec2 a, nk_vec2 b, float rounding); 585 | void nk_draw_list_path_curve_to(nk_draw_list*, nk_vec2 p2, nk_vec2 p3, nk_vec2 p4, uint num_segments); 586 | void nk_draw_list_path_fill(nk_draw_list*, nk_color); 587 | void nk_draw_list_path_stroke(nk_draw_list*, nk_color, nk_draw_list_stroke closed, float thickness); 588 | void nk_draw_list_stroke_line(nk_draw_list*, nk_vec2 a, nk_vec2 b, nk_color, float thickness); 589 | void nk_draw_list_stroke_rect(nk_draw_list*, nk_rect rect, nk_color, float rounding, float thickness); 590 | void nk_draw_list_stroke_triangle(nk_draw_list*, nk_vec2 a, nk_vec2 b, nk_vec2 c, nk_color, float thickness); 591 | void nk_draw_list_stroke_circle(nk_draw_list*, nk_vec2 center, float radius, nk_color, uint segs, float thickness); 592 | void nk_draw_list_stroke_curve(nk_draw_list*, nk_vec2 p0, nk_vec2 cp0, nk_vec2 cp1, nk_vec2 p1, nk_color, uint segments, float thickness); 593 | void nk_draw_list_stroke_poly_line(nk_draw_list*, const(nk_vec2)* pnts, const(uint) cnt, nk_color, nk_draw_list_stroke, float thickness, nk_anti_aliasing); 594 | void nk_draw_list_fill_rect(nk_draw_list*, nk_rect rect, nk_color, float rounding); 595 | void nk_draw_list_fill_rect_multi_color(nk_draw_list*, nk_rect rect, nk_color left, nk_color top, nk_color right, nk_color bottom); 596 | void nk_draw_list_fill_triangle(nk_draw_list*, nk_vec2 a, nk_vec2 b, nk_vec2 c, nk_color); 597 | void nk_draw_list_fill_circle(nk_draw_list*, nk_vec2 center, float radius, nk_color col, uint segs); 598 | void nk_draw_list_fill_poly_convex(nk_draw_list*, const(nk_vec2)* points, const(uint) count, nk_color, nk_anti_aliasing); 599 | void nk_draw_list_add_image(nk_draw_list*, nk_image texture, nk_rect rect, nk_color); 600 | void nk_draw_list_add_text(nk_draw_list*, const(nk_user_font)*, nk_rect, const(char)* text, int len, float font_height, nk_color); 601 | version(NK_INCLUDE_COMMAND_USERDATA) { 602 | void nk_draw_list_push_userdata(nk_draw_list*, nk_handle userdata); 603 | } 604 | } 605 | nk_style_item nk_style_item_image(nk_image img); 606 | nk_style_item nk_style_item_color(nk_color); 607 | nk_style_item nk_style_item_nine_slice(nk_nine_slice slice); 608 | nk_style_item nk_style_item_hide(); 609 | } 610 | -------------------------------------------------------------------------------- /source/bindbc/nuklear/macros.d: -------------------------------------------------------------------------------- 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 | } -------------------------------------------------------------------------------- /source/bindbc/nuklear/package.d: -------------------------------------------------------------------------------- 1 | 2 | // Copyright Mateusz Muszyński 2019. 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; 8 | 9 | public import bindbc.nuklear.types; 10 | public import bindbc.nuklear.macros; 11 | 12 | version(BindBC_Static) version = BindNuklear_Static; 13 | version(BindNuklear_Static) public import bindbc.nuklear.bindstatic; 14 | else public import bindbc.nuklear.binddynamic; --------------------------------------------------------------------------------