1 /* 2 /// # Nuklear 3 /// ![](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif) 4 /// 5 /// ## Contents 6 /// 1. About section 7 /// 2. Highlights section 8 /// 3. Features section 9 /// 4. Usage section 10 /// 1. Flags section 11 /// 2. Constants section 12 /// 3. Dependencies section 13 /// 5. Example section 14 /// 6. API section 15 /// 1. Context section 16 /// 2. Input section 17 /// 3. Drawing section 18 /// 4. Window section 19 /// 5. Layouting section 20 /// 6. Groups section 21 /// 7. Tree section 22 /// 8. Properties section 23 /// 7. License section 24 /// 8. Changelog section 25 /// 9. Gallery section 26 /// 10. Credits section 27 /// 28 /// ## About 29 /// This is a minimal state immediate mode graphical user interface toolkit 30 /// written in ANSI C and licensed under public domain. It was designed as a simple 31 /// embeddable user interface for application and does not have any dependencies, 32 /// a default renderbackend or OS window and input handling but instead provides a very modular 33 /// library approach by using simple input state for input and draw 34 /// commands describing primitive shapes as output. So instead of providing a 35 /// layered library that tries to abstract over a number of platform and 36 /// render backends it only focuses on the actual UI. 37 /// 38 /// ## Highlights 39 /// - Graphical user interface toolkit 40 /// - Single header library 41 /// - Written in C89 (a.k.a. ANSI C or ISO C90) 42 /// - Small codebase (~18kLOC) 43 /// - Focus on portability, efficiency and simplicity 44 /// - No dependencies (not even the standard library if not wanted) 45 /// - Fully skinnable and customizable 46 /// - Low memory footprint with total memory control if needed or wanted 47 /// - UTF-8 support 48 /// - No global or hidden state 49 /// - Customizable library modules (you can compile and use only what you need) 50 /// - Optional font baker and vertex buffer output 51 /// 52 /// ## Features 53 /// - Absolutely no platform dependent code 54 /// - Memory management control ranging from/to 55 /// - Ease of use by allocating everything from standard library 56 /// - Control every byte of memory inside the library 57 /// - Font handling control ranging from/to 58 /// - Use your own font implementation for everything 59 /// - Use this libraries internal font baking and handling API 60 /// - Drawing output control ranging from/to 61 /// - Simple shapes for more high level APIs which already have drawing capabilities 62 /// - Hardware accessible anti-aliased vertex buffer output 63 /// - Customizable colors and properties ranging from/to 64 /// - Simple changes to color by filling a simple color table 65 /// - Complete control with ability to use skinning to decorate widgets 66 /// - Bendable UI library with widget ranging from/to 67 /// - Basic widgets like buttons, checkboxes, slider, ... 68 /// - Advanced widget like abstract comboboxes, contextual menus,... 69 /// - Compile time configuration to only compile what you need 70 /// - Subset which can be used if you do not want to link or use the standard library 71 /// - Can be easily modified to only update on user input instead of frame updates 72 /// 73 /// ## Usage 74 /// This library is self contained in one single header file and can be used either 75 /// in header only mode or in implementation mode. The header only mode is used 76 /// by default when included and allows including this header in other headers 77 /// and does not contain the actual implementation. <br /><br /> 78 /// 79 /// The implementation mode requires to define the preprocessor macro 80 /// NK_IMPLEMENTATION in *one* .c/.cpp file before #including this file, e.g.: 81 /// 82 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C 83 /// #define NK_IMPLEMENTATION 84 /// #include "nuklear.h" 85 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 86 /// 87 /// Also optionally define the symbols listed in the section "OPTIONAL DEFINES" 88 /// below in header and implementation mode if you want to use additional functionality 89 /// or need more control over the library. 90 /// 91 /// !!! WARNING 92 /// Every time nuklear is included define the same compiler flags. This very important not doing so could lead to compiler errors or even worse stack corruptions. 93 /// 94 /// ### Flags 95 /// Flag | Description 96 /// --------------------------------|------------------------------------------ 97 /// NK_PRIVATE | If defined declares all functions as static, so they can only be accessed inside the file that contains the implementation 98 /// NK_INCLUDE_FIXED_TYPES | If defined it will include header `<stdint.h>` for fixed sized types otherwise nuklear tries to select the correct type. If that fails it will throw a compiler error and you have to select the correct types yourself. 99 /// NK_INCLUDE_DEFAULT_ALLOCATOR | If defined it will include header `<stdlib.h>` and provide additional functions to use this library without caring for memory allocation control and therefore ease memory management. 100 /// NK_INCLUDE_STANDARD_IO | If defined it will include header `<stdio.h>` and provide additional functions depending on file loading. 101 /// NK_INCLUDE_STANDARD_VARARGS | If defined it will include header <stdarg.h> and provide additional functions depending on file loading. 102 /// NK_INCLUDE_STANDARD_BOOL | If defined it will include header `<stdbool.h>` for nk_bool otherwise nuklear defines nk_bool as int. 103 /// NK_INCLUDE_VERTEX_BUFFER_OUTPUT | Defining this adds a vertex draw command list backend to this library, which allows you to convert queue commands into vertex draw commands. This is mainly if you need a hardware accessible format for OpenGL, DirectX, Vulkan, Metal,... 104 /// NK_INCLUDE_FONT_BAKING | Defining this adds `stb_truetype` and `stb_rect_pack` implementation to this library and provides font baking and rendering. If you already have font handling or do not want to use this font handler you don't have to define it. 105 /// NK_INCLUDE_DEFAULT_FONT | Defining this adds the default font: ProggyClean.ttf into this library which can be loaded into a font atlas and allows using this library without having a truetype font 106 /// NK_INCLUDE_COMMAND_USERDATA | Defining this adds a userdata pointer into each command. Can be useful for example if you want to provide custom shaders depending on the used widget. Can be combined with the style structures. 107 /// NK_BUTTON_TRIGGER_ON_RELEASE | Different platforms require button clicks occurring either on buttons being pressed (up to down) or released (down to up). By default this library will react on buttons being pressed, but if you define this it will only trigger if a button is released. 108 /// NK_ZERO_COMMAND_MEMORY | Defining this will zero out memory for each drawing command added to a drawing queue (inside nk_command_buffer_push). Zeroing command memory is very useful for fast checking (using memcmp) if command buffers are equal and avoid drawing frames when nothing on screen has changed since previous frame. 109 /// NK_UINT_DRAW_INDEX | Defining this will set the size of vertex index elements when using NK_VERTEX_BUFFER_OUTPUT to 32bit instead of the default of 16bit 110 /// NK_KEYSTATE_BASED_INPUT | Define this if your backend uses key state for each frame rather than key press/release events 111 /// 112 /// !!! WARNING 113 /// The following flags will pull in the standard C library: 114 /// - NK_INCLUDE_DEFAULT_ALLOCATOR 115 /// - NK_INCLUDE_STANDARD_IO 116 /// - NK_INCLUDE_STANDARD_VARARGS 117 /// 118 /// !!! WARNING 119 /// The following flags if defined need to be defined for both header and implementation: 120 /// - NK_INCLUDE_FIXED_TYPES 121 /// - NK_INCLUDE_DEFAULT_ALLOCATOR 122 /// - NK_INCLUDE_STANDARD_VARARGS 123 /// - NK_INCLUDE_STANDARD_BOOL 124 /// - NK_INCLUDE_VERTEX_BUFFER_OUTPUT 125 /// - NK_INCLUDE_FONT_BAKING 126 /// - NK_INCLUDE_DEFAULT_FONT 127 /// - NK_INCLUDE_STANDARD_VARARGS 128 /// - NK_INCLUDE_COMMAND_USERDATA 129 /// - NK_UINT_DRAW_INDEX 130 /// 131 /// ### Constants 132 /// Define | Description 133 /// --------------------------------|--------------------------------------- 134 /// NK_BUFFER_DEFAULT_INITIAL_SIZE | Initial buffer size allocated by all buffers while using the default allocator functions included by defining NK_INCLUDE_DEFAULT_ALLOCATOR. If you don't want to allocate the default 4k memory then redefine it. 135 /// NK_MAX_NUMBER_BUFFER | Maximum buffer size for the conversion buffer between float and string Under normal circumstances this should be more than sufficient. 136 /// NK_INPUT_MAX | Defines the max number of bytes which can be added as text input in one frame. Under normal circumstances this should be more than sufficient. 137 /// 138 /// !!! WARNING 139 /// The following constants if defined need to be defined for both header and implementation: 140 /// - NK_MAX_NUMBER_BUFFER 141 /// - NK_BUFFER_DEFAULT_INITIAL_SIZE 142 /// - NK_INPUT_MAX 143 /// 144 /// ### Dependencies 145 /// Function | Description 146 /// ------------|--------------------------------------------------------------- 147 /// NK_ASSERT | If you don't define this, nuklear will use <assert.h> with assert(). 148 /// NK_MEMSET | You can define this to 'memset' or your own memset implementation replacement. If not nuklear will use its own version. 149 /// NK_MEMCPY | You can define this to 'memcpy' or your own memcpy implementation replacement. If not nuklear will use its own version. 150 /// NK_INV_SQRT | You can define this to your own inverse sqrt implementation replacement. If not nuklear will use its own slow and not highly accurate version. 151 /// NK_SIN | You can define this to 'sinf' or your own sine implementation replacement. If not nuklear will use its own approximation implementation. 152 /// NK_COS | You can define this to 'cosf' or your own cosine implementation replacement. If not nuklear will use its own approximation implementation. 153 /// NK_STRTOD | You can define this to `strtod` or your own string to double conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!). 154 /// NK_DTOA | You can define this to `dtoa` or your own double to string conversion implementation replacement. If not defined nuklear will use its own imprecise and possibly unsafe version (does not handle nan or infinity!). 155 /// NK_VSNPRINTF| If you define `NK_INCLUDE_STANDARD_VARARGS` as well as `NK_INCLUDE_STANDARD_IO` and want to be safe define this to `vsnprintf` on compilers supporting later versions of C or C++. By default nuklear will check for your stdlib version in C as well as compiler version in C++. if `vsnprintf` is available it will define it to `vsnprintf` directly. If not defined and if you have older versions of C or C++ it will be defined to `vsprintf` which is unsafe. 156 /// 157 /// !!! WARNING 158 /// The following dependencies will pull in the standard C library if not redefined: 159 /// - NK_ASSERT 160 /// 161 /// !!! WARNING 162 /// The following dependencies if defined need to be defined for both header and implementation: 163 /// - NK_ASSERT 164 /// 165 /// !!! WARNING 166 /// The following dependencies if defined need to be defined only for the implementation part: 167 /// - NK_MEMSET 168 /// - NK_MEMCPY 169 /// - NK_SQRT 170 /// - NK_SIN 171 /// - NK_COS 172 /// - NK_STRTOD 173 /// - NK_DTOA 174 /// - NK_VSNPRINTF 175 /// 176 /// ## Example 177 /// 178 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 179 /// // init gui state 180 /// enum {EASY, HARD}; 181 /// static int op = EASY; 182 /// static float value = 0.6f; 183 /// static int i = 20; 184 /// struct nk_context ctx; 185 /// 186 /// nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font); 187 /// if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220), 188 /// NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) { 189 /// // fixed widget pixel width 190 /// nk_layout_row_static(&ctx, 30, 80, 1); 191 /// if (nk_button_label(&ctx, "button")) { 192 /// // event handling 193 /// } 194 /// 195 /// // fixed widget window ratio width 196 /// nk_layout_row_dynamic(&ctx, 30, 2); 197 /// if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY; 198 /// if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD; 199 /// 200 /// // custom widget pixel width 201 /// nk_layout_row_begin(&ctx, NK_STATIC, 30, 2); 202 /// { 203 /// nk_layout_row_push(&ctx, 50); 204 /// nk_label(&ctx, "Volume:", NK_TEXT_LEFT); 205 /// nk_layout_row_push(&ctx, 110); 206 /// nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f); 207 /// } 208 /// nk_layout_row_end(&ctx); 209 /// } 210 /// nk_end(&ctx); 211 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 212 /// 213 /// ![](https://cloud.githubusercontent.com/assets/8057201/10187981/584ecd68-675c-11e5-897c-822ef534a876.png) 214 /// 215 /// ## API 216 /// 217 */ 218 219 module nuklear; 220 221 import core.stdc.config; 222 223 extern (C): 224 225 /* 226 * ============================================================== 227 * 228 * CONSTANTS 229 * 230 * =============================================================== 231 */ 232 enum NK_UNDEFINED = -1.0f; 233 enum NK_UTF_INVALID = 0xFFFD; /* internal invalid utf8 rune */ 234 enum NK_UTF_SIZE = 4; /* describes the number of bytes a glyph consists of*/ 235 236 enum NK_INPUT_MAX = 16; 237 238 enum NK_MAX_NUMBER_BUFFER = 64; 239 240 enum NK_SCROLLBAR_HIDING_TIMEOUT = 4.0f; 241 242 /* 243 * ============================================================== 244 * 245 * HELPER 246 * 247 * =============================================================== 248 */ 249 250 extern (D) auto NK_FLAG(T)(auto ref T x) 251 { 252 return 1 << x; 253 } 254 255 extern (D) string NK_STRINGIFY(T)(auto ref T x) 256 { 257 import std.conv : to; 258 259 return to!string(x); 260 } 261 262 alias NK_MACRO_STRINGIFY = NK_STRINGIFY; 263 264 extern (D) string NK_STRING_JOIN_IMMEDIATE(T0, T1)(auto ref T0 arg1, auto ref T1 arg2) 265 { 266 import std.conv : to; 267 268 return to!string(arg1) ~ to!string(arg2); 269 } 270 271 alias NK_STRING_JOIN_DELAY = NK_STRING_JOIN_IMMEDIATE; 272 alias NK_STRING_JOIN = NK_STRING_JOIN_DELAY; 273 274 extern (D) auto NK_UNIQUE_NAME(T)(auto ref T name) 275 { 276 return NK_STRING_JOIN(name, __LINE__); 277 } 278 279 extern (D) auto NK_MIN(T0, T1)(auto ref T0 a, auto ref T1 b) 280 { 281 return a < b ? a : b; 282 } 283 284 extern (D) auto NK_MAX(T0, T1)(auto ref T0 a, auto ref T1 b) 285 { 286 return a < b ? b : a; 287 } 288 289 extern (D) auto NK_CLAMP(T0, T1, T2)(auto ref T0 i, auto ref T1 v, auto ref T2 x) 290 { 291 return NK_MAX(NK_MIN(v, x), i); 292 } 293 294 /* VS 2010 and above */ 295 296 /* 297 * =============================================================== 298 * 299 * BASIC 300 * 301 * =============================================================== 302 */ 303 304 alias NK_INT8 = byte; 305 306 alias NK_UINT8 = ubyte; 307 308 alias NK_INT16 = short; 309 310 alias NK_UINT16 = ushort; 311 312 alias NK_INT32 = int; 313 314 alias NK_UINT32 = uint; 315 316 alias NK_SIZE_TYPE = c_ulong; 317 318 alias NK_POINTER_TYPE = c_ulong; 319 320 alias NK_BOOL = int; /* could be char, use int for drop-in replacement backwards compatibility */ 321 322 alias nk_char = byte; 323 alias nk_uchar = ubyte; 324 alias nk_byte = ubyte; 325 alias nk_short = short; 326 alias nk_ushort = ushort; 327 alias nk_int = int; 328 alias nk_uint = uint; 329 alias nk_size = c_ulong; 330 alias nk_ptr = c_ulong; 331 alias nk_bool = int; 332 333 alias nk_hash = uint; 334 alias nk_flags = uint; 335 alias nk_rune = uint; 336 337 /* Make sure correct type size: 338 * This will fire with a negative subscript error if the type sizes 339 * are set incorrectly by the compiler, and compile out if not */ 340 alias _dummy_array428 = char[1]; 341 alias _dummy_array429 = char[1]; 342 alias _dummy_array430 = char[1]; 343 alias _dummy_array431 = char[1]; 344 alias _dummy_array432 = char[1]; 345 alias _dummy_array433 = char[1]; 346 alias _dummy_array434 = char[1]; 347 alias _dummy_array435 = char[1]; 348 alias _dummy_array436 = char[1]; 349 350 alias _dummy_array440 = char[1]; 351 352 /* ============================================================================ 353 * 354 * API 355 * 356 * =========================================================================== */ 357 358 struct nk_draw_command; 359 360 struct nk_draw_list; 361 362 struct nk_draw_vertex_layout_element; 363 364 struct nk_style_slide; 365 366 enum 367 { 368 nk_false = 0, 369 nk_true = 1 370 } 371 372 struct nk_color 373 { 374 nk_byte r; 375 nk_byte g; 376 nk_byte b; 377 nk_byte a; 378 } 379 380 struct nk_colorf 381 { 382 float r; 383 float g; 384 float b; 385 float a; 386 } 387 388 struct nk_vec2_ 389 { 390 float x; 391 float y; 392 } 393 394 struct nk_vec2i_ 395 { 396 short x; 397 short y; 398 } 399 400 struct nk_rect_ 401 { 402 float x; 403 float y; 404 float w; 405 float h; 406 } 407 408 struct nk_recti_ 409 { 410 short x; 411 short y; 412 short w; 413 short h; 414 } 415 416 alias nk_glyph = char[NK_UTF_SIZE]; 417 418 union nk_handle 419 { 420 void* ptr; 421 int id; 422 } 423 424 struct nk_image_ 425 { 426 nk_handle handle; 427 nk_ushort w; 428 nk_ushort h; 429 nk_ushort[4] region; 430 } 431 432 struct nk_nine_slice 433 { 434 nk_image_ img; 435 nk_ushort l; 436 nk_ushort t; 437 nk_ushort r; 438 nk_ushort b; 439 } 440 441 struct nk_cursor 442 { 443 nk_image_ img; 444 nk_vec2_ size; 445 nk_vec2_ offset; 446 } 447 448 struct nk_scroll 449 { 450 nk_uint x; 451 nk_uint y; 452 } 453 454 enum nk_heading 455 { 456 NK_UP = 0, 457 NK_RIGHT = 1, 458 NK_DOWN = 2, 459 NK_LEFT = 3 460 } 461 462 enum nk_button_behavior 463 { 464 NK_BUTTON_DEFAULT = 0, 465 NK_BUTTON_REPEATER = 1 466 } 467 468 enum nk_modify 469 { 470 NK_FIXED = .nk_false, 471 NK_MODIFIABLE = .nk_true 472 } 473 474 enum nk_orientation 475 { 476 NK_VERTICAL = 0, 477 NK_HORIZONTAL = 1 478 } 479 480 enum nk_collapse_states 481 { 482 NK_MINIMIZED = .nk_false, 483 NK_MAXIMIZED = .nk_true 484 } 485 486 enum nk_show_states 487 { 488 NK_HIDDEN = .nk_false, 489 NK_SHOWN = .nk_true 490 } 491 492 enum nk_chart_type 493 { 494 NK_CHART_LINES = 0, 495 NK_CHART_COLUMN = 1, 496 NK_CHART_MAX = 2 497 } 498 499 enum nk_chart_event 500 { 501 NK_CHART_HOVERING = 0x01, 502 NK_CHART_CLICKED = 0x02 503 } 504 505 enum nk_color_format 506 { 507 NK_RGB = 0, 508 NK_RGBA = 1 509 } 510 511 enum nk_popup_type 512 { 513 NK_POPUP_STATIC = 0, 514 NK_POPUP_DYNAMIC = 1 515 } 516 517 enum nk_layout_format 518 { 519 NK_DYNAMIC = 0, 520 NK_STATIC = 1 521 } 522 523 enum nk_tree_type 524 { 525 NK_TREE_NODE = 0, 526 NK_TREE_TAB = 1 527 } 528 529 alias nk_plugin_alloc = void* function (nk_handle, void* old, nk_size); 530 alias nk_plugin_free = void function (nk_handle, void* old); 531 alias nk_plugin_filter = int function (const(nk_text_edit)*, nk_rune unicode); 532 alias nk_plugin_paste = void function (nk_handle, nk_text_edit*); 533 alias nk_plugin_copy = void function (nk_handle, const(char)*, int len); 534 535 struct nk_allocator 536 { 537 nk_handle userdata; 538 nk_plugin_alloc alloc; 539 nk_plugin_free free; 540 } 541 542 enum nk_symbol_type 543 { 544 NK_SYMBOL_NONE = 0, 545 NK_SYMBOL_X = 1, 546 NK_SYMBOL_UNDERSCORE = 2, 547 NK_SYMBOL_CIRCLE_SOLID = 3, 548 NK_SYMBOL_CIRCLE_OUTLINE = 4, 549 NK_SYMBOL_RECT_SOLID = 5, 550 NK_SYMBOL_RECT_OUTLINE = 6, 551 NK_SYMBOL_TRIANGLE_UP = 7, 552 NK_SYMBOL_TRIANGLE_DOWN = 8, 553 NK_SYMBOL_TRIANGLE_LEFT = 9, 554 NK_SYMBOL_TRIANGLE_RIGHT = 10, 555 NK_SYMBOL_PLUS = 11, 556 NK_SYMBOL_MINUS = 12, 557 NK_SYMBOL_MAX = 13 558 } 559 560 /* ============================================================================= 561 * 562 * CONTEXT 563 * 564 * =============================================================================*/ 565 /*/// ### Context 566 /// Contexts are the main entry point and the majestro of nuklear and contain all required state. 567 /// They are used for window, memory, input, style, stack, commands and time management and need 568 /// to be passed into all nuklear GUI specific functions. 569 /// 570 /// #### Usage 571 /// To use a context it first has to be initialized which can be achieved by calling 572 /// one of either `nk_init_default`, `nk_init_fixed`, `nk_init`, `nk_init_custom`. 573 /// Each takes in a font handle and a specific way of handling memory. Memory control 574 /// hereby ranges from standard library to just specifying a fixed sized block of memory 575 /// which nuklear has to manage itself from. 576 /// 577 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 578 /// struct nk_context ctx; 579 /// nk_init_xxx(&ctx, ...); 580 /// while (1) { 581 /// // [...] 582 /// nk_clear(&ctx); 583 /// } 584 /// nk_free(&ctx); 585 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 586 /// 587 /// #### Reference 588 /// Function | Description 589 /// --------------------|------------------------------------------------------- 590 /// __nk_init_default__ | Initializes context with standard library memory allocation (malloc,free) 591 /// __nk_init_fixed__ | Initializes context from single fixed size memory block 592 /// __nk_init__ | Initializes context with memory allocator callbacks for alloc and free 593 /// __nk_init_custom__ | Initializes context from two buffers. One for draw commands the other for window/panel/table allocations 594 /// __nk_clear__ | Called at the end of the frame to reset and prepare the context for the next frame 595 /// __nk_free__ | Shutdown and free all memory allocated inside the context 596 /// __nk_set_user_data__| Utility function to pass user data to draw command 597 */ 598 599 /*/// #### nk_init_default 600 /// Initializes a `nk_context` struct with a default standard library allocator. 601 /// Should be used if you don't want to be bothered with memory management in nuklear. 602 /// 603 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 604 /// nk_bool nk_init_default(struct nk_context *ctx, const struct nk_user_font *font); 605 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 606 /// 607 /// Parameter | Description 608 /// ------------|--------------------------------------------------------------- 609 /// __ctx__ | Must point to an either stack or heap allocated `nk_context` struct 610 /// __font__ | Must point to a previously initialized font handle for more info look at font documentation 611 /// 612 /// Returns either `false(0)` on failure or `true(1)` on success. 613 /// 614 */ 615 616 /*/// #### nk_init_fixed 617 /// Initializes a `nk_context` struct from single fixed size memory block 618 /// Should be used if you want complete control over nuklear's memory management. 619 /// Especially recommended for system with little memory or systems with virtual memory. 620 /// For the later case you can just allocate for example 16MB of virtual memory 621 /// and only the required amount of memory will actually be committed. 622 /// 623 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 624 /// nk_bool nk_init_fixed(struct nk_context *ctx, void *memory, nk_size size, const struct nk_user_font *font); 625 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 626 /// 627 /// !!! Warning 628 /// make sure the passed memory block is aligned correctly for `nk_draw_commands`. 629 /// 630 /// Parameter | Description 631 /// ------------|-------------------------------------------------------------- 632 /// __ctx__ | Must point to an either stack or heap allocated `nk_context` struct 633 /// __memory__ | Must point to a previously allocated memory block 634 /// __size__ | Must contain the total size of __memory__ 635 /// __font__ | Must point to a previously initialized font handle for more info look at font documentation 636 /// 637 /// Returns either `false(0)` on failure or `true(1)` on success. 638 */ 639 nk_bool nk_init_fixed (nk_context*, void* memory, nk_size size, const(nk_user_font)*); 640 /*/// #### nk_init 641 /// Initializes a `nk_context` struct with memory allocation callbacks for nuklear to allocate 642 /// memory from. Used internally for `nk_init_default` and provides a kitchen sink allocation 643 /// interface to nuklear. Can be useful for cases like monitoring memory consumption. 644 /// 645 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 646 /// nk_bool nk_init(struct nk_context *ctx, struct nk_allocator *alloc, const struct nk_user_font *font); 647 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 648 /// 649 /// Parameter | Description 650 /// ------------|--------------------------------------------------------------- 651 /// __ctx__ | Must point to an either stack or heap allocated `nk_context` struct 652 /// __alloc__ | Must point to a previously allocated memory allocator 653 /// __font__ | Must point to a previously initialized font handle for more info look at font documentation 654 /// 655 /// Returns either `false(0)` on failure or `true(1)` on success. 656 */ 657 nk_bool nk_init (nk_context*, nk_allocator*, const(nk_user_font)*); 658 /*/// #### nk_init_custom 659 /// Initializes a `nk_context` struct from two different either fixed or growing 660 /// buffers. The first buffer is for allocating draw commands while the second buffer is 661 /// used for allocating windows, panels and state tables. 662 /// 663 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 664 /// nk_bool nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font *font); 665 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 666 /// 667 /// Parameter | Description 668 /// ------------|--------------------------------------------------------------- 669 /// __ctx__ | Must point to an either stack or heap allocated `nk_context` struct 670 /// __cmds__ | Must point to a previously initialized memory buffer either fixed or dynamic to store draw commands into 671 /// __pool__ | Must point to a previously initialized memory buffer either fixed or dynamic to store windows, panels and tables 672 /// __font__ | Must point to a previously initialized font handle for more info look at font documentation 673 /// 674 /// Returns either `false(0)` on failure or `true(1)` on success. 675 */ 676 nk_bool nk_init_custom (nk_context*, nk_buffer* cmds, nk_buffer* pool, const(nk_user_font)*); 677 /*/// #### nk_clear 678 /// Resets the context state at the end of the frame. This includes mostly 679 /// garbage collector tasks like removing windows or table not called and therefore 680 /// used anymore. 681 /// 682 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 683 /// void nk_clear(struct nk_context *ctx); 684 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 685 /// 686 /// Parameter | Description 687 /// ------------|----------------------------------------------------------- 688 /// __ctx__ | Must point to a previously initialized `nk_context` struct 689 */ 690 void nk_clear (nk_context*); 691 /*/// #### nk_free 692 /// Frees all memory allocated by nuklear. Not needed if context was 693 /// initialized with `nk_init_fixed`. 694 /// 695 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 696 /// void nk_free(struct nk_context *ctx); 697 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 698 /// 699 /// Parameter | Description 700 /// ------------|----------------------------------------------------------- 701 /// __ctx__ | Must point to a previously initialized `nk_context` struct 702 */ 703 void nk_free (nk_context*); 704 705 /*/// #### nk_set_user_data 706 /// Sets the currently passed userdata passed down into each draw command. 707 /// 708 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 709 /// void nk_set_user_data(struct nk_context *ctx, nk_handle data); 710 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 711 /// 712 /// Parameter | Description 713 /// ------------|-------------------------------------------------------------- 714 /// __ctx__ | Must point to a previously initialized `nk_context` struct 715 /// __data__ | Handle with either pointer or index to be passed into every draw commands 716 */ 717 718 /* ============================================================================= 719 * 720 * INPUT 721 * 722 * =============================================================================*/ 723 /*/// ### Input 724 /// The input API is responsible for holding the current input state composed of 725 /// mouse, key and text input states. 726 /// It is worth noting that no direct OS or window handling is done in nuklear. 727 /// Instead all input state has to be provided by platform specific code. This on one hand 728 /// expects more work from the user and complicates usage but on the other hand 729 /// provides simple abstraction over a big number of platforms, libraries and other 730 /// already provided functionality. 731 /// 732 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 733 /// nk_input_begin(&ctx); 734 /// while (GetEvent(&evt)) { 735 /// if (evt.type == MOUSE_MOVE) 736 /// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); 737 /// else if (evt.type == [...]) { 738 /// // [...] 739 /// } 740 /// } nk_input_end(&ctx); 741 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 742 /// 743 /// #### Usage 744 /// Input state needs to be provided to nuklear by first calling `nk_input_begin` 745 /// which resets internal state like delta mouse position and button transitions. 746 /// After `nk_input_begin` all current input state needs to be provided. This includes 747 /// mouse motion, button and key pressed and released, text input and scrolling. 748 /// Both event- or state-based input handling are supported by this API 749 /// and should work without problems. Finally after all input state has been 750 /// mirrored `nk_input_end` needs to be called to finish input process. 751 /// 752 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 753 /// struct nk_context ctx; 754 /// nk_init_xxx(&ctx, ...); 755 /// while (1) { 756 /// Event evt; 757 /// nk_input_begin(&ctx); 758 /// while (GetEvent(&evt)) { 759 /// if (evt.type == MOUSE_MOVE) 760 /// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); 761 /// else if (evt.type == [...]) { 762 /// // [...] 763 /// } 764 /// } 765 /// nk_input_end(&ctx); 766 /// // [...] 767 /// nk_clear(&ctx); 768 /// } nk_free(&ctx); 769 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 770 /// 771 /// #### Reference 772 /// Function | Description 773 /// --------------------|------------------------------------------------------- 774 /// __nk_input_begin__ | Begins the input mirroring process. Needs to be called before all other `nk_input_xxx` calls 775 /// __nk_input_motion__ | Mirrors mouse cursor position 776 /// __nk_input_key__ | Mirrors key state with either pressed or released 777 /// __nk_input_button__ | Mirrors mouse button state with either pressed or released 778 /// __nk_input_scroll__ | Mirrors mouse scroll values 779 /// __nk_input_char__ | Adds a single ASCII text character into an internal text buffer 780 /// __nk_input_glyph__ | Adds a single multi-byte UTF-8 character into an internal text buffer 781 /// __nk_input_unicode__| Adds a single unicode rune into an internal text buffer 782 /// __nk_input_end__ | Ends the input mirroring process by calculating state changes. Don't call any `nk_input_xxx` function referenced above after this call 783 */ 784 enum nk_keys 785 { 786 NK_KEY_NONE = 0, 787 NK_KEY_SHIFT = 1, 788 NK_KEY_CTRL = 2, 789 NK_KEY_DEL = 3, 790 NK_KEY_ENTER = 4, 791 NK_KEY_TAB = 5, 792 NK_KEY_BACKSPACE = 6, 793 NK_KEY_COPY = 7, 794 NK_KEY_CUT = 8, 795 NK_KEY_PASTE = 9, 796 NK_KEY_UP = 10, 797 NK_KEY_DOWN = 11, 798 NK_KEY_LEFT = 12, 799 NK_KEY_RIGHT = 13, 800 /* Shortcuts: text field */ 801 NK_KEY_TEXT_INSERT_MODE = 14, 802 NK_KEY_TEXT_REPLACE_MODE = 15, 803 NK_KEY_TEXT_RESET_MODE = 16, 804 NK_KEY_TEXT_LINE_START = 17, 805 NK_KEY_TEXT_LINE_END = 18, 806 NK_KEY_TEXT_START = 19, 807 NK_KEY_TEXT_END = 20, 808 NK_KEY_TEXT_UNDO = 21, 809 NK_KEY_TEXT_REDO = 22, 810 NK_KEY_TEXT_SELECT_ALL = 23, 811 NK_KEY_TEXT_WORD_LEFT = 24, 812 NK_KEY_TEXT_WORD_RIGHT = 25, 813 /* Shortcuts: scrollbar */ 814 NK_KEY_SCROLL_START = 26, 815 NK_KEY_SCROLL_END = 27, 816 NK_KEY_SCROLL_DOWN = 28, 817 NK_KEY_SCROLL_UP = 29, 818 NK_KEY_MAX = 30 819 } 820 821 enum nk_buttons 822 { 823 NK_BUTTON_LEFT = 0, 824 NK_BUTTON_MIDDLE = 1, 825 NK_BUTTON_RIGHT = 2, 826 NK_BUTTON_DOUBLE = 3, 827 NK_BUTTON_MAX = 4 828 } 829 830 /*/// #### nk_input_begin 831 /// Begins the input mirroring process by resetting text, scroll 832 /// mouse, previous mouse position and movement as well as key state transitions, 833 /// 834 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 835 /// void nk_input_begin(struct nk_context*); 836 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 837 /// 838 /// Parameter | Description 839 /// ------------|----------------------------------------------------------- 840 /// __ctx__ | Must point to a previously initialized `nk_context` struct 841 */ 842 void nk_input_begin (nk_context*); 843 /*/// #### nk_input_motion 844 /// Mirrors current mouse position to nuklear 845 /// 846 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 847 /// void nk_input_motion(struct nk_context *ctx, int x, int y); 848 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 849 /// 850 /// Parameter | Description 851 /// ------------|----------------------------------------------------------- 852 /// __ctx__ | Must point to a previously initialized `nk_context` struct 853 /// __x__ | Must hold an integer describing the current mouse cursor x-position 854 /// __y__ | Must hold an integer describing the current mouse cursor y-position 855 */ 856 void nk_input_motion (nk_context*, int x, int y); 857 /*/// #### nk_input_key 858 /// Mirrors the state of a specific key to nuklear 859 /// 860 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 861 /// void nk_input_key(struct nk_context*, enum nk_keys key, nk_bool down); 862 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 863 /// 864 /// Parameter | Description 865 /// ------------|----------------------------------------------------------- 866 /// __ctx__ | Must point to a previously initialized `nk_context` struct 867 /// __key__ | Must be any value specified in enum `nk_keys` that needs to be mirrored 868 /// __down__ | Must be 0 for key is up and 1 for key is down 869 */ 870 void nk_input_key (nk_context*, nk_keys, nk_bool down); 871 /*/// #### nk_input_button 872 /// Mirrors the state of a specific mouse button to nuklear 873 /// 874 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 875 /// void nk_input_button(struct nk_context *ctx, enum nk_buttons btn, int x, int y, nk_bool down); 876 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 877 /// 878 /// Parameter | Description 879 /// ------------|----------------------------------------------------------- 880 /// __ctx__ | Must point to a previously initialized `nk_context` struct 881 /// __btn__ | Must be any value specified in enum `nk_buttons` that needs to be mirrored 882 /// __x__ | Must contain an integer describing mouse cursor x-position on click up/down 883 /// __y__ | Must contain an integer describing mouse cursor y-position on click up/down 884 /// __down__ | Must be 0 for key is up and 1 for key is down 885 */ 886 void nk_input_button (nk_context*, nk_buttons, int x, int y, nk_bool down); 887 /*/// #### nk_input_scroll 888 /// Copies the last mouse scroll value to nuklear. Is generally 889 /// a scroll value. So does not have to come from mouse and could also originate 890 /// TODO finish this sentence 891 /// 892 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 893 /// void nk_input_scroll(struct nk_context *ctx, struct nk_vec2 val); 894 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 895 /// 896 /// Parameter | Description 897 /// ------------|----------------------------------------------------------- 898 /// __ctx__ | Must point to a previously initialized `nk_context` struct 899 /// __val__ | vector with both X- as well as Y-scroll value 900 */ 901 void nk_input_scroll (nk_context*, nk_vec2_ val); 902 /*/// #### nk_input_char 903 /// Copies a single ASCII character into an internal text buffer 904 /// This is basically a helper function to quickly push ASCII characters into 905 /// nuklear. 906 /// 907 /// !!! Note 908 /// Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`. 909 /// 910 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 911 /// void nk_input_char(struct nk_context *ctx, char c); 912 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 913 /// 914 /// Parameter | Description 915 /// ------------|----------------------------------------------------------- 916 /// __ctx__ | Must point to a previously initialized `nk_context` struct 917 /// __c__ | Must be a single ASCII character preferable one that can be printed 918 */ 919 void nk_input_char (nk_context*, char); 920 /*/// #### nk_input_glyph 921 /// Converts an encoded unicode rune into UTF-8 and copies the result into an 922 /// internal text buffer. 923 /// 924 /// !!! Note 925 /// Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`. 926 /// 927 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 928 /// void nk_input_glyph(struct nk_context *ctx, const nk_glyph g); 929 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 930 /// 931 /// Parameter | Description 932 /// ------------|----------------------------------------------------------- 933 /// __ctx__ | Must point to a previously initialized `nk_context` struct 934 /// __g__ | UTF-32 unicode codepoint 935 */ 936 void nk_input_glyph (nk_context*, const nk_glyph); 937 /*/// #### nk_input_unicode 938 /// Converts a unicode rune into UTF-8 and copies the result 939 /// into an internal text buffer. 940 /// !!! Note 941 /// Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`. 942 /// 943 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 944 /// void nk_input_unicode(struct nk_context*, nk_rune rune); 945 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 946 /// 947 /// Parameter | Description 948 /// ------------|----------------------------------------------------------- 949 /// __ctx__ | Must point to a previously initialized `nk_context` struct 950 /// __rune__ | UTF-32 unicode codepoint 951 */ 952 void nk_input_unicode (nk_context*, nk_rune); 953 /*/// #### nk_input_end 954 /// End the input mirroring process by resetting mouse grabbing 955 /// state to ensure the mouse cursor is not grabbed indefinitely. 956 /// 957 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 958 /// void nk_input_end(struct nk_context *ctx); 959 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 960 /// 961 /// Parameter | Description 962 /// ------------|----------------------------------------------------------- 963 /// __ctx__ | Must point to a previously initialized `nk_context` struct 964 */ 965 void nk_input_end (nk_context*); 966 /* ============================================================================= 967 * 968 * DRAWING 969 * 970 * =============================================================================*/ 971 /*/// ### Drawing 972 /// This library was designed to be render backend agnostic so it does 973 /// not draw anything to screen directly. Instead all drawn shapes, widgets 974 /// are made of, are buffered into memory and make up a command queue. 975 /// Each frame therefore fills the command buffer with draw commands 976 /// that then need to be executed by the user and his own render backend. 977 /// After that the command buffer needs to be cleared and a new frame can be 978 /// started. It is probably important to note that the command buffer is the main 979 /// drawing API and the optional vertex buffer API only takes this format and 980 /// converts it into a hardware accessible format. 981 /// 982 /// #### Usage 983 /// To draw all draw commands accumulated over a frame you need your own render 984 /// backend able to draw a number of 2D primitives. This includes at least 985 /// filled and stroked rectangles, circles, text, lines, triangles and scissors. 986 /// As soon as this criterion is met you can iterate over each draw command 987 /// and execute each draw command in a interpreter like fashion: 988 /// 989 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 990 /// const struct nk_command *cmd = 0; 991 /// nk_foreach(cmd, &ctx) { 992 /// switch (cmd->type) { 993 /// case NK_COMMAND_LINE: 994 /// your_draw_line_function(...) 995 /// break; 996 /// case NK_COMMAND_RECT 997 /// your_draw_rect_function(...) 998 /// break; 999 /// case //...: 1000 /// //[...] 1001 /// } 1002 /// } 1003 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1004 /// 1005 /// In program flow context draw commands need to be executed after input has been 1006 /// gathered and the complete UI with windows and their contained widgets have 1007 /// been executed and before calling `nk_clear` which frees all previously 1008 /// allocated draw commands. 1009 /// 1010 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1011 /// struct nk_context ctx; 1012 /// nk_init_xxx(&ctx, ...); 1013 /// while (1) { 1014 /// Event evt; 1015 /// nk_input_begin(&ctx); 1016 /// while (GetEvent(&evt)) { 1017 /// if (evt.type == MOUSE_MOVE) 1018 /// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); 1019 /// else if (evt.type == [...]) { 1020 /// [...] 1021 /// } 1022 /// } 1023 /// nk_input_end(&ctx); 1024 /// // 1025 /// // [...] 1026 /// // 1027 /// const struct nk_command *cmd = 0; 1028 /// nk_foreach(cmd, &ctx) { 1029 /// switch (cmd->type) { 1030 /// case NK_COMMAND_LINE: 1031 /// your_draw_line_function(...) 1032 /// break; 1033 /// case NK_COMMAND_RECT 1034 /// your_draw_rect_function(...) 1035 /// break; 1036 /// case ...: 1037 /// // [...] 1038 /// } 1039 /// nk_clear(&ctx); 1040 /// } 1041 /// nk_free(&ctx); 1042 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1043 /// 1044 /// You probably noticed that you have to draw all of the UI each frame which is 1045 /// quite wasteful. While the actual UI updating loop is quite fast rendering 1046 /// without actually needing it is not. So there are multiple things you could do. 1047 /// 1048 /// First is only update on input. This of course is only an option if your 1049 /// application only depends on the UI and does not require any outside calculations. 1050 /// If you actually only update on input make sure to update the UI two times each 1051 /// frame and call `nk_clear` directly after the first pass and only draw in 1052 /// the second pass. In addition it is recommended to also add additional timers 1053 /// to make sure the UI is not drawn more than a fixed number of frames per second. 1054 /// 1055 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1056 /// struct nk_context ctx; 1057 /// nk_init_xxx(&ctx, ...); 1058 /// while (1) { 1059 /// // [...wait for input ] 1060 /// // [...do two UI passes ...] 1061 /// do_ui(...) 1062 /// nk_clear(&ctx); 1063 /// do_ui(...) 1064 /// // 1065 /// // draw 1066 /// const struct nk_command *cmd = 0; 1067 /// nk_foreach(cmd, &ctx) { 1068 /// switch (cmd->type) { 1069 /// case NK_COMMAND_LINE: 1070 /// your_draw_line_function(...) 1071 /// break; 1072 /// case NK_COMMAND_RECT 1073 /// your_draw_rect_function(...) 1074 /// break; 1075 /// case ...: 1076 /// //[...] 1077 /// } 1078 /// nk_clear(&ctx); 1079 /// } 1080 /// nk_free(&ctx); 1081 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1082 /// 1083 /// The second probably more applicable trick is to only draw if anything changed. 1084 /// It is not really useful for applications with continuous draw loop but 1085 /// quite useful for desktop applications. To actually get nuklear to only 1086 /// draw on changes you first have to define `NK_ZERO_COMMAND_MEMORY` and 1087 /// allocate a memory buffer that will store each unique drawing output. 1088 /// After each frame you compare the draw command memory inside the library 1089 /// with your allocated buffer by memcmp. If memcmp detects differences 1090 /// you have to copy the command buffer into the allocated buffer 1091 /// and then draw like usual (this example uses fixed memory but you could 1092 /// use dynamically allocated memory). 1093 /// 1094 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1095 /// //[... other defines ...] 1096 /// #define NK_ZERO_COMMAND_MEMORY 1097 /// #include "nuklear.h" 1098 /// // 1099 /// // setup context 1100 /// struct nk_context ctx; 1101 /// void *last = calloc(1,64*1024); 1102 /// void *buf = calloc(1,64*1024); 1103 /// nk_init_fixed(&ctx, buf, 64*1024); 1104 /// // 1105 /// // loop 1106 /// while (1) { 1107 /// // [...input...] 1108 /// // [...ui...] 1109 /// void *cmds = nk_buffer_memory(&ctx.memory); 1110 /// if (memcmp(cmds, last, ctx.memory.allocated)) { 1111 /// memcpy(last,cmds,ctx.memory.allocated); 1112 /// const struct nk_command *cmd = 0; 1113 /// nk_foreach(cmd, &ctx) { 1114 /// switch (cmd->type) { 1115 /// case NK_COMMAND_LINE: 1116 /// your_draw_line_function(...) 1117 /// break; 1118 /// case NK_COMMAND_RECT 1119 /// your_draw_rect_function(...) 1120 /// break; 1121 /// case ...: 1122 /// // [...] 1123 /// } 1124 /// } 1125 /// } 1126 /// nk_clear(&ctx); 1127 /// } 1128 /// nk_free(&ctx); 1129 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1130 /// 1131 /// Finally while using draw commands makes sense for higher abstracted platforms like 1132 /// X11 and Win32 or drawing libraries it is often desirable to use graphics 1133 /// hardware directly. Therefore it is possible to just define 1134 /// `NK_INCLUDE_VERTEX_BUFFER_OUTPUT` which includes optional vertex output. 1135 /// To access the vertex output you first have to convert all draw commands into 1136 /// vertexes by calling `nk_convert` which takes in your preferred vertex format. 1137 /// After successfully converting all draw commands just iterate over and execute all 1138 /// vertex draw commands: 1139 /// 1140 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1141 /// // fill configuration 1142 /// struct your_vertex 1143 /// { 1144 /// float pos[2]; // important to keep it to 2 floats 1145 /// float uv[2]; 1146 /// unsigned char col[4]; 1147 /// }; 1148 /// struct nk_convert_config cfg = {}; 1149 /// static const struct nk_draw_vertex_layout_element vertex_layout[] = { 1150 /// {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, pos)}, 1151 /// {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, uv)}, 1152 /// {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct your_vertex, col)}, 1153 /// {NK_VERTEX_LAYOUT_END} 1154 /// }; 1155 /// cfg.shape_AA = NK_ANTI_ALIASING_ON; 1156 /// cfg.line_AA = NK_ANTI_ALIASING_ON; 1157 /// cfg.vertex_layout = vertex_layout; 1158 /// cfg.vertex_size = sizeof(struct your_vertex); 1159 /// cfg.vertex_alignment = NK_ALIGNOF(struct your_vertex); 1160 /// cfg.circle_segment_count = 22; 1161 /// cfg.curve_segment_count = 22; 1162 /// cfg.arc_segment_count = 22; 1163 /// cfg.global_alpha = 1.0f; 1164 /// cfg.tex_null = dev->tex_null; 1165 /// // 1166 /// // setup buffers and convert 1167 /// struct nk_buffer cmds, verts, idx; 1168 /// nk_buffer_init_default(&cmds); 1169 /// nk_buffer_init_default(&verts); 1170 /// nk_buffer_init_default(&idx); 1171 /// nk_convert(&ctx, &cmds, &verts, &idx, &cfg); 1172 /// // 1173 /// // draw 1174 /// nk_draw_foreach(cmd, &ctx, &cmds) { 1175 /// if (!cmd->elem_count) continue; 1176 /// //[...] 1177 /// } 1178 /// nk_buffer_free(&cms); 1179 /// nk_buffer_free(&verts); 1180 /// nk_buffer_free(&idx); 1181 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1182 /// 1183 /// #### Reference 1184 /// Function | Description 1185 /// --------------------|------------------------------------------------------- 1186 /// __nk__begin__ | Returns the first draw command in the context draw command list to be drawn 1187 /// __nk__next__ | Increments the draw command iterator to the next command inside the context draw command list 1188 /// __nk_foreach__ | Iterates over each draw command inside the context draw command list 1189 /// __nk_convert__ | Converts from the abstract draw commands list into a hardware accessible vertex format 1190 /// __nk_draw_begin__ | Returns the first vertex command in the context vertex draw list to be executed 1191 /// __nk__draw_next__ | Increments the vertex command iterator to the next command inside the context vertex command list 1192 /// __nk__draw_end__ | Returns the end of the vertex draw list 1193 /// __nk_draw_foreach__ | Iterates over each vertex draw command inside the vertex draw list 1194 */ 1195 enum nk_anti_aliasing 1196 { 1197 NK_ANTI_ALIASING_OFF = 0, 1198 NK_ANTI_ALIASING_ON = 1 1199 } 1200 1201 enum nk_convert_result 1202 { 1203 NK_CONVERT_SUCCESS = 0, 1204 NK_CONVERT_INVALID_PARAM = 1, 1205 NK_CONVERT_COMMAND_BUFFER_FULL = NK_FLAG(1), 1206 NK_CONVERT_VERTEX_BUFFER_FULL = NK_FLAG(2), 1207 NK_CONVERT_ELEMENT_BUFFER_FULL = NK_FLAG(3) 1208 } 1209 1210 struct nk_draw_null_texture 1211 { 1212 nk_handle texture; /* texture handle to a texture with a white pixel */ 1213 nk_vec2_ uv; /* coordinates to a white pixel in the texture */ 1214 } 1215 1216 struct nk_convert_config 1217 { 1218 float global_alpha; /* global alpha value */ 1219 nk_anti_aliasing line_AA; /* line anti-aliasing flag can be turned off if you are tight on memory */ 1220 nk_anti_aliasing shape_AA; /* shape anti-aliasing flag can be turned off if you are tight on memory */ 1221 uint circle_segment_count; /* number of segments used for circles: default to 22 */ 1222 uint arc_segment_count; /* number of segments used for arcs: default to 22 */ 1223 uint curve_segment_count; /* number of segments used for curves: default to 22 */ 1224 nk_draw_null_texture tex_null; /* handle to texture with a white pixel for shape drawing */ 1225 const(nk_draw_vertex_layout_element)* vertex_layout; /* describes the vertex output format and packing */ 1226 nk_size vertex_size; /* sizeof one vertex for vertex packing */ 1227 nk_size vertex_alignment; /* vertex alignment: Can be obtained by NK_ALIGNOF */ 1228 } 1229 1230 /*/// #### nk__begin 1231 /// Returns a draw command list iterator to iterate all draw 1232 /// commands accumulated over one frame. 1233 /// 1234 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1235 /// const struct nk_command* nk__begin(struct nk_context*); 1236 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1237 /// 1238 /// Parameter | Description 1239 /// ------------|----------------------------------------------------------- 1240 /// __ctx__ | must point to an previously initialized `nk_context` struct at the end of a frame 1241 /// 1242 /// Returns draw command pointer pointing to the first command inside the draw command list 1243 */ 1244 const(nk_command)* nk__begin (nk_context*); 1245 /*/// #### nk__next 1246 /// Returns draw command pointer pointing to the next command inside the draw command list 1247 /// 1248 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1249 /// const struct nk_command* nk__next(struct nk_context*, const struct nk_command*); 1250 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1251 /// 1252 /// Parameter | Description 1253 /// ------------|----------------------------------------------------------- 1254 /// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame 1255 /// __cmd__ | Must point to an previously a draw command either returned by `nk__begin` or `nk__next` 1256 /// 1257 /// Returns draw command pointer pointing to the next command inside the draw command list 1258 */ 1259 const(nk_command)* nk__next (nk_context*, const(nk_command)*); 1260 /*/// #### nk_foreach 1261 /// Iterates over each draw command inside the context draw command list 1262 /// 1263 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1264 /// #define nk_foreach(c, ctx) 1265 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1266 /// 1267 /// Parameter | Description 1268 /// ------------|----------------------------------------------------------- 1269 /// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame 1270 /// __cmd__ | Command pointer initialized to NULL 1271 /// 1272 /// Iterates over each draw command inside the context draw command list 1273 */ 1274 1275 /*/// #### nk_convert 1276 /// Converts all internal draw commands into vertex draw commands and fills 1277 /// three buffers with vertexes, vertex draw commands and vertex indices. The vertex format 1278 /// as well as some other configuration values have to be configured by filling out a 1279 /// `nk_convert_config` struct. 1280 /// 1281 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1282 /// nk_flags nk_convert(struct nk_context *ctx, struct nk_buffer *cmds, 1283 /// struct nk_buffer *vertices, struct nk_buffer *elements, const struct nk_convert_config*); 1284 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1285 /// 1286 /// Parameter | Description 1287 /// ------------|----------------------------------------------------------- 1288 /// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame 1289 /// __cmds__ | Must point to a previously initialized buffer to hold converted vertex draw commands 1290 /// __vertices__| Must point to a previously initialized buffer to hold all produced vertices 1291 /// __elements__| Must point to a previously initialized buffer to hold all produced vertex indices 1292 /// __config__ | Must point to a filled out `nk_config` struct to configure the conversion process 1293 /// 1294 /// Returns one of enum nk_convert_result error codes 1295 /// 1296 /// Parameter | Description 1297 /// --------------------------------|----------------------------------------------------------- 1298 /// NK_CONVERT_SUCCESS | Signals a successful draw command to vertex buffer conversion 1299 /// NK_CONVERT_INVALID_PARAM | An invalid argument was passed in the function call 1300 /// NK_CONVERT_COMMAND_BUFFER_FULL | The provided buffer for storing draw commands is full or failed to allocate more memory 1301 /// NK_CONVERT_VERTEX_BUFFER_FULL | The provided buffer for storing vertices is full or failed to allocate more memory 1302 /// NK_CONVERT_ELEMENT_BUFFER_FULL | The provided buffer for storing indices is full or failed to allocate more memory 1303 */ 1304 1305 /*/// #### nk__draw_begin 1306 /// Returns a draw vertex command buffer iterator to iterate over the vertex draw command buffer 1307 /// 1308 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1309 /// const struct nk_draw_command* nk__draw_begin(const struct nk_context*, const struct nk_buffer*); 1310 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1311 /// 1312 /// Parameter | Description 1313 /// ------------|----------------------------------------------------------- 1314 /// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame 1315 /// __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer 1316 /// 1317 /// Returns vertex draw command pointer pointing to the first command inside the vertex draw command buffer 1318 */ 1319 1320 /*/// #### nk__draw_end 1321 /// Returns the vertex draw command at the end of the vertex draw command buffer 1322 /// 1323 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1324 /// const struct nk_draw_command* nk__draw_end(const struct nk_context *ctx, const struct nk_buffer *buf); 1325 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1326 /// 1327 /// Parameter | Description 1328 /// ------------|----------------------------------------------------------- 1329 /// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame 1330 /// __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer 1331 /// 1332 /// Returns vertex draw command pointer pointing to the end of the last vertex draw command inside the vertex draw command buffer 1333 */ 1334 1335 /*/// #### nk__draw_next 1336 /// Increments the vertex draw command buffer iterator 1337 /// 1338 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1339 /// const struct nk_draw_command* nk__draw_next(const struct nk_draw_command*, const struct nk_buffer*, const struct nk_context*); 1340 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1341 /// 1342 /// Parameter | Description 1343 /// ------------|----------------------------------------------------------- 1344 /// __cmd__ | Must point to an previously either by `nk__draw_begin` or `nk__draw_next` returned vertex draw command 1345 /// __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer 1346 /// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame 1347 /// 1348 /// Returns vertex draw command pointer pointing to the end of the last vertex draw command inside the vertex draw command buffer 1349 */ 1350 1351 /*/// #### nk_draw_foreach 1352 /// Iterates over each vertex draw command inside a vertex draw command buffer 1353 /// 1354 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1355 /// #define nk_draw_foreach(cmd,ctx, b) 1356 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1357 /// 1358 /// Parameter | Description 1359 /// ------------|----------------------------------------------------------- 1360 /// __cmd__ | `nk_draw_command`iterator set to NULL 1361 /// __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer 1362 /// __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame 1363 */ 1364 1365 /* ============================================================================= 1366 * 1367 * WINDOW 1368 * 1369 * ============================================================================= 1370 /// ### Window 1371 /// Windows are the main persistent state used inside nuklear and are life time 1372 /// controlled by simply "retouching" (i.e. calling) each window each frame. 1373 /// All widgets inside nuklear can only be added inside the function pair `nk_begin_xxx` 1374 /// and `nk_end`. Calling any widgets outside these two functions will result in an 1375 /// assert in debug or no state change in release mode.<br /><br /> 1376 /// 1377 /// Each window holds frame persistent state like position, size, flags, state tables, 1378 /// and some garbage collected internal persistent widget state. Each window 1379 /// is linked into a window stack list which determines the drawing and overlapping 1380 /// order. The topmost window thereby is the currently active window.<br /><br /> 1381 /// 1382 /// To change window position inside the stack occurs either automatically by 1383 /// user input by being clicked on or programmatically by calling `nk_window_focus`. 1384 /// Windows by default are visible unless explicitly being defined with flag 1385 /// `NK_WINDOW_HIDDEN`, the user clicked the close button on windows with flag 1386 /// `NK_WINDOW_CLOSABLE` or if a window was explicitly hidden by calling 1387 /// `nk_window_show`. To explicitly close and destroy a window call `nk_window_close`.<br /><br /> 1388 /// 1389 /// #### Usage 1390 /// To create and keep a window you have to call one of the two `nk_begin_xxx` 1391 /// functions to start window declarations and `nk_end` at the end. Furthermore it 1392 /// is recommended to check the return value of `nk_begin_xxx` and only process 1393 /// widgets inside the window if the value is not 0. Either way you have to call 1394 /// `nk_end` at the end of window declarations. Furthermore, do not attempt to 1395 /// nest `nk_begin_xxx` calls which will hopefully result in an assert or if not 1396 /// in a segmentation fault. 1397 /// 1398 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1399 /// if (nk_begin_xxx(...) { 1400 /// // [... widgets ...] 1401 /// } 1402 /// nk_end(ctx); 1403 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1404 /// 1405 /// In the grand concept window and widget declarations need to occur after input 1406 /// handling and before drawing to screen. Not doing so can result in higher 1407 /// latency or at worst invalid behavior. Furthermore make sure that `nk_clear` 1408 /// is called at the end of the frame. While nuklear's default platform backends 1409 /// already call `nk_clear` for you if you write your own backend not calling 1410 /// `nk_clear` can cause asserts or even worse undefined behavior. 1411 /// 1412 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1413 /// struct nk_context ctx; 1414 /// nk_init_xxx(&ctx, ...); 1415 /// while (1) { 1416 /// Event evt; 1417 /// nk_input_begin(&ctx); 1418 /// while (GetEvent(&evt)) { 1419 /// if (evt.type == MOUSE_MOVE) 1420 /// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); 1421 /// else if (evt.type == [...]) { 1422 /// nk_input_xxx(...); 1423 /// } 1424 /// } 1425 /// nk_input_end(&ctx); 1426 /// 1427 /// if (nk_begin_xxx(...) { 1428 /// //[...] 1429 /// } 1430 /// nk_end(ctx); 1431 /// 1432 /// const struct nk_command *cmd = 0; 1433 /// nk_foreach(cmd, &ctx) { 1434 /// case NK_COMMAND_LINE: 1435 /// your_draw_line_function(...) 1436 /// break; 1437 /// case NK_COMMAND_RECT 1438 /// your_draw_rect_function(...) 1439 /// break; 1440 /// case //...: 1441 /// //[...] 1442 /// } 1443 /// nk_clear(&ctx); 1444 /// } 1445 /// nk_free(&ctx); 1446 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1447 /// 1448 /// #### Reference 1449 /// Function | Description 1450 /// ------------------------------------|---------------------------------------- 1451 /// nk_begin | Starts a new window; needs to be called every frame for every window (unless hidden) or otherwise the window gets removed 1452 /// nk_begin_titled | Extended window start with separated title and identifier to allow multiple windows with same name but not title 1453 /// nk_end | Needs to be called at the end of the window building process to process scaling, scrollbars and general cleanup 1454 // 1455 /// nk_window_find | Finds and returns the window with give name 1456 /// nk_window_get_bounds | Returns a rectangle with screen position and size of the currently processed window. 1457 /// nk_window_get_position | Returns the position of the currently processed window 1458 /// nk_window_get_size | Returns the size with width and height of the currently processed window 1459 /// nk_window_get_width | Returns the width of the currently processed window 1460 /// nk_window_get_height | Returns the height of the currently processed window 1461 /// nk_window_get_panel | Returns the underlying panel which contains all processing state of the current window 1462 /// nk_window_get_content_region | Returns the position and size of the currently visible and non-clipped space inside the currently processed window 1463 /// nk_window_get_content_region_min | Returns the upper rectangle position of the currently visible and non-clipped space inside the currently processed window 1464 /// nk_window_get_content_region_max | Returns the upper rectangle position of the currently visible and non-clipped space inside the currently processed window 1465 /// nk_window_get_content_region_size | Returns the size of the currently visible and non-clipped space inside the currently processed window 1466 /// nk_window_get_canvas | Returns the draw command buffer. Can be used to draw custom widgets 1467 /// nk_window_get_scroll | Gets the scroll offset of the current window 1468 /// nk_window_has_focus | Returns if the currently processed window is currently active 1469 /// nk_window_is_collapsed | Returns if the window with given name is currently minimized/collapsed 1470 /// nk_window_is_closed | Returns if the currently processed window was closed 1471 /// nk_window_is_hidden | Returns if the currently processed window was hidden 1472 /// nk_window_is_active | Same as nk_window_has_focus for some reason 1473 /// nk_window_is_hovered | Returns if the currently processed window is currently being hovered by mouse 1474 /// nk_window_is_any_hovered | Return if any window currently hovered 1475 /// nk_item_is_any_active | Returns if any window or widgets is currently hovered or active 1476 // 1477 /// nk_window_set_bounds | Updates position and size of the currently processed window 1478 /// nk_window_set_position | Updates position of the currently process window 1479 /// nk_window_set_size | Updates the size of the currently processed window 1480 /// nk_window_set_focus | Set the currently processed window as active window 1481 /// nk_window_set_scroll | Sets the scroll offset of the current window 1482 // 1483 /// nk_window_close | Closes the window with given window name which deletes the window at the end of the frame 1484 /// nk_window_collapse | Collapses the window with given window name 1485 /// nk_window_collapse_if | Collapses the window with given window name if the given condition was met 1486 /// nk_window_show | Hides a visible or reshows a hidden window 1487 /// nk_window_show_if | Hides/shows a window depending on condition 1488 */ 1489 /* 1490 /// #### nk_panel_flags 1491 /// Flag | Description 1492 /// ----------------------------|---------------------------------------- 1493 /// NK_WINDOW_BORDER | Draws a border around the window to visually separate window from the background 1494 /// NK_WINDOW_MOVABLE | The movable flag indicates that a window can be moved by user input or by dragging the window header 1495 /// NK_WINDOW_SCALABLE | The scalable flag indicates that a window can be scaled by user input by dragging a scaler icon at the button of the window 1496 /// NK_WINDOW_CLOSABLE | Adds a closable icon into the header 1497 /// NK_WINDOW_MINIMIZABLE | Adds a minimize icon into the header 1498 /// NK_WINDOW_NO_SCROLLBAR | Removes the scrollbar from the window 1499 /// NK_WINDOW_TITLE | Forces a header at the top at the window showing the title 1500 /// NK_WINDOW_SCROLL_AUTO_HIDE | Automatically hides the window scrollbar if no user interaction: also requires delta time in `nk_context` to be set each frame 1501 /// NK_WINDOW_BACKGROUND | Always keep window in the background 1502 /// NK_WINDOW_SCALE_LEFT | Puts window scaler in the left-bottom corner instead right-bottom 1503 /// NK_WINDOW_NO_INPUT | Prevents window of scaling, moving or getting focus 1504 /// 1505 /// #### nk_collapse_states 1506 /// State | Description 1507 /// ----------------|----------------------------------------------------------- 1508 /// __NK_MINIMIZED__| UI section is collased and not visible until maximized 1509 /// __NK_MAXIMIZED__| UI section is extended and visible until minimized 1510 /// <br /><br /> 1511 */ 1512 enum nk_panel_flags 1513 { 1514 NK_WINDOW_BORDER = NK_FLAG(0), 1515 NK_WINDOW_MOVABLE = NK_FLAG(1), 1516 NK_WINDOW_SCALABLE = NK_FLAG(2), 1517 NK_WINDOW_CLOSABLE = NK_FLAG(3), 1518 NK_WINDOW_MINIMIZABLE = NK_FLAG(4), 1519 NK_WINDOW_NO_SCROLLBAR = NK_FLAG(5), 1520 NK_WINDOW_TITLE = NK_FLAG(6), 1521 NK_WINDOW_SCROLL_AUTO_HIDE = NK_FLAG(7), 1522 NK_WINDOW_BACKGROUND = NK_FLAG(8), 1523 NK_WINDOW_SCALE_LEFT = NK_FLAG(9), 1524 NK_WINDOW_NO_INPUT = NK_FLAG(10) 1525 } 1526 1527 /*/// #### nk_begin 1528 /// Starts a new window; needs to be called every frame for every 1529 /// window (unless hidden) or otherwise the window gets removed 1530 /// 1531 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1532 /// nk_bool nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags); 1533 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1534 /// 1535 /// Parameter | Description 1536 /// ------------|----------------------------------------------------------- 1537 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1538 /// __title__ | Window title and identifier. Needs to be persistent over frames to identify the window 1539 /// __bounds__ | Initial position and window size. However if you do not define `NK_WINDOW_SCALABLE` or `NK_WINDOW_MOVABLE` you can set window position and size every frame 1540 /// __flags__ | Window flags defined in the nk_panel_flags section with a number of different window behaviors 1541 /// 1542 /// Returns `true(1)` if the window can be filled up with widgets from this point 1543 /// until `nk_end` or `false(0)` otherwise for example if minimized 1544 */ 1545 nk_bool nk_begin (nk_context* ctx, const(char)* title, nk_rect_ bounds, nk_flags flags); 1546 /*/// #### nk_begin_titled 1547 /// Extended window start with separated title and identifier to allow multiple 1548 /// windows with same title but not name 1549 /// 1550 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1551 /// nk_bool nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags); 1552 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1553 /// 1554 /// Parameter | Description 1555 /// ------------|----------------------------------------------------------- 1556 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1557 /// __name__ | Window identifier. Needs to be persistent over frames to identify the window 1558 /// __title__ | Window title displayed inside header if flag `NK_WINDOW_TITLE` or either `NK_WINDOW_CLOSABLE` or `NK_WINDOW_MINIMIZED` was set 1559 /// __bounds__ | Initial position and window size. However if you do not define `NK_WINDOW_SCALABLE` or `NK_WINDOW_MOVABLE` you can set window position and size every frame 1560 /// __flags__ | Window flags defined in the nk_panel_flags section with a number of different window behaviors 1561 /// 1562 /// Returns `true(1)` if the window can be filled up with widgets from this point 1563 /// until `nk_end` or `false(0)` otherwise for example if minimized 1564 */ 1565 nk_bool nk_begin_titled (nk_context* ctx, const(char)* name, const(char)* title, nk_rect_ bounds, nk_flags flags); 1566 /*/// #### nk_end 1567 /// Needs to be called at the end of the window building process to process scaling, scrollbars and general cleanup. 1568 /// All widget calls after this functions will result in asserts or no state changes 1569 /// 1570 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1571 /// void nk_end(struct nk_context *ctx); 1572 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1573 /// 1574 /// Parameter | Description 1575 /// ------------|----------------------------------------------------------- 1576 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1577 */ 1578 void nk_end (nk_context* ctx); 1579 /*/// #### nk_window_find 1580 /// Finds and returns a window from passed name 1581 /// 1582 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1583 /// struct nk_window *nk_window_find(struct nk_context *ctx, const char *name); 1584 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1585 /// 1586 /// Parameter | Description 1587 /// ------------|----------------------------------------------------------- 1588 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1589 /// __name__ | Window identifier 1590 /// 1591 /// Returns a `nk_window` struct pointing to the identified window or NULL if 1592 /// no window with the given name was found 1593 */ 1594 nk_window* nk_window_find (nk_context* ctx, const(char)* name); 1595 /*/// #### nk_window_get_bounds 1596 /// Returns a rectangle with screen position and size of the currently processed window 1597 /// 1598 /// !!! WARNING 1599 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1600 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1601 /// struct nk_rect nk_window_get_bounds(const struct nk_context *ctx); 1602 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1603 /// 1604 /// Parameter | Description 1605 /// ------------|----------------------------------------------------------- 1606 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1607 /// 1608 /// Returns a `nk_rect` struct with window upper left window position and size 1609 */ 1610 nk_rect_ nk_window_get_bounds (const(nk_context)* ctx); 1611 /*/// #### nk_window_get_position 1612 /// Returns the position of the currently processed window. 1613 /// 1614 /// !!! WARNING 1615 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1616 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1617 /// struct nk_vec2 nk_window_get_position(const struct nk_context *ctx); 1618 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1619 /// 1620 /// Parameter | Description 1621 /// ------------|----------------------------------------------------------- 1622 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1623 /// 1624 /// Returns a `nk_vec2` struct with window upper left position 1625 */ 1626 nk_vec2_ nk_window_get_position (const(nk_context)* ctx); 1627 /*/// #### nk_window_get_size 1628 /// Returns the size with width and height of the currently processed window. 1629 /// 1630 /// !!! WARNING 1631 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1632 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1633 /// struct nk_vec2 nk_window_get_size(const struct nk_context *ctx); 1634 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1635 /// 1636 /// Parameter | Description 1637 /// ------------|----------------------------------------------------------- 1638 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1639 /// 1640 /// Returns a `nk_vec2` struct with window width and height 1641 */ 1642 nk_vec2_ nk_window_get_size (const(nk_context)*); 1643 /*/// #### nk_window_get_width 1644 /// Returns the width of the currently processed window. 1645 /// 1646 /// !!! WARNING 1647 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1648 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1649 /// float nk_window_get_width(const struct nk_context *ctx); 1650 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1651 /// 1652 /// Parameter | Description 1653 /// ------------|----------------------------------------------------------- 1654 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1655 /// 1656 /// Returns the current window width 1657 */ 1658 float nk_window_get_width (const(nk_context)*); 1659 /*/// #### nk_window_get_height 1660 /// Returns the height of the currently processed window. 1661 /// 1662 /// !!! WARNING 1663 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1664 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1665 /// float nk_window_get_height(const struct nk_context *ctx); 1666 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1667 /// 1668 /// Parameter | Description 1669 /// ------------|----------------------------------------------------------- 1670 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1671 /// 1672 /// Returns the current window height 1673 */ 1674 float nk_window_get_height (const(nk_context)*); 1675 /*/// #### nk_window_get_panel 1676 /// Returns the underlying panel which contains all processing state of the current window. 1677 /// 1678 /// !!! WARNING 1679 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1680 /// !!! WARNING 1681 /// Do not keep the returned panel pointer around, it is only valid until `nk_end` 1682 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1683 /// struct nk_panel* nk_window_get_panel(struct nk_context *ctx); 1684 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1685 /// 1686 /// Parameter | Description 1687 /// ------------|----------------------------------------------------------- 1688 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1689 /// 1690 /// Returns a pointer to window internal `nk_panel` state. 1691 */ 1692 nk_panel* nk_window_get_panel (nk_context*); 1693 /*/// #### nk_window_get_content_region 1694 /// Returns the position and size of the currently visible and non-clipped space 1695 /// inside the currently processed window. 1696 /// 1697 /// !!! WARNING 1698 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1699 /// 1700 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1701 /// struct nk_rect nk_window_get_content_region(struct nk_context *ctx); 1702 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1703 /// 1704 /// Parameter | Description 1705 /// ------------|----------------------------------------------------------- 1706 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1707 /// 1708 /// Returns `nk_rect` struct with screen position and size (no scrollbar offset) 1709 /// of the visible space inside the current window 1710 */ 1711 nk_rect_ nk_window_get_content_region (nk_context*); 1712 /*/// #### nk_window_get_content_region_min 1713 /// Returns the upper left position of the currently visible and non-clipped 1714 /// space inside the currently processed window. 1715 /// 1716 /// !!! WARNING 1717 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1718 /// 1719 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1720 /// struct nk_vec2 nk_window_get_content_region_min(struct nk_context *ctx); 1721 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1722 /// 1723 /// Parameter | Description 1724 /// ------------|----------------------------------------------------------- 1725 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1726 /// 1727 /// returns `nk_vec2` struct with upper left screen position (no scrollbar offset) 1728 /// of the visible space inside the current window 1729 */ 1730 nk_vec2_ nk_window_get_content_region_min (nk_context*); 1731 /*/// #### nk_window_get_content_region_max 1732 /// Returns the lower right screen position of the currently visible and 1733 /// non-clipped space inside the currently processed window. 1734 /// 1735 /// !!! WARNING 1736 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1737 /// 1738 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1739 /// struct nk_vec2 nk_window_get_content_region_max(struct nk_context *ctx); 1740 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1741 /// 1742 /// Parameter | Description 1743 /// ------------|----------------------------------------------------------- 1744 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1745 /// 1746 /// Returns `nk_vec2` struct with lower right screen position (no scrollbar offset) 1747 /// of the visible space inside the current window 1748 */ 1749 nk_vec2_ nk_window_get_content_region_max (nk_context*); 1750 /*/// #### nk_window_get_content_region_size 1751 /// Returns the size of the currently visible and non-clipped space inside the 1752 /// currently processed window 1753 /// 1754 /// !!! WARNING 1755 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1756 /// 1757 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1758 /// struct nk_vec2 nk_window_get_content_region_size(struct nk_context *ctx); 1759 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1760 /// 1761 /// Parameter | Description 1762 /// ------------|----------------------------------------------------------- 1763 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1764 /// 1765 /// Returns `nk_vec2` struct with size the visible space inside the current window 1766 */ 1767 nk_vec2_ nk_window_get_content_region_size (nk_context*); 1768 /*/// #### nk_window_get_canvas 1769 /// Returns the draw command buffer. Can be used to draw custom widgets 1770 /// !!! WARNING 1771 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1772 /// !!! WARNING 1773 /// Do not keep the returned command buffer pointer around it is only valid until `nk_end` 1774 /// 1775 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1776 /// struct nk_command_buffer* nk_window_get_canvas(struct nk_context *ctx); 1777 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1778 /// 1779 /// Parameter | Description 1780 /// ------------|----------------------------------------------------------- 1781 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1782 /// 1783 /// Returns a pointer to window internal `nk_command_buffer` struct used as 1784 /// drawing canvas. Can be used to do custom drawing. 1785 */ 1786 nk_command_buffer* nk_window_get_canvas (nk_context*); 1787 /*/// #### nk_window_get_scroll 1788 /// Gets the scroll offset for the current window 1789 /// !!! WARNING 1790 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1791 /// 1792 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1793 /// void nk_window_get_scroll(struct nk_context *ctx, nk_uint *offset_x, nk_uint *offset_y); 1794 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1795 /// 1796 /// Parameter | Description 1797 /// -------------|----------------------------------------------------------- 1798 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1799 /// __offset_x__ | A pointer to the x offset output (or NULL to ignore) 1800 /// __offset_y__ | A pointer to the y offset output (or NULL to ignore) 1801 */ 1802 void nk_window_get_scroll (nk_context*, nk_uint* offset_x, nk_uint* offset_y); 1803 /*/// #### nk_window_has_focus 1804 /// Returns if the currently processed window is currently active 1805 /// !!! WARNING 1806 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1807 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1808 /// nk_bool nk_window_has_focus(const struct nk_context *ctx); 1809 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1810 /// 1811 /// Parameter | Description 1812 /// ------------|----------------------------------------------------------- 1813 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1814 /// 1815 /// Returns `false(0)` if current window is not active or `true(1)` if it is 1816 */ 1817 nk_bool nk_window_has_focus (const(nk_context)*); 1818 /*/// #### nk_window_is_hovered 1819 /// Return if the current window is being hovered 1820 /// !!! WARNING 1821 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1822 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1823 /// nk_bool nk_window_is_hovered(struct nk_context *ctx); 1824 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1825 /// 1826 /// Parameter | Description 1827 /// ------------|----------------------------------------------------------- 1828 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1829 /// 1830 /// Returns `true(1)` if current window is hovered or `false(0)` otherwise 1831 */ 1832 nk_bool nk_window_is_hovered (nk_context*); 1833 /*/// #### nk_window_is_collapsed 1834 /// Returns if the window with given name is currently minimized/collapsed 1835 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1836 /// nk_bool nk_window_is_collapsed(struct nk_context *ctx, const char *name); 1837 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1838 /// 1839 /// Parameter | Description 1840 /// ------------|----------------------------------------------------------- 1841 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1842 /// __name__ | Identifier of window you want to check if it is collapsed 1843 /// 1844 /// Returns `true(1)` if current window is minimized and `false(0)` if window not 1845 /// found or is not minimized 1846 */ 1847 nk_bool nk_window_is_collapsed (nk_context* ctx, const(char)* name); 1848 /*/// #### nk_window_is_closed 1849 /// Returns if the window with given name was closed by calling `nk_close` 1850 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1851 /// nk_bool nk_window_is_closed(struct nk_context *ctx, const char *name); 1852 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1853 /// 1854 /// Parameter | Description 1855 /// ------------|----------------------------------------------------------- 1856 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1857 /// __name__ | Identifier of window you want to check if it is closed 1858 /// 1859 /// Returns `true(1)` if current window was closed or `false(0)` window not found or not closed 1860 */ 1861 nk_bool nk_window_is_closed (nk_context*, const(char)*); 1862 /*/// #### nk_window_is_hidden 1863 /// Returns if the window with given name is hidden 1864 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1865 /// nk_bool nk_window_is_hidden(struct nk_context *ctx, const char *name); 1866 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1867 /// 1868 /// Parameter | Description 1869 /// ------------|----------------------------------------------------------- 1870 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1871 /// __name__ | Identifier of window you want to check if it is hidden 1872 /// 1873 /// Returns `true(1)` if current window is hidden or `false(0)` window not found or visible 1874 */ 1875 nk_bool nk_window_is_hidden (nk_context*, const(char)*); 1876 /*/// #### nk_window_is_active 1877 /// Same as nk_window_has_focus for some reason 1878 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1879 /// nk_bool nk_window_is_active(struct nk_context *ctx, const char *name); 1880 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1881 /// 1882 /// Parameter | Description 1883 /// ------------|----------------------------------------------------------- 1884 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1885 /// __name__ | Identifier of window you want to check if it is active 1886 /// 1887 /// Returns `true(1)` if current window is active or `false(0)` window not found or not active 1888 */ 1889 nk_bool nk_window_is_active (nk_context*, const(char)*); 1890 /*/// #### nk_window_is_any_hovered 1891 /// Returns if the any window is being hovered 1892 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1893 /// nk_bool nk_window_is_any_hovered(struct nk_context*); 1894 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1895 /// 1896 /// Parameter | Description 1897 /// ------------|----------------------------------------------------------- 1898 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1899 /// 1900 /// Returns `true(1)` if any window is hovered or `false(0)` otherwise 1901 */ 1902 nk_bool nk_window_is_any_hovered (nk_context*); 1903 /*/// #### nk_item_is_any_active 1904 /// Returns if the any window is being hovered or any widget is currently active. 1905 /// Can be used to decide if input should be processed by UI or your specific input handling. 1906 /// Example could be UI and 3D camera to move inside a 3D space. 1907 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1908 /// nk_bool nk_item_is_any_active(struct nk_context*); 1909 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1910 /// 1911 /// Parameter | Description 1912 /// ------------|----------------------------------------------------------- 1913 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1914 /// 1915 /// Returns `true(1)` if any window is hovered or any item is active or `false(0)` otherwise 1916 */ 1917 nk_bool nk_item_is_any_active (nk_context*); 1918 /*/// #### nk_window_set_bounds 1919 /// Updates position and size of window with passed in name 1920 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1921 /// void nk_window_set_bounds(struct nk_context*, const char *name, struct nk_rect bounds); 1922 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1923 /// 1924 /// Parameter | Description 1925 /// ------------|----------------------------------------------------------- 1926 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1927 /// __name__ | Identifier of the window to modify both position and size 1928 /// __bounds__ | Must point to a `nk_rect` struct with the new position and size 1929 */ 1930 void nk_window_set_bounds (nk_context*, const(char)* name, nk_rect_ bounds); 1931 /*/// #### nk_window_set_position 1932 /// Updates position of window with passed name 1933 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1934 /// void nk_window_set_position(struct nk_context*, const char *name, struct nk_vec2 pos); 1935 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1936 /// 1937 /// Parameter | Description 1938 /// ------------|----------------------------------------------------------- 1939 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1940 /// __name__ | Identifier of the window to modify both position 1941 /// __pos__ | Must point to a `nk_vec2` struct with the new position 1942 */ 1943 void nk_window_set_position (nk_context*, const(char)* name, nk_vec2_ pos); 1944 /*/// #### nk_window_set_size 1945 /// Updates size of window with passed in name 1946 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1947 /// void nk_window_set_size(struct nk_context*, const char *name, struct nk_vec2); 1948 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1949 /// 1950 /// Parameter | Description 1951 /// ------------|----------------------------------------------------------- 1952 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1953 /// __name__ | Identifier of the window to modify both window size 1954 /// __size__ | Must point to a `nk_vec2` struct with new window size 1955 */ 1956 void nk_window_set_size (nk_context*, const(char)* name, nk_vec2_); 1957 /*/// #### nk_window_set_focus 1958 /// Sets the window with given name as active 1959 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1960 /// void nk_window_set_focus(struct nk_context*, const char *name); 1961 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1962 /// 1963 /// Parameter | Description 1964 /// ------------|----------------------------------------------------------- 1965 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1966 /// __name__ | Identifier of the window to set focus on 1967 */ 1968 void nk_window_set_focus (nk_context*, const(char)* name); 1969 /*/// #### nk_window_set_scroll 1970 /// Sets the scroll offset for the current window 1971 /// !!! WARNING 1972 /// Only call this function between calls `nk_begin_xxx` and `nk_end` 1973 /// 1974 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1975 /// void nk_window_set_scroll(struct nk_context *ctx, nk_uint offset_x, nk_uint offset_y); 1976 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1977 /// 1978 /// Parameter | Description 1979 /// -------------|----------------------------------------------------------- 1980 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1981 /// __offset_x__ | The x offset to scroll to 1982 /// __offset_y__ | The y offset to scroll to 1983 */ 1984 void nk_window_set_scroll (nk_context*, nk_uint offset_x, nk_uint offset_y); 1985 /*/// #### nk_window_close 1986 /// Closes a window and marks it for being freed at the end of the frame 1987 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 1988 /// void nk_window_close(struct nk_context *ctx, const char *name); 1989 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1990 /// 1991 /// Parameter | Description 1992 /// ------------|----------------------------------------------------------- 1993 /// __ctx__ | Must point to an previously initialized `nk_context` struct 1994 /// __name__ | Identifier of the window to close 1995 */ 1996 void nk_window_close (nk_context* ctx, const(char)* name); 1997 /*/// #### nk_window_collapse 1998 /// Updates collapse state of a window with given name 1999 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2000 /// void nk_window_collapse(struct nk_context*, const char *name, enum nk_collapse_states state); 2001 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2002 /// 2003 /// Parameter | Description 2004 /// ------------|----------------------------------------------------------- 2005 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2006 /// __name__ | Identifier of the window to close 2007 /// __state__ | value out of nk_collapse_states section 2008 */ 2009 void nk_window_collapse (nk_context*, const(char)* name, nk_collapse_states state); 2010 /*/// #### nk_window_collapse_if 2011 /// Updates collapse state of a window with given name if given condition is met 2012 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2013 /// void nk_window_collapse_if(struct nk_context*, const char *name, enum nk_collapse_states, int cond); 2014 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2015 /// 2016 /// Parameter | Description 2017 /// ------------|----------------------------------------------------------- 2018 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2019 /// __name__ | Identifier of the window to either collapse or maximize 2020 /// __state__ | value out of nk_collapse_states section the window should be put into 2021 /// __cond__ | condition that has to be met to actually commit the collapse state change 2022 */ 2023 void nk_window_collapse_if (nk_context*, const(char)* name, nk_collapse_states, int cond); 2024 /*/// #### nk_window_show 2025 /// updates visibility state of a window with given name 2026 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2027 /// void nk_window_show(struct nk_context*, const char *name, enum nk_show_states); 2028 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2029 /// 2030 /// Parameter | Description 2031 /// ------------|----------------------------------------------------------- 2032 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2033 /// __name__ | Identifier of the window to either collapse or maximize 2034 /// __state__ | state with either visible or hidden to modify the window with 2035 */ 2036 void nk_window_show (nk_context*, const(char)* name, nk_show_states); 2037 /*/// #### nk_window_show_if 2038 /// Updates visibility state of a window with given name if a given condition is met 2039 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2040 /// void nk_window_show_if(struct nk_context*, const char *name, enum nk_show_states, int cond); 2041 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2042 /// 2043 /// Parameter | Description 2044 /// ------------|----------------------------------------------------------- 2045 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2046 /// __name__ | Identifier of the window to either hide or show 2047 /// __state__ | state with either visible or hidden to modify the window with 2048 /// __cond__ | condition that has to be met to actually commit the visbility state change 2049 */ 2050 void nk_window_show_if (nk_context*, const(char)* name, nk_show_states, int cond); 2051 /* ============================================================================= 2052 * 2053 * LAYOUT 2054 * 2055 * ============================================================================= 2056 /// ### Layouting 2057 /// Layouting in general describes placing widget inside a window with position and size. 2058 /// While in this particular implementation there are five different APIs for layouting 2059 /// each with different trade offs between control and ease of use. <br /><br /> 2060 /// 2061 /// All layouting methods in this library are based around the concept of a row. 2062 /// A row has a height the window content grows by and a number of columns and each 2063 /// layouting method specifies how each widget is placed inside the row. 2064 /// After a row has been allocated by calling a layouting functions and then 2065 /// filled with widgets will advance an internal pointer over the allocated row. <br /><br /> 2066 /// 2067 /// To actually define a layout you just call the appropriate layouting function 2068 /// and each subsequent widget call will place the widget as specified. Important 2069 /// here is that if you define more widgets then columns defined inside the layout 2070 /// functions it will allocate the next row without you having to make another layouting <br /><br /> 2071 /// call. 2072 /// 2073 /// Biggest limitation with using all these APIs outside the `nk_layout_space_xxx` API 2074 /// is that you have to define the row height for each. However the row height 2075 /// often depends on the height of the font. <br /><br /> 2076 /// 2077 /// To fix that internally nuklear uses a minimum row height that is set to the 2078 /// height plus padding of currently active font and overwrites the row height 2079 /// value if zero. <br /><br /> 2080 /// 2081 /// If you manually want to change the minimum row height then 2082 /// use nk_layout_set_min_row_height, and use nk_layout_reset_min_row_height to 2083 /// reset it back to be derived from font height. <br /><br /> 2084 /// 2085 /// Also if you change the font in nuklear it will automatically change the minimum 2086 /// row height for you and. This means if you change the font but still want 2087 /// a minimum row height smaller than the font you have to repush your value. <br /><br /> 2088 /// 2089 /// For actually more advanced UI I would even recommend using the `nk_layout_space_xxx` 2090 /// layouting method in combination with a cassowary constraint solver (there are 2091 /// some versions on github with permissive license model) to take over all control over widget 2092 /// layouting yourself. However for quick and dirty layouting using all the other layouting 2093 /// functions should be fine. 2094 /// 2095 /// #### Usage 2096 /// 1. __nk_layout_row_dynamic__<br /><br /> 2097 /// The easiest layouting function is `nk_layout_row_dynamic`. It provides each 2098 /// widgets with same horizontal space inside the row and dynamically grows 2099 /// if the owning window grows in width. So the number of columns dictates 2100 /// the size of each widget dynamically by formula: 2101 /// 2102 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2103 /// widget_width = (window_width - padding - spacing) * (1/colum_count) 2104 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2105 /// 2106 /// Just like all other layouting APIs if you define more widget than columns this 2107 /// library will allocate a new row and keep all layouting parameters previously 2108 /// defined. 2109 /// 2110 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2111 /// if (nk_begin_xxx(...) { 2112 /// // first row with height: 30 composed of two widgets 2113 /// nk_layout_row_dynamic(&ctx, 30, 2); 2114 /// nk_widget(...); 2115 /// nk_widget(...); 2116 /// // 2117 /// // second row with same parameter as defined above 2118 /// nk_widget(...); 2119 /// nk_widget(...); 2120 /// // 2121 /// // third row uses 0 for height which will use auto layouting 2122 /// nk_layout_row_dynamic(&ctx, 0, 2); 2123 /// nk_widget(...); 2124 /// nk_widget(...); 2125 /// } 2126 /// nk_end(...); 2127 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2128 /// 2129 /// 2. __nk_layout_row_static__<br /><br /> 2130 /// Another easy layouting function is `nk_layout_row_static`. It provides each 2131 /// widget with same horizontal pixel width inside the row and does not grow 2132 /// if the owning window scales smaller or bigger. 2133 /// 2134 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2135 /// if (nk_begin_xxx(...) { 2136 /// // first row with height: 30 composed of two widgets with width: 80 2137 /// nk_layout_row_static(&ctx, 30, 80, 2); 2138 /// nk_widget(...); 2139 /// nk_widget(...); 2140 /// // 2141 /// // second row with same parameter as defined above 2142 /// nk_widget(...); 2143 /// nk_widget(...); 2144 /// // 2145 /// // third row uses 0 for height which will use auto layouting 2146 /// nk_layout_row_static(&ctx, 0, 80, 2); 2147 /// nk_widget(...); 2148 /// nk_widget(...); 2149 /// } 2150 /// nk_end(...); 2151 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2152 /// 2153 /// 3. __nk_layout_row_xxx__<br /><br /> 2154 /// A little bit more advanced layouting API are functions `nk_layout_row_begin`, 2155 /// `nk_layout_row_push` and `nk_layout_row_end`. They allow to directly 2156 /// specify each column pixel or window ratio in a row. It supports either 2157 /// directly setting per column pixel width or widget window ratio but not 2158 /// both. Furthermore it is a immediate mode API so each value is directly 2159 /// pushed before calling a widget. Therefore the layout is not automatically 2160 /// repeating like the last two layouting functions. 2161 /// 2162 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2163 /// if (nk_begin_xxx(...) { 2164 /// // first row with height: 25 composed of two widgets with width 60 and 40 2165 /// nk_layout_row_begin(ctx, NK_STATIC, 25, 2); 2166 /// nk_layout_row_push(ctx, 60); 2167 /// nk_widget(...); 2168 /// nk_layout_row_push(ctx, 40); 2169 /// nk_widget(...); 2170 /// nk_layout_row_end(ctx); 2171 /// // 2172 /// // second row with height: 25 composed of two widgets with window ratio 0.25 and 0.75 2173 /// nk_layout_row_begin(ctx, NK_DYNAMIC, 25, 2); 2174 /// nk_layout_row_push(ctx, 0.25f); 2175 /// nk_widget(...); 2176 /// nk_layout_row_push(ctx, 0.75f); 2177 /// nk_widget(...); 2178 /// nk_layout_row_end(ctx); 2179 /// // 2180 /// // third row with auto generated height: composed of two widgets with window ratio 0.25 and 0.75 2181 /// nk_layout_row_begin(ctx, NK_DYNAMIC, 0, 2); 2182 /// nk_layout_row_push(ctx, 0.25f); 2183 /// nk_widget(...); 2184 /// nk_layout_row_push(ctx, 0.75f); 2185 /// nk_widget(...); 2186 /// nk_layout_row_end(ctx); 2187 /// } 2188 /// nk_end(...); 2189 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2190 /// 2191 /// 4. __nk_layout_row__<br /><br /> 2192 /// The array counterpart to API nk_layout_row_xxx is the single nk_layout_row 2193 /// functions. Instead of pushing either pixel or window ratio for every widget 2194 /// it allows to define it by array. The trade of for less control is that 2195 /// `nk_layout_row` is automatically repeating. Otherwise the behavior is the 2196 /// same. 2197 /// 2198 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2199 /// if (nk_begin_xxx(...) { 2200 /// // two rows with height: 30 composed of two widgets with width 60 and 40 2201 /// const float size[] = {60,40}; 2202 /// nk_layout_row(ctx, NK_STATIC, 30, 2, ratio); 2203 /// nk_widget(...); 2204 /// nk_widget(...); 2205 /// nk_widget(...); 2206 /// nk_widget(...); 2207 /// // 2208 /// // two rows with height: 30 composed of two widgets with window ratio 0.25 and 0.75 2209 /// const float ratio[] = {0.25, 0.75}; 2210 /// nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratio); 2211 /// nk_widget(...); 2212 /// nk_widget(...); 2213 /// nk_widget(...); 2214 /// nk_widget(...); 2215 /// // 2216 /// // two rows with auto generated height composed of two widgets with window ratio 0.25 and 0.75 2217 /// const float ratio[] = {0.25, 0.75}; 2218 /// nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratio); 2219 /// nk_widget(...); 2220 /// nk_widget(...); 2221 /// nk_widget(...); 2222 /// nk_widget(...); 2223 /// } 2224 /// nk_end(...); 2225 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2226 /// 2227 /// 5. __nk_layout_row_template_xxx__<br /><br /> 2228 /// The most complex and second most flexible API is a simplified flexbox version without 2229 /// line wrapping and weights for dynamic widgets. It is an immediate mode API but 2230 /// unlike `nk_layout_row_xxx` it has auto repeat behavior and needs to be called 2231 /// before calling the templated widgets. 2232 /// The row template layout has three different per widget size specifier. The first 2233 /// one is the `nk_layout_row_template_push_static` with fixed widget pixel width. 2234 /// They do not grow if the row grows and will always stay the same. 2235 /// The second size specifier is `nk_layout_row_template_push_variable` 2236 /// which defines a minimum widget size but it also can grow if more space is available 2237 /// not taken by other widgets. 2238 /// Finally there are dynamic widgets with `nk_layout_row_template_push_dynamic` 2239 /// which are completely flexible and unlike variable widgets can even shrink 2240 /// to zero if not enough space is provided. 2241 /// 2242 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2243 /// if (nk_begin_xxx(...) { 2244 /// // two rows with height: 30 composed of three widgets 2245 /// nk_layout_row_template_begin(ctx, 30); 2246 /// nk_layout_row_template_push_dynamic(ctx); 2247 /// nk_layout_row_template_push_variable(ctx, 80); 2248 /// nk_layout_row_template_push_static(ctx, 80); 2249 /// nk_layout_row_template_end(ctx); 2250 /// // 2251 /// // first row 2252 /// nk_widget(...); // dynamic widget can go to zero if not enough space 2253 /// nk_widget(...); // variable widget with min 80 pixel but can grow bigger if enough space 2254 /// nk_widget(...); // static widget with fixed 80 pixel width 2255 /// // 2256 /// // second row same layout 2257 /// nk_widget(...); 2258 /// nk_widget(...); 2259 /// nk_widget(...); 2260 /// } 2261 /// nk_end(...); 2262 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2263 /// 2264 /// 6. __nk_layout_space_xxx__<br /><br /> 2265 /// Finally the most flexible API directly allows you to place widgets inside the 2266 /// window. The space layout API is an immediate mode API which does not support 2267 /// row auto repeat and directly sets position and size of a widget. Position 2268 /// and size hereby can be either specified as ratio of allocated space or 2269 /// allocated space local position and pixel size. Since this API is quite 2270 /// powerful there are a number of utility functions to get the available space 2271 /// and convert between local allocated space and screen space. 2272 /// 2273 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2274 /// if (nk_begin_xxx(...) { 2275 /// // static row with height: 500 (you can set column count to INT_MAX if you don't want to be bothered) 2276 /// nk_layout_space_begin(ctx, NK_STATIC, 500, INT_MAX); 2277 /// nk_layout_space_push(ctx, nk_rect(0,0,150,200)); 2278 /// nk_widget(...); 2279 /// nk_layout_space_push(ctx, nk_rect(200,200,100,200)); 2280 /// nk_widget(...); 2281 /// nk_layout_space_end(ctx); 2282 /// // 2283 /// // dynamic row with height: 500 (you can set column count to INT_MAX if you don't want to be bothered) 2284 /// nk_layout_space_begin(ctx, NK_DYNAMIC, 500, INT_MAX); 2285 /// nk_layout_space_push(ctx, nk_rect(0.5,0.5,0.1,0.1)); 2286 /// nk_widget(...); 2287 /// nk_layout_space_push(ctx, nk_rect(0.7,0.6,0.1,0.1)); 2288 /// nk_widget(...); 2289 /// } 2290 /// nk_end(...); 2291 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2292 /// 2293 /// #### Reference 2294 /// Function | Description 2295 /// ----------------------------------------|------------------------------------ 2296 /// nk_layout_set_min_row_height | Set the currently used minimum row height to a specified value 2297 /// nk_layout_reset_min_row_height | Resets the currently used minimum row height to font height 2298 /// nk_layout_widget_bounds | Calculates current width a static layout row can fit inside a window 2299 /// nk_layout_ratio_from_pixel | Utility functions to calculate window ratio from pixel size 2300 // 2301 /// nk_layout_row_dynamic | Current layout is divided into n same sized growing columns 2302 /// nk_layout_row_static | Current layout is divided into n same fixed sized columns 2303 /// nk_layout_row_begin | Starts a new row with given height and number of columns 2304 /// nk_layout_row_push | Pushes another column with given size or window ratio 2305 /// nk_layout_row_end | Finished previously started row 2306 /// nk_layout_row | Specifies row columns in array as either window ratio or size 2307 // 2308 /// nk_layout_row_template_begin | Begins the row template declaration 2309 /// nk_layout_row_template_push_dynamic | Adds a dynamic column that dynamically grows and can go to zero if not enough space 2310 /// nk_layout_row_template_push_variable | Adds a variable column that dynamically grows but does not shrink below specified pixel width 2311 /// nk_layout_row_template_push_static | Adds a static column that does not grow and will always have the same size 2312 /// nk_layout_row_template_end | Marks the end of the row template 2313 // 2314 /// nk_layout_space_begin | Begins a new layouting space that allows to specify each widgets position and size 2315 /// nk_layout_space_push | Pushes position and size of the next widget in own coordinate space either as pixel or ratio 2316 /// nk_layout_space_end | Marks the end of the layouting space 2317 // 2318 /// nk_layout_space_bounds | Callable after nk_layout_space_begin and returns total space allocated 2319 /// nk_layout_space_to_screen | Converts vector from nk_layout_space coordinate space into screen space 2320 /// nk_layout_space_to_local | Converts vector from screen space into nk_layout_space coordinates 2321 /// nk_layout_space_rect_to_screen | Converts rectangle from nk_layout_space coordinate space into screen space 2322 /// nk_layout_space_rect_to_local | Converts rectangle from screen space into nk_layout_space coordinates 2323 */ 2324 /*/// #### nk_layout_set_min_row_height 2325 /// Sets the currently used minimum row height. 2326 /// !!! WARNING 2327 /// The passed height needs to include both your preferred row height 2328 /// as well as padding. No internal padding is added. 2329 /// 2330 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2331 /// void nk_layout_set_min_row_height(struct nk_context*, float height); 2332 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2333 /// 2334 /// Parameter | Description 2335 /// ------------|----------------------------------------------------------- 2336 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2337 /// __height__ | New minimum row height to be used for auto generating the row height 2338 */ 2339 void nk_layout_set_min_row_height (nk_context*, float height); 2340 /*/// #### nk_layout_reset_min_row_height 2341 /// Reset the currently used minimum row height back to `font_height + text_padding + padding` 2342 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2343 /// void nk_layout_reset_min_row_height(struct nk_context*); 2344 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2345 /// 2346 /// Parameter | Description 2347 /// ------------|----------------------------------------------------------- 2348 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2349 */ 2350 void nk_layout_reset_min_row_height (nk_context*); 2351 /*/// #### nk_layout_widget_bounds 2352 /// Returns the width of the next row allocate by one of the layouting functions 2353 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2354 /// struct nk_rect nk_layout_widget_bounds(struct nk_context*); 2355 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2356 /// 2357 /// Parameter | Description 2358 /// ------------|----------------------------------------------------------- 2359 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2360 /// 2361 /// Return `nk_rect` with both position and size of the next row 2362 */ 2363 nk_rect_ nk_layout_widget_bounds (nk_context*); 2364 /*/// #### nk_layout_ratio_from_pixel 2365 /// Utility functions to calculate window ratio from pixel size 2366 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2367 /// float nk_layout_ratio_from_pixel(struct nk_context*, float pixel_width); 2368 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2369 /// 2370 /// Parameter | Description 2371 /// ------------|----------------------------------------------------------- 2372 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2373 /// __pixel__ | Pixel_width to convert to window ratio 2374 /// 2375 /// Returns `nk_rect` with both position and size of the next row 2376 */ 2377 float nk_layout_ratio_from_pixel (nk_context*, float pixel_width); 2378 /*/// #### nk_layout_row_dynamic 2379 /// Sets current row layout to share horizontal space 2380 /// between @cols number of widgets evenly. Once called all subsequent widget 2381 /// calls greater than @cols will allocate a new row with same layout. 2382 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2383 /// void nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols); 2384 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2385 /// 2386 /// Parameter | Description 2387 /// ------------|----------------------------------------------------------- 2388 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2389 /// __height__ | Holds height of each widget in row or zero for auto layouting 2390 /// __columns__ | Number of widget inside row 2391 */ 2392 void nk_layout_row_dynamic (nk_context* ctx, float height, int cols); 2393 /*/// #### nk_layout_row_static 2394 /// Sets current row layout to fill @cols number of widgets 2395 /// in row with same @item_width horizontal size. Once called all subsequent widget 2396 /// calls greater than @cols will allocate a new row with same layout. 2397 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2398 /// void nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols); 2399 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2400 /// 2401 /// Parameter | Description 2402 /// ------------|----------------------------------------------------------- 2403 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2404 /// __height__ | Holds height of each widget in row or zero for auto layouting 2405 /// __width__ | Holds pixel width of each widget in the row 2406 /// __columns__ | Number of widget inside row 2407 */ 2408 void nk_layout_row_static (nk_context* ctx, float height, int item_width, int cols); 2409 /*/// #### nk_layout_row_begin 2410 /// Starts a new dynamic or fixed row with given height and columns. 2411 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2412 /// void nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, float row_height, int cols); 2413 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2414 /// 2415 /// Parameter | Description 2416 /// ------------|----------------------------------------------------------- 2417 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2418 /// __fmt__ | either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns 2419 /// __height__ | holds height of each widget in row or zero for auto layouting 2420 /// __columns__ | Number of widget inside row 2421 */ 2422 void nk_layout_row_begin (nk_context* ctx, nk_layout_format fmt, float row_height, int cols); 2423 /*/// #### nk_layout_row_push 2424 /// Specifies either window ratio or width of a single column 2425 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2426 /// void nk_layout_row_push(struct nk_context*, float value); 2427 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2428 /// 2429 /// Parameter | Description 2430 /// ------------|----------------------------------------------------------- 2431 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2432 /// __value__ | either a window ratio or fixed width depending on @fmt in previous `nk_layout_row_begin` call 2433 */ 2434 void nk_layout_row_push (nk_context*, float value); 2435 /*/// #### nk_layout_row_end 2436 /// Finished previously started row 2437 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2438 /// void nk_layout_row_end(struct nk_context*); 2439 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2440 /// 2441 /// Parameter | Description 2442 /// ------------|----------------------------------------------------------- 2443 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2444 */ 2445 void nk_layout_row_end (nk_context*); 2446 /*/// #### nk_layout_row 2447 /// Specifies row columns in array as either window ratio or size 2448 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2449 /// void nk_layout_row(struct nk_context*, enum nk_layout_format, float height, int cols, const float *ratio); 2450 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2451 /// 2452 /// Parameter | Description 2453 /// ------------|----------------------------------------------------------- 2454 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2455 /// __fmt__ | Either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns 2456 /// __height__ | Holds height of each widget in row or zero for auto layouting 2457 /// __columns__ | Number of widget inside row 2458 */ 2459 void nk_layout_row (nk_context*, nk_layout_format, float height, int cols, const(float)* ratio); 2460 /*/// #### nk_layout_row_template_begin 2461 /// Begins the row template declaration 2462 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2463 /// void nk_layout_row_template_begin(struct nk_context*, float row_height); 2464 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2465 /// 2466 /// Parameter | Description 2467 /// ------------|----------------------------------------------------------- 2468 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2469 /// __height__ | Holds height of each widget in row or zero for auto layouting 2470 */ 2471 void nk_layout_row_template_begin (nk_context*, float row_height); 2472 /*/// #### nk_layout_row_template_push_dynamic 2473 /// Adds a dynamic column that dynamically grows and can go to zero if not enough space 2474 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2475 /// void nk_layout_row_template_push_dynamic(struct nk_context*); 2476 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2477 /// 2478 /// Parameter | Description 2479 /// ------------|----------------------------------------------------------- 2480 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2481 /// __height__ | Holds height of each widget in row or zero for auto layouting 2482 */ 2483 void nk_layout_row_template_push_dynamic (nk_context*); 2484 /*/// #### nk_layout_row_template_push_variable 2485 /// Adds a variable column that dynamically grows but does not shrink below specified pixel width 2486 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2487 /// void nk_layout_row_template_push_variable(struct nk_context*, float min_width); 2488 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2489 /// 2490 /// Parameter | Description 2491 /// ------------|----------------------------------------------------------- 2492 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2493 /// __width__ | Holds the minimum pixel width the next column must always be 2494 */ 2495 void nk_layout_row_template_push_variable (nk_context*, float min_width); 2496 /*/// #### nk_layout_row_template_push_static 2497 /// Adds a static column that does not grow and will always have the same size 2498 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2499 /// void nk_layout_row_template_push_static(struct nk_context*, float width); 2500 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2501 /// 2502 /// Parameter | Description 2503 /// ------------|----------------------------------------------------------- 2504 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2505 /// __width__ | Holds the absolute pixel width value the next column must be 2506 */ 2507 void nk_layout_row_template_push_static (nk_context*, float width); 2508 /*/// #### nk_layout_row_template_end 2509 /// Marks the end of the row template 2510 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2511 /// void nk_layout_row_template_end(struct nk_context*); 2512 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2513 /// 2514 /// Parameter | Description 2515 /// ------------|----------------------------------------------------------- 2516 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2517 */ 2518 void nk_layout_row_template_end (nk_context*); 2519 /*/// #### nk_layout_space_begin 2520 /// Begins a new layouting space that allows to specify each widgets position and size. 2521 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2522 /// void nk_layout_space_begin(struct nk_context*, enum nk_layout_format, float height, int widget_count); 2523 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2524 /// 2525 /// Parameter | Description 2526 /// ------------|----------------------------------------------------------- 2527 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx` 2528 /// __fmt__ | Either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns 2529 /// __height__ | Holds height of each widget in row or zero for auto layouting 2530 /// __columns__ | Number of widgets inside row 2531 */ 2532 void nk_layout_space_begin (nk_context*, nk_layout_format, float height, int widget_count); 2533 /*/// #### nk_layout_space_push 2534 /// Pushes position and size of the next widget in own coordinate space either as pixel or ratio 2535 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2536 /// void nk_layout_space_push(struct nk_context *ctx, struct nk_rect bounds); 2537 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2538 /// 2539 /// Parameter | Description 2540 /// ------------|----------------------------------------------------------- 2541 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` 2542 /// __bounds__ | Position and size in laoyut space local coordinates 2543 */ 2544 void nk_layout_space_push (nk_context*, nk_rect_ bounds); 2545 /*/// #### nk_layout_space_end 2546 /// Marks the end of the layout space 2547 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2548 /// void nk_layout_space_end(struct nk_context*); 2549 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2550 /// 2551 /// Parameter | Description 2552 /// ------------|----------------------------------------------------------- 2553 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` 2554 */ 2555 void nk_layout_space_end (nk_context*); 2556 /*/// #### nk_layout_space_bounds 2557 /// Utility function to calculate total space allocated for `nk_layout_space` 2558 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2559 /// struct nk_rect nk_layout_space_bounds(struct nk_context*); 2560 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2561 /// 2562 /// Parameter | Description 2563 /// ------------|----------------------------------------------------------- 2564 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` 2565 /// 2566 /// Returns `nk_rect` holding the total space allocated 2567 */ 2568 nk_rect_ nk_layout_space_bounds (nk_context*); 2569 /*/// #### nk_layout_space_to_screen 2570 /// Converts vector from nk_layout_space coordinate space into screen space 2571 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2572 /// struct nk_vec2 nk_layout_space_to_screen(struct nk_context*, struct nk_vec2); 2573 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2574 /// 2575 /// Parameter | Description 2576 /// ------------|----------------------------------------------------------- 2577 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` 2578 /// __vec__ | Position to convert from layout space into screen coordinate space 2579 /// 2580 /// Returns transformed `nk_vec2` in screen space coordinates 2581 */ 2582 nk_vec2_ nk_layout_space_to_screen (nk_context*, nk_vec2_); 2583 /*/// #### nk_layout_space_to_local 2584 /// Converts vector from layout space into screen space 2585 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2586 /// struct nk_vec2 nk_layout_space_to_local(struct nk_context*, struct nk_vec2); 2587 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2588 /// 2589 /// Parameter | Description 2590 /// ------------|----------------------------------------------------------- 2591 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` 2592 /// __vec__ | Position to convert from screen space into layout coordinate space 2593 /// 2594 /// Returns transformed `nk_vec2` in layout space coordinates 2595 */ 2596 nk_vec2_ nk_layout_space_to_local (nk_context*, nk_vec2_); 2597 /*/// #### nk_layout_space_rect_to_screen 2598 /// Converts rectangle from screen space into layout space 2599 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2600 /// struct nk_rect nk_layout_space_rect_to_screen(struct nk_context*, struct nk_rect); 2601 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2602 /// 2603 /// Parameter | Description 2604 /// ------------|----------------------------------------------------------- 2605 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` 2606 /// __bounds__ | Rectangle to convert from layout space into screen space 2607 /// 2608 /// Returns transformed `nk_rect` in screen space coordinates 2609 */ 2610 nk_rect_ nk_layout_space_rect_to_screen (nk_context*, nk_rect_); 2611 /*/// #### nk_layout_space_rect_to_local 2612 /// Converts rectangle from layout space into screen space 2613 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2614 /// struct nk_rect nk_layout_space_rect_to_local(struct nk_context*, struct nk_rect); 2615 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2616 /// 2617 /// Parameter | Description 2618 /// ------------|----------------------------------------------------------- 2619 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` 2620 /// __bounds__ | Rectangle to convert from layout space into screen space 2621 /// 2622 /// Returns transformed `nk_rect` in layout space coordinates 2623 */ 2624 nk_rect_ nk_layout_space_rect_to_local (nk_context*, nk_rect_); 2625 2626 /*/// #### nk_spacer 2627 /// Spacer is a dummy widget that consumes space as usual but doesn't draw anything 2628 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2629 /// void nk_spacer(struct nk_context* ); 2630 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2631 /// 2632 /// Parameter | Description 2633 /// ------------|----------------------------------------------------------- 2634 /// __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin` 2635 /// 2636 */ 2637 void nk_spacer (nk_context*); 2638 2639 /* ============================================================================= 2640 * 2641 * GROUP 2642 * 2643 * ============================================================================= 2644 /// ### Groups 2645 /// Groups are basically windows inside windows. They allow to subdivide space 2646 /// in a window to layout widgets as a group. Almost all more complex widget 2647 /// layouting requirements can be solved using groups and basic layouting 2648 /// fuctionality. Groups just like windows are identified by an unique name and 2649 /// internally keep track of scrollbar offsets by default. However additional 2650 /// versions are provided to directly manage the scrollbar. 2651 /// 2652 /// #### Usage 2653 /// To create a group you have to call one of the three `nk_group_begin_xxx` 2654 /// functions to start group declarations and `nk_group_end` at the end. Furthermore it 2655 /// is required to check the return value of `nk_group_begin_xxx` and only process 2656 /// widgets inside the window if the value is not 0. 2657 /// Nesting groups is possible and even encouraged since many layouting schemes 2658 /// can only be achieved by nesting. Groups, unlike windows, need `nk_group_end` 2659 /// to be only called if the corresponding `nk_group_begin_xxx` call does not return 0: 2660 /// 2661 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2662 /// if (nk_group_begin_xxx(ctx, ...) { 2663 /// // [... widgets ...] 2664 /// nk_group_end(ctx); 2665 /// } 2666 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2667 /// 2668 /// In the grand concept groups can be called after starting a window 2669 /// with `nk_begin_xxx` and before calling `nk_end`: 2670 /// 2671 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2672 /// struct nk_context ctx; 2673 /// nk_init_xxx(&ctx, ...); 2674 /// while (1) { 2675 /// // Input 2676 /// Event evt; 2677 /// nk_input_begin(&ctx); 2678 /// while (GetEvent(&evt)) { 2679 /// if (evt.type == MOUSE_MOVE) 2680 /// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); 2681 /// else if (evt.type == [...]) { 2682 /// nk_input_xxx(...); 2683 /// } 2684 /// } 2685 /// nk_input_end(&ctx); 2686 /// // 2687 /// // Window 2688 /// if (nk_begin_xxx(...) { 2689 /// // [...widgets...] 2690 /// nk_layout_row_dynamic(...); 2691 /// if (nk_group_begin_xxx(ctx, ...) { 2692 /// //[... widgets ...] 2693 /// nk_group_end(ctx); 2694 /// } 2695 /// } 2696 /// nk_end(ctx); 2697 /// // 2698 /// // Draw 2699 /// const struct nk_command *cmd = 0; 2700 /// nk_foreach(cmd, &ctx) { 2701 /// switch (cmd->type) { 2702 /// case NK_COMMAND_LINE: 2703 /// your_draw_line_function(...) 2704 /// break; 2705 /// case NK_COMMAND_RECT 2706 /// your_draw_rect_function(...) 2707 /// break; 2708 /// case ...: 2709 /// // [...] 2710 /// } 2711 /// nk_clear(&ctx); 2712 /// } 2713 /// nk_free(&ctx); 2714 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2715 /// #### Reference 2716 /// Function | Description 2717 /// --------------------------------|------------------------------------------- 2718 /// nk_group_begin | Start a new group with internal scrollbar handling 2719 /// nk_group_begin_titled | Start a new group with separated name and title and internal scrollbar handling 2720 /// nk_group_end | Ends a group. Should only be called if nk_group_begin returned non-zero 2721 /// nk_group_scrolled_offset_begin | Start a new group with manual separated handling of scrollbar x- and y-offset 2722 /// nk_group_scrolled_begin | Start a new group with manual scrollbar handling 2723 /// nk_group_scrolled_end | Ends a group with manual scrollbar handling. Should only be called if nk_group_begin returned non-zero 2724 /// nk_group_get_scroll | Gets the scroll offset for the given group 2725 /// nk_group_set_scroll | Sets the scroll offset for the given group 2726 */ 2727 /*/// #### nk_group_begin 2728 /// Starts a new widget group. Requires a previous layouting function to specify a pos/size. 2729 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2730 /// nk_bool nk_group_begin(struct nk_context*, const char *title, nk_flags); 2731 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2732 /// 2733 /// Parameter | Description 2734 /// ------------|----------------------------------------------------------- 2735 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2736 /// __title__ | Must be an unique identifier for this group that is also used for the group header 2737 /// __flags__ | Window flags defined in the nk_panel_flags section with a number of different group behaviors 2738 /// 2739 /// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise 2740 */ 2741 nk_bool nk_group_begin (nk_context*, const(char)* title, nk_flags); 2742 /*/// #### nk_group_begin_titled 2743 /// Starts a new widget group. Requires a previous layouting function to specify a pos/size. 2744 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2745 /// nk_bool nk_group_begin_titled(struct nk_context*, const char *name, const char *title, nk_flags); 2746 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2747 /// 2748 /// Parameter | Description 2749 /// ------------|----------------------------------------------------------- 2750 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2751 /// __id__ | Must be an unique identifier for this group 2752 /// __title__ | Group header title 2753 /// __flags__ | Window flags defined in the nk_panel_flags section with a number of different group behaviors 2754 /// 2755 /// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise 2756 */ 2757 nk_bool nk_group_begin_titled (nk_context*, const(char)* name, const(char)* title, nk_flags); 2758 /*/// #### nk_group_end 2759 /// Ends a widget group 2760 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2761 /// void nk_group_end(struct nk_context*); 2762 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2763 /// 2764 /// Parameter | Description 2765 /// ------------|----------------------------------------------------------- 2766 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2767 */ 2768 void nk_group_end (nk_context*); 2769 /*/// #### nk_group_scrolled_offset_begin 2770 /// starts a new widget group. requires a previous layouting function to specify 2771 /// a size. Does not keep track of scrollbar. 2772 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2773 /// nk_bool nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags); 2774 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2775 /// 2776 /// Parameter | Description 2777 /// ------------|----------------------------------------------------------- 2778 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2779 /// __x_offset__| Scrollbar x-offset to offset all widgets inside the group horizontally. 2780 /// __y_offset__| Scrollbar y-offset to offset all widgets inside the group vertically 2781 /// __title__ | Window unique group title used to both identify and display in the group header 2782 /// __flags__ | Window flags from the nk_panel_flags section 2783 /// 2784 /// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise 2785 */ 2786 nk_bool nk_group_scrolled_offset_begin (nk_context*, nk_uint* x_offset, nk_uint* y_offset, const(char)* title, nk_flags flags); 2787 /*/// #### nk_group_scrolled_begin 2788 /// Starts a new widget group. requires a previous 2789 /// layouting function to specify a size. Does not keep track of scrollbar. 2790 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2791 /// nk_bool nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, const char *title, nk_flags); 2792 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2793 /// 2794 /// Parameter | Description 2795 /// ------------|----------------------------------------------------------- 2796 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2797 /// __off__ | Both x- and y- scroll offset. Allows for manual scrollbar control 2798 /// __title__ | Window unique group title used to both identify and display in the group header 2799 /// __flags__ | Window flags from nk_panel_flags section 2800 /// 2801 /// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise 2802 */ 2803 nk_bool nk_group_scrolled_begin (nk_context*, nk_scroll* off, const(char)* title, nk_flags); 2804 /*/// #### nk_group_scrolled_end 2805 /// Ends a widget group after calling nk_group_scrolled_offset_begin or nk_group_scrolled_begin. 2806 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2807 /// void nk_group_scrolled_end(struct nk_context*); 2808 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2809 /// 2810 /// Parameter | Description 2811 /// ------------|----------------------------------------------------------- 2812 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2813 */ 2814 void nk_group_scrolled_end (nk_context*); 2815 /*/// #### nk_group_get_scroll 2816 /// Gets the scroll position of the given group. 2817 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2818 /// void nk_group_get_scroll(struct nk_context*, const char *id, nk_uint *x_offset, nk_uint *y_offset); 2819 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2820 /// 2821 /// Parameter | Description 2822 /// -------------|----------------------------------------------------------- 2823 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2824 /// __id__ | The id of the group to get the scroll position of 2825 /// __x_offset__ | A pointer to the x offset output (or NULL to ignore) 2826 /// __y_offset__ | A pointer to the y offset output (or NULL to ignore) 2827 */ 2828 void nk_group_get_scroll (nk_context*, const(char)* id, nk_uint* x_offset, nk_uint* y_offset); 2829 /*/// #### nk_group_set_scroll 2830 /// Sets the scroll position of the given group. 2831 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2832 /// void nk_group_set_scroll(struct nk_context*, const char *id, nk_uint x_offset, nk_uint y_offset); 2833 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2834 /// 2835 /// Parameter | Description 2836 /// -------------|----------------------------------------------------------- 2837 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2838 /// __id__ | The id of the group to scroll 2839 /// __x_offset__ | The x offset to scroll to 2840 /// __y_offset__ | The y offset to scroll to 2841 */ 2842 void nk_group_set_scroll (nk_context*, const(char)* id, nk_uint x_offset, nk_uint y_offset); 2843 /* ============================================================================= 2844 * 2845 * TREE 2846 * 2847 * ============================================================================= 2848 /// ### Tree 2849 /// Trees represent two different concept. First the concept of a collapsible 2850 /// UI section that can be either in a hidden or visible state. They allow the UI 2851 /// user to selectively minimize the current set of visible UI to comprehend. 2852 /// The second concept are tree widgets for visual UI representation of trees.<br /><br /> 2853 /// 2854 /// Trees thereby can be nested for tree representations and multiple nested 2855 /// collapsible UI sections. All trees are started by calling of the 2856 /// `nk_tree_xxx_push_tree` functions and ended by calling one of the 2857 /// `nk_tree_xxx_pop_xxx()` functions. Each starting functions takes a title label 2858 /// and optionally an image to be displayed and the initial collapse state from 2859 /// the nk_collapse_states section.<br /><br /> 2860 /// 2861 /// The runtime state of the tree is either stored outside the library by the caller 2862 /// or inside which requires a unique ID. The unique ID can either be generated 2863 /// automatically from `__FILE__` and `__LINE__` with function `nk_tree_push`, 2864 /// by `__FILE__` and a user provided ID generated for example by loop index with 2865 /// function `nk_tree_push_id` or completely provided from outside by user with 2866 /// function `nk_tree_push_hashed`. 2867 /// 2868 /// #### Usage 2869 /// To create a tree you have to call one of the seven `nk_tree_xxx_push_xxx` 2870 /// functions to start a collapsible UI section and `nk_tree_xxx_pop` to mark the 2871 /// end. 2872 /// Each starting function will either return `false(0)` if the tree is collapsed 2873 /// or hidden and therefore does not need to be filled with content or `true(1)` 2874 /// if visible and required to be filled. 2875 /// 2876 /// !!! Note 2877 /// The tree header does not require and layouting function and instead 2878 /// calculates a auto height based on the currently used font size 2879 /// 2880 /// The tree ending functions only need to be called if the tree content is 2881 /// actually visible. So make sure the tree push function is guarded by `if` 2882 /// and the pop call is only taken if the tree is visible. 2883 /// 2884 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2885 /// if (nk_tree_push(ctx, NK_TREE_TAB, "Tree", NK_MINIMIZED)) { 2886 /// nk_layout_row_dynamic(...); 2887 /// nk_widget(...); 2888 /// nk_tree_pop(ctx); 2889 /// } 2890 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2891 /// 2892 /// #### Reference 2893 /// Function | Description 2894 /// ----------------------------|------------------------------------------- 2895 /// nk_tree_push | Start a collapsible UI section with internal state management 2896 /// nk_tree_push_id | Start a collapsible UI section with internal state management callable in a look 2897 /// nk_tree_push_hashed | Start a collapsible UI section with internal state management with full control over internal unique ID use to store state 2898 /// nk_tree_image_push | Start a collapsible UI section with image and label header 2899 /// nk_tree_image_push_id | Start a collapsible UI section with image and label header and internal state management callable in a look 2900 /// nk_tree_image_push_hashed | Start a collapsible UI section with image and label header and internal state management with full control over internal unique ID use to store state 2901 /// nk_tree_pop | Ends a collapsible UI section 2902 // 2903 /// nk_tree_state_push | Start a collapsible UI section with external state management 2904 /// nk_tree_state_image_push | Start a collapsible UI section with image and label header and external state management 2905 /// nk_tree_state_pop | Ends a collapsabale UI section 2906 /// 2907 /// #### nk_tree_type 2908 /// Flag | Description 2909 /// ----------------|---------------------------------------- 2910 /// NK_TREE_NODE | Highlighted tree header to mark a collapsible UI section 2911 /// NK_TREE_TAB | Non-highlighted tree header closer to tree representations 2912 */ 2913 /*/// #### nk_tree_push 2914 /// Starts a collapsible UI section with internal state management 2915 /// !!! WARNING 2916 /// To keep track of the runtime tree collapsible state this function uses 2917 /// defines `__FILE__` and `__LINE__` to generate a unique ID. If you want 2918 /// to call this function in a loop please use `nk_tree_push_id` or 2919 /// `nk_tree_push_hashed` instead. 2920 /// 2921 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2922 /// #define nk_tree_push(ctx, type, title, state) 2923 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2924 /// 2925 /// Parameter | Description 2926 /// ------------|----------------------------------------------------------- 2927 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2928 /// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node 2929 /// __title__ | Label printed in the tree header 2930 /// __state__ | Initial tree state value out of nk_collapse_states 2931 /// 2932 /// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise 2933 */ 2934 extern (D) auto nk_tree_push(T0, T1, T2, T3)(auto ref T0 ctx, auto ref T1 type, auto ref T2 title, auto ref T3 state) 2935 { 2936 return nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE, nk_strlen(NK_FILE_LINE), __LINE__); 2937 } 2938 2939 /*/// #### nk_tree_push_id 2940 /// Starts a collapsible UI section with internal state management callable in a look 2941 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2942 /// #define nk_tree_push_id(ctx, type, title, state, id) 2943 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2944 /// 2945 /// Parameter | Description 2946 /// ------------|----------------------------------------------------------- 2947 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2948 /// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node 2949 /// __title__ | Label printed in the tree header 2950 /// __state__ | Initial tree state value out of nk_collapse_states 2951 /// __id__ | Loop counter index if this function is called in a loop 2952 /// 2953 /// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise 2954 */ 2955 extern (D) auto nk_tree_push_id(T0, T1, T2, T3, T4)(auto ref T0 ctx, auto ref T1 type, auto ref T2 title, auto ref T3 state, auto ref T4 id) 2956 { 2957 return nk_tree_push_hashed(ctx, type, title, state, NK_FILE_LINE, nk_strlen(NK_FILE_LINE), id); 2958 } 2959 2960 /*/// #### nk_tree_push_hashed 2961 /// Start a collapsible UI section with internal state management with full 2962 /// control over internal unique ID used to store state 2963 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2964 /// nk_bool nk_tree_push_hashed(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); 2965 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2966 /// 2967 /// Parameter | Description 2968 /// ------------|----------------------------------------------------------- 2969 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2970 /// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node 2971 /// __title__ | Label printed in the tree header 2972 /// __state__ | Initial tree state value out of nk_collapse_states 2973 /// __hash__ | Memory block or string to generate the ID from 2974 /// __len__ | Size of passed memory block or string in __hash__ 2975 /// __seed__ | Seeding value if this function is called in a loop or default to `0` 2976 /// 2977 /// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise 2978 */ 2979 nk_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); 2980 /*/// #### nk_tree_image_push 2981 /// Start a collapsible UI section with image and label header 2982 /// !!! WARNING 2983 /// To keep track of the runtime tree collapsible state this function uses 2984 /// defines `__FILE__` and `__LINE__` to generate a unique ID. If you want 2985 /// to call this function in a loop please use `nk_tree_image_push_id` or 2986 /// `nk_tree_image_push_hashed` instead. 2987 /// 2988 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 2989 /// #define nk_tree_image_push(ctx, type, img, title, state) 2990 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2991 // 2992 /// Parameter | Description 2993 /// ------------|----------------------------------------------------------- 2994 /// __ctx__ | Must point to an previously initialized `nk_context` struct 2995 /// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node 2996 /// __img__ | Image to display inside the header on the left of the label 2997 /// __title__ | Label printed in the tree header 2998 /// __state__ | Initial tree state value out of nk_collapse_states 2999 /// 3000 /// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise 3001 */ 3002 extern (D) auto nk_tree_image_push(T0, T1, T2, T3, T4)(auto ref T0 ctx, auto ref T1 type, auto ref T2 img, auto ref T3 title, auto ref T4 state) 3003 { 3004 return nk_tree_image_push_hashed(ctx, type, img, title, state, NK_FILE_LINE, nk_strlen(NK_FILE_LINE), __LINE__); 3005 } 3006 3007 /*/// #### nk_tree_image_push_id 3008 /// Start a collapsible UI section with image and label header and internal state 3009 /// management callable in a look 3010 /// 3011 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 3012 /// #define nk_tree_image_push_id(ctx, type, img, title, state, id) 3013 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3014 /// 3015 /// Parameter | Description 3016 /// ------------|----------------------------------------------------------- 3017 /// __ctx__ | Must point to an previously initialized `nk_context` struct 3018 /// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node 3019 /// __img__ | Image to display inside the header on the left of the label 3020 /// __title__ | Label printed in the tree header 3021 /// __state__ | Initial tree state value out of nk_collapse_states 3022 /// __id__ | Loop counter index if this function is called in a loop 3023 /// 3024 /// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise 3025 */ 3026 extern (D) auto nk_tree_image_push_id(T0, T1, T2, T3, T4, T5)(auto ref T0 ctx, auto ref T1 type, auto ref T2 img, auto ref T3 title, auto ref T4 state, auto ref T5 id) 3027 { 3028 return nk_tree_image_push_hashed(ctx, type, img, title, state, NK_FILE_LINE, nk_strlen(NK_FILE_LINE), id); 3029 } 3030 3031 /*/// #### nk_tree_image_push_hashed 3032 /// Start a collapsible UI section with internal state management with full 3033 /// control over internal unique ID used to store state 3034 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 3035 /// nk_bool nk_tree_image_push_hashed(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states initial_state, const char *hash, int len,int seed); 3036 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3037 /// 3038 /// Parameter | Description 3039 /// ------------|----------------------------------------------------------- 3040 /// __ctx__ | Must point to an previously initialized `nk_context` struct 3041 /// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node 3042 /// __img__ | Image to display inside the header on the left of the label 3043 /// __title__ | Label printed in the tree header 3044 /// __state__ | Initial tree state value out of nk_collapse_states 3045 /// __hash__ | Memory block or string to generate the ID from 3046 /// __len__ | Size of passed memory block or string in __hash__ 3047 /// __seed__ | Seeding value if this function is called in a loop or default to `0` 3048 /// 3049 /// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise 3050 */ 3051 nk_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); 3052 /*/// #### nk_tree_pop 3053 /// Ends a collapsabale UI section 3054 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 3055 /// void nk_tree_pop(struct nk_context*); 3056 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3057 /// 3058 /// Parameter | Description 3059 /// ------------|----------------------------------------------------------- 3060 /// __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` 3061 */ 3062 void nk_tree_pop (nk_context*); 3063 /*/// #### nk_tree_state_push 3064 /// Start a collapsible UI section with external state management 3065 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 3066 /// nk_bool nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state); 3067 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3068 /// 3069 /// Parameter | Description 3070 /// ------------|----------------------------------------------------------- 3071 /// __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` 3072 /// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node 3073 /// __title__ | Label printed in the tree header 3074 /// __state__ | Persistent state to update 3075 /// 3076 /// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise 3077 */ 3078 nk_bool nk_tree_state_push (nk_context*, nk_tree_type, const(char)* title, nk_collapse_states* state); 3079 /*/// #### nk_tree_state_image_push 3080 /// Start a collapsible UI section with image and label header and external state management 3081 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 3082 /// nk_bool nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state); 3083 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3084 /// 3085 /// Parameter | Description 3086 /// ------------|----------------------------------------------------------- 3087 /// __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` 3088 /// __img__ | Image to display inside the header on the left of the label 3089 /// __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node 3090 /// __title__ | Label printed in the tree header 3091 /// __state__ | Persistent state to update 3092 /// 3093 /// Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise 3094 */ 3095 nk_bool nk_tree_state_image_push (nk_context*, nk_tree_type, nk_image_, const(char)* title, nk_collapse_states* state); 3096 /*/// #### nk_tree_state_pop 3097 /// Ends a collapsabale UI section 3098 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 3099 /// void nk_tree_state_pop(struct nk_context*); 3100 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3101 /// 3102 /// Parameter | Description 3103 /// ------------|----------------------------------------------------------- 3104 /// __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx` 3105 */ 3106 void nk_tree_state_pop (nk_context*); 3107 3108 extern (D) auto nk_tree_element_push(T0, T1, T2, T3, T4)(auto ref T0 ctx, auto ref T1 type, auto ref T2 title, auto ref T3 state, auto ref T4 sel) 3109 { 3110 return nk_tree_element_push_hashed(ctx, type, title, state, sel, NK_FILE_LINE, nk_strlen(NK_FILE_LINE), __LINE__); 3111 } 3112 3113 extern (D) auto nk_tree_element_push_id(T0, T1, T2, T3, T4, T5)(auto ref T0 ctx, auto ref T1 type, auto ref T2 title, auto ref T3 state, auto ref T4 sel, auto ref T5 id) 3114 { 3115 return nk_tree_element_push_hashed(ctx, type, title, state, sel, NK_FILE_LINE, nk_strlen(NK_FILE_LINE), id); 3116 } 3117 3118 nk_bool nk_tree_element_push_hashed (nk_context*, nk_tree_type, const(char)* title, nk_collapse_states initial_state, nk_bool* selected, const(char)* hash, int len, int seed); 3119 nk_bool nk_tree_element_image_push_hashed (nk_context*, nk_tree_type, nk_image_, const(char)* title, nk_collapse_states initial_state, nk_bool* selected, const(char)* hash, int len, int seed); 3120 void nk_tree_element_pop (nk_context*); 3121 3122 /* ============================================================================= 3123 * 3124 * LIST VIEW 3125 * 3126 * ============================================================================= */ 3127 struct nk_list_view 3128 { 3129 /* public: */ 3130 int begin; 3131 int end; 3132 int count; 3133 /* private: */ 3134 int total_height; 3135 nk_context* ctx; 3136 nk_uint* scroll_pointer; 3137 nk_uint scroll_value; 3138 } 3139 3140 nk_bool nk_list_view_begin (nk_context*, nk_list_view* out_, const(char)* id, nk_flags, int row_height, int row_count); 3141 void nk_list_view_end (nk_list_view*); 3142 /* ============================================================================= 3143 * 3144 * WIDGET 3145 * 3146 * ============================================================================= */ 3147 enum nk_widget_layout_states 3148 { 3149 NK_WIDGET_INVALID = 0, /* The widget cannot be seen and is completely out of view */ 3150 NK_WIDGET_VALID = 1, /* The widget is completely inside the window and can be updated and drawn */ 3151 NK_WIDGET_ROM = 2 /* The widget is partially visible and cannot be updated */ 3152 } 3153 3154 enum nk_widget_states 3155 { 3156 NK_WIDGET_STATE_MODIFIED = NK_FLAG(1), 3157 NK_WIDGET_STATE_INACTIVE = NK_FLAG(2), /* widget is neither active nor hovered */ 3158 NK_WIDGET_STATE_ENTERED = NK_FLAG(3), /* widget has been hovered on the current frame */ 3159 NK_WIDGET_STATE_HOVER = NK_FLAG(4), /* widget is being hovered */ 3160 NK_WIDGET_STATE_ACTIVED = NK_FLAG(5), /* widget is currently activated */ 3161 NK_WIDGET_STATE_LEFT = NK_FLAG(6), /* widget is from this frame on not hovered anymore */ 3162 NK_WIDGET_STATE_HOVERED = NK_WIDGET_STATE_HOVER | NK_WIDGET_STATE_MODIFIED, /* widget is being hovered */ 3163 NK_WIDGET_STATE_ACTIVE = NK_WIDGET_STATE_ACTIVED | NK_WIDGET_STATE_MODIFIED /* widget is currently activated */ 3164 } 3165 3166 nk_widget_layout_states nk_widget (nk_rect_*, const(nk_context)*); 3167 nk_widget_layout_states nk_widget_fitting (nk_rect_*, nk_context*, nk_vec2_); 3168 nk_rect_ nk_widget_bounds (nk_context*); 3169 nk_vec2_ nk_widget_position (nk_context*); 3170 nk_vec2_ nk_widget_size (nk_context*); 3171 float nk_widget_width (nk_context*); 3172 float nk_widget_height (nk_context*); 3173 nk_bool nk_widget_is_hovered (nk_context*); 3174 nk_bool nk_widget_is_mouse_clicked (nk_context*, nk_buttons); 3175 nk_bool nk_widget_has_mouse_click_down (nk_context*, nk_buttons, nk_bool down); 3176 void nk_spacing (nk_context*, int cols); 3177 /* ============================================================================= 3178 * 3179 * TEXT 3180 * 3181 * ============================================================================= */ 3182 enum nk_text_align 3183 { 3184 NK_TEXT_ALIGN_LEFT = 0x01, 3185 NK_TEXT_ALIGN_CENTERED = 0x02, 3186 NK_TEXT_ALIGN_RIGHT = 0x04, 3187 NK_TEXT_ALIGN_TOP = 0x08, 3188 NK_TEXT_ALIGN_MIDDLE = 0x10, 3189 NK_TEXT_ALIGN_BOTTOM = 0x20 3190 } 3191 3192 enum nk_text_alignment 3193 { 3194 NK_TEXT_LEFT = nk_text_align.NK_TEXT_ALIGN_MIDDLE | nk_text_align.NK_TEXT_ALIGN_LEFT, 3195 NK_TEXT_CENTERED = nk_text_align.NK_TEXT_ALIGN_MIDDLE | nk_text_align.NK_TEXT_ALIGN_CENTERED, 3196 NK_TEXT_RIGHT = nk_text_align.NK_TEXT_ALIGN_MIDDLE | nk_text_align.NK_TEXT_ALIGN_RIGHT 3197 } 3198 3199 void nk_text (nk_context*, const(char)*, int, nk_flags); 3200 void nk_text_colored (nk_context*, const(char)*, int, nk_flags, nk_color); 3201 void nk_text_wrap (nk_context*, const(char)*, int); 3202 void nk_text_wrap_colored (nk_context*, const(char)*, int, nk_color); 3203 void nk_label (nk_context*, const(char)*, nk_flags align_); 3204 void nk_label_colored (nk_context*, const(char)*, nk_flags align_, nk_color); 3205 void nk_label_wrap (nk_context*, const(char)*); 3206 void nk_label_colored_wrap (nk_context*, const(char)*, nk_color); 3207 void nk_image (nk_context*, nk_image_); 3208 void nk_image_color (nk_context*, nk_image_, nk_color); 3209 3210 /* ============================================================================= 3211 * 3212 * BUTTON 3213 * 3214 * ============================================================================= */ 3215 nk_bool nk_button_text (nk_context*, const(char)* title, int len); 3216 nk_bool nk_button_label (nk_context*, const(char)* title); 3217 nk_bool nk_button_color (nk_context*, nk_color); 3218 nk_bool nk_button_symbol (nk_context*, nk_symbol_type); 3219 nk_bool nk_button_image (nk_context*, nk_image_ img); 3220 nk_bool nk_button_symbol_label (nk_context*, nk_symbol_type, const(char)*, nk_flags text_alignment); 3221 nk_bool nk_button_symbol_text (nk_context*, nk_symbol_type, const(char)*, int, nk_flags alignment); 3222 nk_bool nk_button_image_label (nk_context*, nk_image_ img, const(char)*, nk_flags text_alignment); 3223 nk_bool nk_button_image_text (nk_context*, nk_image_ img, const(char)*, int, nk_flags alignment); 3224 nk_bool nk_button_text_styled (nk_context*, const(nk_style_button)*, const(char)* title, int len); 3225 nk_bool nk_button_label_styled (nk_context*, const(nk_style_button)*, const(char)* title); 3226 nk_bool nk_button_symbol_styled (nk_context*, const(nk_style_button)*, nk_symbol_type); 3227 nk_bool nk_button_image_styled (nk_context*, const(nk_style_button)*, nk_image_ img); 3228 nk_bool nk_button_symbol_text_styled (nk_context*, const(nk_style_button)*, nk_symbol_type, const(char)*, int, nk_flags alignment); 3229 nk_bool nk_button_symbol_label_styled (nk_context* ctx, const(nk_style_button)* style, nk_symbol_type symbol, const(char)* title, nk_flags align_); 3230 nk_bool nk_button_image_label_styled (nk_context*, const(nk_style_button)*, nk_image_ img, const(char)*, nk_flags text_alignment); 3231 nk_bool nk_button_image_text_styled (nk_context*, const(nk_style_button)*, nk_image_ img, const(char)*, int, nk_flags alignment); 3232 void nk_button_set_behavior (nk_context*, nk_button_behavior); 3233 nk_bool nk_button_push_behavior (nk_context*, nk_button_behavior); 3234 nk_bool nk_button_pop_behavior (nk_context*); 3235 /* ============================================================================= 3236 * 3237 * CHECKBOX 3238 * 3239 * ============================================================================= */ 3240 nk_bool nk_check_label (nk_context*, const(char)*, nk_bool active); 3241 nk_bool nk_check_text (nk_context*, const(char)*, int, nk_bool active); 3242 uint nk_check_flags_label (nk_context*, const(char)*, uint flags, uint value); 3243 uint nk_check_flags_text (nk_context*, const(char)*, int, uint flags, uint value); 3244 nk_bool nk_checkbox_label (nk_context*, const(char)*, nk_bool* active); 3245 nk_bool nk_checkbox_text (nk_context*, const(char)*, int, nk_bool* active); 3246 nk_bool nk_checkbox_flags_label (nk_context*, const(char)*, uint* flags, uint value); 3247 nk_bool nk_checkbox_flags_text (nk_context*, const(char)*, int, uint* flags, uint value); 3248 /* ============================================================================= 3249 * 3250 * RADIO BUTTON 3251 * 3252 * ============================================================================= */ 3253 nk_bool nk_radio_label (nk_context*, const(char)*, nk_bool* active); 3254 nk_bool nk_radio_text (nk_context*, const(char)*, int, nk_bool* active); 3255 nk_bool nk_option_label (nk_context*, const(char)*, nk_bool active); 3256 nk_bool nk_option_text (nk_context*, const(char)*, int, nk_bool active); 3257 /* ============================================================================= 3258 * 3259 * SELECTABLE 3260 * 3261 * ============================================================================= */ 3262 nk_bool nk_selectable_label (nk_context*, const(char)*, nk_flags align_, nk_bool* value); 3263 nk_bool nk_selectable_text (nk_context*, const(char)*, int, nk_flags align_, nk_bool* value); 3264 nk_bool nk_selectable_image_label (nk_context*, nk_image_, const(char)*, nk_flags align_, nk_bool* value); 3265 nk_bool nk_selectable_image_text (nk_context*, nk_image_, const(char)*, int, nk_flags align_, nk_bool* value); 3266 nk_bool nk_selectable_symbol_label (nk_context*, nk_symbol_type, const(char)*, nk_flags align_, nk_bool* value); 3267 nk_bool nk_selectable_symbol_text (nk_context*, nk_symbol_type, const(char)*, int, nk_flags align_, nk_bool* value); 3268 3269 nk_bool nk_select_label (nk_context*, const(char)*, nk_flags align_, nk_bool value); 3270 nk_bool nk_select_text (nk_context*, const(char)*, int, nk_flags align_, nk_bool value); 3271 nk_bool nk_select_image_label (nk_context*, nk_image_, const(char)*, nk_flags align_, nk_bool value); 3272 nk_bool nk_select_image_text (nk_context*, nk_image_, const(char)*, int, nk_flags align_, nk_bool value); 3273 nk_bool nk_select_symbol_label (nk_context*, nk_symbol_type, const(char)*, nk_flags align_, nk_bool value); 3274 nk_bool nk_select_symbol_text (nk_context*, nk_symbol_type, const(char)*, int, nk_flags align_, nk_bool value); 3275 3276 /* ============================================================================= 3277 * 3278 * SLIDER 3279 * 3280 * ============================================================================= */ 3281 float nk_slide_float (nk_context*, float min, float val, float max, float step); 3282 int nk_slide_int (nk_context*, int min, int val, int max, int step); 3283 nk_bool nk_slider_float (nk_context*, float min, float* val, float max, float step); 3284 nk_bool nk_slider_int (nk_context*, int min, int* val, int max, int step); 3285 /* ============================================================================= 3286 * 3287 * PROGRESSBAR 3288 * 3289 * ============================================================================= */ 3290 nk_bool nk_progress (nk_context*, nk_size* cur, nk_size max, nk_bool modifyable); 3291 nk_size nk_prog (nk_context*, nk_size cur, nk_size max, nk_bool modifyable); 3292 3293 /* ============================================================================= 3294 * 3295 * COLOR PICKER 3296 * 3297 * ============================================================================= */ 3298 nk_colorf nk_color_picker (nk_context*, nk_colorf, nk_color_format); 3299 nk_bool nk_color_pick (nk_context*, nk_colorf*, nk_color_format); 3300 /* ============================================================================= 3301 * 3302 * PROPERTIES 3303 * 3304 * ============================================================================= 3305 /// ### Properties 3306 /// Properties are the main value modification widgets in Nuklear. Changing a value 3307 /// can be achieved by dragging, adding/removing incremental steps on button click 3308 /// or by directly typing a number. 3309 /// 3310 /// #### Usage 3311 /// Each property requires a unique name for identification that is also used for 3312 /// displaying a label. If you want to use the same name multiple times make sure 3313 /// add a '#' before your name. The '#' will not be shown but will generate a 3314 /// unique ID. Each property also takes in a minimum and maximum value. If you want 3315 /// to make use of the complete number range of a type just use the provided 3316 /// type limits from `limits.h`. For example `INT_MIN` and `INT_MAX` for 3317 /// `nk_property_int` and `nk_propertyi`. In additional each property takes in 3318 /// a increment value that will be added or subtracted if either the increment 3319 /// decrement button is clicked. Finally there is a value for increment per pixel 3320 /// dragged that is added or subtracted from the value. 3321 /// 3322 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 3323 /// int value = 0; 3324 /// struct nk_context ctx; 3325 /// nk_init_xxx(&ctx, ...); 3326 /// while (1) { 3327 /// // Input 3328 /// Event evt; 3329 /// nk_input_begin(&ctx); 3330 /// while (GetEvent(&evt)) { 3331 /// if (evt.type == MOUSE_MOVE) 3332 /// nk_input_motion(&ctx, evt.motion.x, evt.motion.y); 3333 /// else if (evt.type == [...]) { 3334 /// nk_input_xxx(...); 3335 /// } 3336 /// } 3337 /// nk_input_end(&ctx); 3338 /// // 3339 /// // Window 3340 /// if (nk_begin_xxx(...) { 3341 /// // Property 3342 /// nk_layout_row_dynamic(...); 3343 /// nk_property_int(ctx, "ID", INT_MIN, &value, INT_MAX, 1, 1); 3344 /// } 3345 /// nk_end(ctx); 3346 /// // 3347 /// // Draw 3348 /// const struct nk_command *cmd = 0; 3349 /// nk_foreach(cmd, &ctx) { 3350 /// switch (cmd->type) { 3351 /// case NK_COMMAND_LINE: 3352 /// your_draw_line_function(...) 3353 /// break; 3354 /// case NK_COMMAND_RECT 3355 /// your_draw_rect_function(...) 3356 /// break; 3357 /// case ...: 3358 /// // [...] 3359 /// } 3360 /// nk_clear(&ctx); 3361 /// } 3362 /// nk_free(&ctx); 3363 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3364 /// 3365 /// #### Reference 3366 /// Function | Description 3367 /// --------------------|------------------------------------------- 3368 /// nk_property_int | Integer property directly modifying a passed in value 3369 /// nk_property_float | Float property directly modifying a passed in value 3370 /// nk_property_double | Double property directly modifying a passed in value 3371 /// nk_propertyi | Integer property returning the modified int value 3372 /// nk_propertyf | Float property returning the modified float value 3373 /// nk_propertyd | Double property returning the modified double value 3374 /// 3375 */ 3376 /*/// #### nk_property_int 3377 /// Integer property directly modifying a passed in value 3378 /// !!! WARNING 3379 /// To generate a unique property ID using the same label make sure to insert 3380 /// a `#` at the beginning. It will not be shown but guarantees correct behavior. 3381 /// 3382 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 3383 /// void nk_property_int(struct nk_context *ctx, const char *name, int min, int *val, int max, int step, float inc_per_pixel); 3384 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3385 /// 3386 /// Parameter | Description 3387 /// --------------------|----------------------------------------------------------- 3388 /// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function 3389 /// __name__ | String used both as a label as well as a unique identifier 3390 /// __min__ | Minimum value not allowed to be underflown 3391 /// __val__ | Integer pointer to be modified 3392 /// __max__ | Maximum value not allowed to be overflown 3393 /// __step__ | Increment added and subtracted on increment and decrement button 3394 /// __inc_per_pixel__ | Value per pixel added or subtracted on dragging 3395 */ 3396 void nk_property_int (nk_context*, const(char)* name, int min, int* val, int max, int step, float inc_per_pixel); 3397 /*/// #### nk_property_float 3398 /// Float property directly modifying a passed in value 3399 /// !!! WARNING 3400 /// To generate a unique property ID using the same label make sure to insert 3401 /// a `#` at the beginning. It will not be shown but guarantees correct behavior. 3402 /// 3403 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 3404 /// void nk_property_float(struct nk_context *ctx, const char *name, float min, float *val, float max, float step, float inc_per_pixel); 3405 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3406 /// 3407 /// Parameter | Description 3408 /// --------------------|----------------------------------------------------------- 3409 /// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function 3410 /// __name__ | String used both as a label as well as a unique identifier 3411 /// __min__ | Minimum value not allowed to be underflown 3412 /// __val__ | Float pointer to be modified 3413 /// __max__ | Maximum value not allowed to be overflown 3414 /// __step__ | Increment added and subtracted on increment and decrement button 3415 /// __inc_per_pixel__ | Value per pixel added or subtracted on dragging 3416 */ 3417 void nk_property_float (nk_context*, const(char)* name, float min, float* val, float max, float step, float inc_per_pixel); 3418 /*/// #### nk_property_double 3419 /// Double property directly modifying a passed in value 3420 /// !!! WARNING 3421 /// To generate a unique property ID using the same label make sure to insert 3422 /// a `#` at the beginning. It will not be shown but guarantees correct behavior. 3423 /// 3424 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 3425 /// void nk_property_double(struct nk_context *ctx, const char *name, double min, double *val, double max, double step, double inc_per_pixel); 3426 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3427 /// 3428 /// Parameter | Description 3429 /// --------------------|----------------------------------------------------------- 3430 /// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function 3431 /// __name__ | String used both as a label as well as a unique identifier 3432 /// __min__ | Minimum value not allowed to be underflown 3433 /// __val__ | Double pointer to be modified 3434 /// __max__ | Maximum value not allowed to be overflown 3435 /// __step__ | Increment added and subtracted on increment and decrement button 3436 /// __inc_per_pixel__ | Value per pixel added or subtracted on dragging 3437 */ 3438 void nk_property_double (nk_context*, const(char)* name, double min, double* val, double max, double step, float inc_per_pixel); 3439 /*/// #### nk_propertyi 3440 /// Integer property modifying a passed in value and returning the new value 3441 /// !!! WARNING 3442 /// To generate a unique property ID using the same label make sure to insert 3443 /// a `#` at the beginning. It will not be shown but guarantees correct behavior. 3444 /// 3445 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 3446 /// int nk_propertyi(struct nk_context *ctx, const char *name, int min, int val, int max, int step, float inc_per_pixel); 3447 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3448 /// 3449 /// Parameter | Description 3450 /// --------------------|----------------------------------------------------------- 3451 /// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function 3452 /// __name__ | String used both as a label as well as a unique identifier 3453 /// __min__ | Minimum value not allowed to be underflown 3454 /// __val__ | Current integer value to be modified and returned 3455 /// __max__ | Maximum value not allowed to be overflown 3456 /// __step__ | Increment added and subtracted on increment and decrement button 3457 /// __inc_per_pixel__ | Value per pixel added or subtracted on dragging 3458 /// 3459 /// Returns the new modified integer value 3460 */ 3461 int nk_propertyi (nk_context*, const(char)* name, int min, int val, int max, int step, float inc_per_pixel); 3462 /*/// #### nk_propertyf 3463 /// Float property modifying a passed in value and returning the new value 3464 /// !!! WARNING 3465 /// To generate a unique property ID using the same label make sure to insert 3466 /// a `#` at the beginning. It will not be shown but guarantees correct behavior. 3467 /// 3468 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 3469 /// float nk_propertyf(struct nk_context *ctx, const char *name, float min, float val, float max, float step, float inc_per_pixel); 3470 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3471 /// 3472 /// Parameter | Description 3473 /// --------------------|----------------------------------------------------------- 3474 /// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function 3475 /// __name__ | String used both as a label as well as a unique identifier 3476 /// __min__ | Minimum value not allowed to be underflown 3477 /// __val__ | Current float value to be modified and returned 3478 /// __max__ | Maximum value not allowed to be overflown 3479 /// __step__ | Increment added and subtracted on increment and decrement button 3480 /// __inc_per_pixel__ | Value per pixel added or subtracted on dragging 3481 /// 3482 /// Returns the new modified float value 3483 */ 3484 float nk_propertyf (nk_context*, const(char)* name, float min, float val, float max, float step, float inc_per_pixel); 3485 /*/// #### nk_propertyd 3486 /// Float property modifying a passed in value and returning the new value 3487 /// !!! WARNING 3488 /// To generate a unique property ID using the same label make sure to insert 3489 /// a `#` at the beginning. It will not be shown but guarantees correct behavior. 3490 /// 3491 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c 3492 /// float nk_propertyd(struct nk_context *ctx, const char *name, double min, double val, double max, double step, double inc_per_pixel); 3493 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3494 /// 3495 /// Parameter | Description 3496 /// --------------------|----------------------------------------------------------- 3497 /// __ctx__ | Must point to an previously initialized `nk_context` struct after calling a layouting function 3498 /// __name__ | String used both as a label as well as a unique identifier 3499 /// __min__ | Minimum value not allowed to be underflown 3500 /// __val__ | Current double value to be modified and returned 3501 /// __max__ | Maximum value not allowed to be overflown 3502 /// __step__ | Increment added and subtracted on increment and decrement button 3503 /// __inc_per_pixel__ | Value per pixel added or subtracted on dragging 3504 /// 3505 /// Returns the new modified double value 3506 */ 3507 double nk_propertyd (nk_context*, const(char)* name, double min, double val, double max, double step, float inc_per_pixel); 3508 /* ============================================================================= 3509 * 3510 * TEXT EDIT 3511 * 3512 * ============================================================================= */ 3513 enum nk_edit_flags 3514 { 3515 NK_EDIT_DEFAULT = 0, 3516 NK_EDIT_READ_ONLY = NK_FLAG(0), 3517 NK_EDIT_AUTO_SELECT = NK_FLAG(1), 3518 NK_EDIT_SIG_ENTER = NK_FLAG(2), 3519 NK_EDIT_ALLOW_TAB = NK_FLAG(3), 3520 NK_EDIT_NO_CURSOR = NK_FLAG(4), 3521 NK_EDIT_SELECTABLE = NK_FLAG(5), 3522 NK_EDIT_CLIPBOARD = NK_FLAG(6), 3523 NK_EDIT_CTRL_ENTER_NEWLINE = NK_FLAG(7), 3524 NK_EDIT_NO_HORIZONTAL_SCROLL = NK_FLAG(8), 3525 NK_EDIT_ALWAYS_INSERT_MODE = NK_FLAG(9), 3526 NK_EDIT_MULTILINE = NK_FLAG(10), 3527 NK_EDIT_GOTO_END_ON_ACTIVATE = NK_FLAG(11) 3528 } 3529 3530 enum nk_edit_types 3531 { 3532 NK_EDIT_SIMPLE = nk_edit_flags.NK_EDIT_ALWAYS_INSERT_MODE, 3533 NK_EDIT_FIELD = cast(nk_edit_flags)NK_EDIT_SIMPLE | nk_edit_flags.NK_EDIT_SELECTABLE | nk_edit_flags.NK_EDIT_CLIPBOARD, 3534 NK_EDIT_BOX = nk_edit_flags.NK_EDIT_ALWAYS_INSERT_MODE | nk_edit_flags.NK_EDIT_SELECTABLE | nk_edit_flags.NK_EDIT_MULTILINE | nk_edit_flags.NK_EDIT_ALLOW_TAB | nk_edit_flags.NK_EDIT_CLIPBOARD, 3535 NK_EDIT_EDITOR = nk_edit_flags.NK_EDIT_SELECTABLE | nk_edit_flags.NK_EDIT_MULTILINE | nk_edit_flags.NK_EDIT_ALLOW_TAB | nk_edit_flags.NK_EDIT_CLIPBOARD 3536 } 3537 3538 enum nk_edit_events 3539 { 3540 NK_EDIT_ACTIVE = NK_FLAG(0), /* edit widget is currently being modified */ 3541 NK_EDIT_INACTIVE = NK_FLAG(1), /* edit widget is not active and is not being modified */ 3542 NK_EDIT_ACTIVATED = NK_FLAG(2), /* edit widget went from state inactive to state active */ 3543 NK_EDIT_DEACTIVATED = NK_FLAG(3), /* edit widget went from state active to state inactive */ 3544 NK_EDIT_COMMITED = NK_FLAG(4) /* edit widget has received an enter and lost focus */ 3545 } 3546 3547 nk_flags nk_edit_string (nk_context*, nk_flags, char* buffer, int* len, int max, nk_plugin_filter); 3548 nk_flags nk_edit_string_zero_terminated (nk_context*, nk_flags, char* buffer, int max, nk_plugin_filter); 3549 nk_flags nk_edit_buffer (nk_context*, nk_flags, nk_text_edit*, nk_plugin_filter); 3550 void nk_edit_focus (nk_context*, nk_flags flags); 3551 void nk_edit_unfocus (nk_context*); 3552 /* ============================================================================= 3553 * 3554 * CHART 3555 * 3556 * ============================================================================= */ 3557 nk_bool nk_chart_begin (nk_context*, nk_chart_type, int num, float min, float max); 3558 nk_bool nk_chart_begin_colored (nk_context*, nk_chart_type, nk_color, nk_color active, int num, float min, float max); 3559 void nk_chart_add_slot (nk_context* ctx, const nk_chart_type, int count, float min_value, float max_value); 3560 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); 3561 nk_flags nk_chart_push (nk_context*, float); 3562 nk_flags nk_chart_push_slot (nk_context*, float, int); 3563 void nk_chart_end (nk_context*); 3564 void nk_plot (nk_context*, nk_chart_type, const(float)* values, int count, int offset); 3565 void nk_plot_function (nk_context*, nk_chart_type, void* userdata, float function (void* user, int index) value_getter, int count, int offset); 3566 /* ============================================================================= 3567 * 3568 * POPUP 3569 * 3570 * ============================================================================= */ 3571 nk_bool nk_popup_begin (nk_context*, nk_popup_type, const(char)*, nk_flags, nk_rect_ bounds); 3572 void nk_popup_close (nk_context*); 3573 void nk_popup_end (nk_context*); 3574 void nk_popup_get_scroll (nk_context*, nk_uint* offset_x, nk_uint* offset_y); 3575 void nk_popup_set_scroll (nk_context*, nk_uint offset_x, nk_uint offset_y); 3576 /* ============================================================================= 3577 * 3578 * COMBOBOX 3579 * 3580 * ============================================================================= */ 3581 int nk_combo (nk_context*, const(char*)* items, int count, int selected, int item_height, nk_vec2_ size); 3582 int nk_combo_separator (nk_context*, const(char)* items_separated_by_separator, int separator, int selected, int count, int item_height, nk_vec2_ size); 3583 int nk_combo_string (nk_context*, const(char)* items_separated_by_zeros, int selected, int count, int item_height, nk_vec2_ size); 3584 int nk_combo_callback (nk_context*, void function (void*, int, const(char*)*) item_getter, void* userdata, int selected, int count, int item_height, nk_vec2_ size); 3585 void nk_combobox (nk_context*, const(char*)* items, int count, int* selected, int item_height, nk_vec2_ size); 3586 void nk_combobox_string (nk_context*, const(char)* items_separated_by_zeros, int* selected, int count, int item_height, nk_vec2_ size); 3587 void nk_combobox_separator (nk_context*, const(char)* items_separated_by_separator, int separator, int* selected, int count, int item_height, nk_vec2_ size); 3588 void nk_combobox_callback (nk_context*, void function (void*, int, const(char*)*) item_getter, void*, int* selected, int count, int item_height, nk_vec2_ size); 3589 /* ============================================================================= 3590 * 3591 * ABSTRACT COMBOBOX 3592 * 3593 * ============================================================================= */ 3594 nk_bool nk_combo_begin_text (nk_context*, const(char)* selected, int, nk_vec2_ size); 3595 nk_bool nk_combo_begin_label (nk_context*, const(char)* selected, nk_vec2_ size); 3596 nk_bool nk_combo_begin_color (nk_context*, nk_color color, nk_vec2_ size); 3597 nk_bool nk_combo_begin_symbol (nk_context*, nk_symbol_type, nk_vec2_ size); 3598 nk_bool nk_combo_begin_symbol_label (nk_context*, const(char)* selected, nk_symbol_type, nk_vec2_ size); 3599 nk_bool nk_combo_begin_symbol_text (nk_context*, const(char)* selected, int, nk_symbol_type, nk_vec2_ size); 3600 nk_bool nk_combo_begin_image (nk_context*, nk_image_ img, nk_vec2_ size); 3601 nk_bool nk_combo_begin_image_label (nk_context*, const(char)* selected, nk_image_, nk_vec2_ size); 3602 nk_bool nk_combo_begin_image_text (nk_context*, const(char)* selected, int, nk_image_, nk_vec2_ size); 3603 nk_bool nk_combo_item_label (nk_context*, const(char)*, nk_flags alignment); 3604 nk_bool nk_combo_item_text (nk_context*, const(char)*, int, nk_flags alignment); 3605 nk_bool nk_combo_item_image_label (nk_context*, nk_image_, const(char)*, nk_flags alignment); 3606 nk_bool nk_combo_item_image_text (nk_context*, nk_image_, const(char)*, int, nk_flags alignment); 3607 nk_bool nk_combo_item_symbol_label (nk_context*, nk_symbol_type, const(char)*, nk_flags alignment); 3608 nk_bool nk_combo_item_symbol_text (nk_context*, nk_symbol_type, const(char)*, int, nk_flags alignment); 3609 void nk_combo_close (nk_context*); 3610 void nk_combo_end (nk_context*); 3611 /* ============================================================================= 3612 * 3613 * CONTEXTUAL 3614 * 3615 * ============================================================================= */ 3616 nk_bool nk_contextual_begin (nk_context*, nk_flags, nk_vec2_, nk_rect_ trigger_bounds); 3617 nk_bool nk_contextual_item_text (nk_context*, const(char)*, int, nk_flags align_); 3618 nk_bool nk_contextual_item_label (nk_context*, const(char)*, nk_flags align_); 3619 nk_bool nk_contextual_item_image_label (nk_context*, nk_image_, const(char)*, nk_flags alignment); 3620 nk_bool nk_contextual_item_image_text (nk_context*, nk_image_, const(char)*, int len, nk_flags alignment); 3621 nk_bool nk_contextual_item_symbol_label (nk_context*, nk_symbol_type, const(char)*, nk_flags alignment); 3622 nk_bool nk_contextual_item_symbol_text (nk_context*, nk_symbol_type, const(char)*, int, nk_flags alignment); 3623 void nk_contextual_close (nk_context*); 3624 void nk_contextual_end (nk_context*); 3625 /* ============================================================================= 3626 * 3627 * TOOLTIP 3628 * 3629 * ============================================================================= */ 3630 void nk_tooltip (nk_context*, const(char)*); 3631 3632 nk_bool nk_tooltip_begin (nk_context*, float width); 3633 void nk_tooltip_end (nk_context*); 3634 /* ============================================================================= 3635 * 3636 * MENU 3637 * 3638 * ============================================================================= */ 3639 void nk_menubar_begin (nk_context*); 3640 void nk_menubar_end (nk_context*); 3641 nk_bool nk_menu_begin_text (nk_context*, const(char)* title, int title_len, nk_flags align_, nk_vec2_ size); 3642 nk_bool nk_menu_begin_label (nk_context*, const(char)*, nk_flags align_, nk_vec2_ size); 3643 nk_bool nk_menu_begin_image (nk_context*, const(char)*, nk_image_, nk_vec2_ size); 3644 nk_bool nk_menu_begin_image_text (nk_context*, const(char)*, int, nk_flags align_, nk_image_, nk_vec2_ size); 3645 nk_bool nk_menu_begin_image_label (nk_context*, const(char)*, nk_flags align_, nk_image_, nk_vec2_ size); 3646 nk_bool nk_menu_begin_symbol (nk_context*, const(char)*, nk_symbol_type, nk_vec2_ size); 3647 nk_bool nk_menu_begin_symbol_text (nk_context*, const(char)*, int, nk_flags align_, nk_symbol_type, nk_vec2_ size); 3648 nk_bool nk_menu_begin_symbol_label (nk_context*, const(char)*, nk_flags align_, nk_symbol_type, nk_vec2_ size); 3649 nk_bool nk_menu_item_text (nk_context*, const(char)*, int, nk_flags align_); 3650 nk_bool nk_menu_item_label (nk_context*, const(char)*, nk_flags alignment); 3651 nk_bool nk_menu_item_image_label (nk_context*, nk_image_, const(char)*, nk_flags alignment); 3652 nk_bool nk_menu_item_image_text (nk_context*, nk_image_, const(char)*, int len, nk_flags alignment); 3653 nk_bool nk_menu_item_symbol_text (nk_context*, nk_symbol_type, const(char)*, int, nk_flags alignment); 3654 nk_bool nk_menu_item_symbol_label (nk_context*, nk_symbol_type, const(char)*, nk_flags alignment); 3655 void nk_menu_close (nk_context*); 3656 void nk_menu_end (nk_context*); 3657 /* ============================================================================= 3658 * 3659 * STYLE 3660 * 3661 * ============================================================================= */ 3662 enum nk_style_colors 3663 { 3664 NK_COLOR_TEXT = 0, 3665 NK_COLOR_WINDOW = 1, 3666 NK_COLOR_HEADER = 2, 3667 NK_COLOR_BORDER = 3, 3668 NK_COLOR_BUTTON = 4, 3669 NK_COLOR_BUTTON_HOVER = 5, 3670 NK_COLOR_BUTTON_ACTIVE = 6, 3671 NK_COLOR_TOGGLE = 7, 3672 NK_COLOR_TOGGLE_HOVER = 8, 3673 NK_COLOR_TOGGLE_CURSOR = 9, 3674 NK_COLOR_SELECT = 10, 3675 NK_COLOR_SELECT_ACTIVE = 11, 3676 NK_COLOR_SLIDER = 12, 3677 NK_COLOR_SLIDER_CURSOR = 13, 3678 NK_COLOR_SLIDER_CURSOR_HOVER = 14, 3679 NK_COLOR_SLIDER_CURSOR_ACTIVE = 15, 3680 NK_COLOR_PROPERTY = 16, 3681 NK_COLOR_EDIT = 17, 3682 NK_COLOR_EDIT_CURSOR = 18, 3683 NK_COLOR_COMBO = 19, 3684 NK_COLOR_CHART = 20, 3685 NK_COLOR_CHART_COLOR = 21, 3686 NK_COLOR_CHART_COLOR_HIGHLIGHT = 22, 3687 NK_COLOR_SCROLLBAR = 23, 3688 NK_COLOR_SCROLLBAR_CURSOR = 24, 3689 NK_COLOR_SCROLLBAR_CURSOR_HOVER = 25, 3690 NK_COLOR_SCROLLBAR_CURSOR_ACTIVE = 26, 3691 NK_COLOR_TAB_HEADER = 27, 3692 NK_COLOR_COUNT = 28 3693 } 3694 3695 enum nk_style_cursor 3696 { 3697 NK_CURSOR_ARROW = 0, 3698 NK_CURSOR_TEXT = 1, 3699 NK_CURSOR_MOVE = 2, 3700 NK_CURSOR_RESIZE_VERTICAL = 3, 3701 NK_CURSOR_RESIZE_HORIZONTAL = 4, 3702 NK_CURSOR_RESIZE_TOP_LEFT_DOWN_RIGHT = 5, 3703 NK_CURSOR_RESIZE_TOP_RIGHT_DOWN_LEFT = 6, 3704 NK_CURSOR_COUNT = 7 3705 } 3706 3707 void nk_style_default (nk_context*); 3708 void nk_style_from_table (nk_context*, const(nk_color)*); 3709 void nk_style_load_cursor (nk_context*, nk_style_cursor, const(nk_cursor)*); 3710 void nk_style_load_all_cursors (nk_context*, nk_cursor*); 3711 const(char)* nk_style_get_color_by_name (nk_style_colors); 3712 void nk_style_set_font (nk_context*, const(nk_user_font)*); 3713 nk_bool nk_style_set_cursor (nk_context*, nk_style_cursor); 3714 void nk_style_show_cursor (nk_context*); 3715 void nk_style_hide_cursor (nk_context*); 3716 3717 nk_bool nk_style_push_font (nk_context*, const(nk_user_font)*); 3718 nk_bool nk_style_push_float (nk_context*, float*, float); 3719 nk_bool nk_style_push_vec2 (nk_context*, nk_vec2_*, nk_vec2_); 3720 nk_bool nk_style_push_style_item (nk_context*, nk_style_item*, nk_style_item); 3721 nk_bool nk_style_push_flags (nk_context*, nk_flags*, nk_flags); 3722 nk_bool nk_style_push_color (nk_context*, nk_color*, nk_color); 3723 3724 nk_bool nk_style_pop_font (nk_context*); 3725 nk_bool nk_style_pop_float (nk_context*); 3726 nk_bool nk_style_pop_vec2 (nk_context*); 3727 nk_bool nk_style_pop_style_item (nk_context*); 3728 nk_bool nk_style_pop_flags (nk_context*); 3729 nk_bool nk_style_pop_color (nk_context*); 3730 /* ============================================================================= 3731 * 3732 * COLOR 3733 * 3734 * ============================================================================= */ 3735 nk_color nk_rgb (int r, int g, int b); 3736 nk_color nk_rgb_iv (const(int)* rgb); 3737 nk_color nk_rgb_bv (const(nk_byte)* rgb); 3738 nk_color nk_rgb_f (float r, float g, float b); 3739 nk_color nk_rgb_fv (const(float)* rgb); 3740 nk_color nk_rgb_cf (nk_colorf c); 3741 nk_color nk_rgb_hex (const(char)* rgb); 3742 3743 nk_color nk_rgba (int r, int g, int b, int a); 3744 nk_color nk_rgba_u32 (nk_uint); 3745 nk_color nk_rgba_iv (const(int)* rgba); 3746 nk_color nk_rgba_bv (const(nk_byte)* rgba); 3747 nk_color nk_rgba_f (float r, float g, float b, float a); 3748 nk_color nk_rgba_fv (const(float)* rgba); 3749 nk_color nk_rgba_cf (nk_colorf c); 3750 nk_color nk_rgba_hex (const(char)* rgb); 3751 3752 nk_colorf nk_hsva_colorf (float h, float s, float v, float a); 3753 nk_colorf nk_hsva_colorfv (float* c); 3754 void nk_colorf_hsva_f (float* out_h, float* out_s, float* out_v, float* out_a, nk_colorf in_); 3755 void nk_colorf_hsva_fv (float* hsva, nk_colorf in_); 3756 3757 nk_color nk_hsv (int h, int s, int v); 3758 nk_color nk_hsv_iv (const(int)* hsv); 3759 nk_color nk_hsv_bv (const(nk_byte)* hsv); 3760 nk_color nk_hsv_f (float h, float s, float v); 3761 nk_color nk_hsv_fv (const(float)* hsv); 3762 3763 nk_color nk_hsva (int h, int s, int v, int a); 3764 nk_color nk_hsva_iv (const(int)* hsva); 3765 nk_color nk_hsva_bv (const(nk_byte)* hsva); 3766 nk_color nk_hsva_f (float h, float s, float v, float a); 3767 nk_color nk_hsva_fv (const(float)* hsva); 3768 3769 /* color (conversion nuklear --> user) */ 3770 void nk_color_f (float* r, float* g, float* b, float* a, nk_color); 3771 void nk_color_fv (float* rgba_out, nk_color); 3772 nk_colorf nk_color_cf (nk_color); 3773 void nk_color_d (double* r, double* g, double* b, double* a, nk_color); 3774 void nk_color_dv (double* rgba_out, nk_color); 3775 3776 nk_uint nk_color_u32 (nk_color); 3777 void nk_color_hex_rgba (char* output, nk_color); 3778 void nk_color_hex_rgb (char* output, nk_color); 3779 3780 void nk_color_hsv_i (int* out_h, int* out_s, int* out_v, nk_color); 3781 void nk_color_hsv_b (nk_byte* out_h, nk_byte* out_s, nk_byte* out_v, nk_color); 3782 void nk_color_hsv_iv (int* hsv_out, nk_color); 3783 void nk_color_hsv_bv (nk_byte* hsv_out, nk_color); 3784 void nk_color_hsv_f (float* out_h, float* out_s, float* out_v, nk_color); 3785 void nk_color_hsv_fv (float* hsv_out, nk_color); 3786 3787 void nk_color_hsva_i (int* h, int* s, int* v, int* a, nk_color); 3788 void nk_color_hsva_b (nk_byte* h, nk_byte* s, nk_byte* v, nk_byte* a, nk_color); 3789 void nk_color_hsva_iv (int* hsva_out, nk_color); 3790 void nk_color_hsva_bv (nk_byte* hsva_out, nk_color); 3791 void nk_color_hsva_f (float* out_h, float* out_s, float* out_v, float* out_a, nk_color); 3792 void nk_color_hsva_fv (float* hsva_out, nk_color); 3793 /* ============================================================================= 3794 * 3795 * IMAGE 3796 * 3797 * ============================================================================= */ 3798 nk_handle nk_handle_ptr (void*); 3799 nk_handle nk_handle_id (int); 3800 nk_image_ nk_image_handle (nk_handle); 3801 nk_image_ nk_image_ptr (void*); 3802 nk_image_ nk_image_id (int); 3803 nk_bool nk_image_is_subimage (const(nk_image_)* img); 3804 nk_image_ nk_subimage_ptr (void*, nk_ushort w, nk_ushort h, nk_rect_ sub_region); 3805 nk_image_ nk_subimage_id (int, nk_ushort w, nk_ushort h, nk_rect_ sub_region); 3806 nk_image_ nk_subimage_handle (nk_handle, nk_ushort w, nk_ushort h, nk_rect_ sub_region); 3807 /* ============================================================================= 3808 * 3809 * 9-SLICE 3810 * 3811 * ============================================================================= */ 3812 nk_nine_slice nk_nine_slice_handle (nk_handle, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); 3813 nk_nine_slice nk_nine_slice_ptr (void*, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); 3814 nk_nine_slice nk_nine_slice_id (int, nk_ushort l, nk_ushort t, nk_ushort r, nk_ushort b); 3815 int nk_nine_slice_is_sub9slice (const(nk_nine_slice)* img); 3816 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); 3817 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); 3818 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); 3819 /* ============================================================================= 3820 * 3821 * MATH 3822 * 3823 * ============================================================================= */ 3824 nk_hash nk_murmur_hash (const(void)* key, int len, nk_hash seed); 3825 void nk_triangle_from_direction (nk_vec2_* result, nk_rect_ r, float pad_x, float pad_y, nk_heading); 3826 3827 nk_vec2_ nk_vec2 (float x, float y); 3828 nk_vec2_ nk_vec2i (int x, int y); 3829 nk_vec2_ nk_vec2v (const(float)* xy); 3830 nk_vec2_ nk_vec2iv (const(int)* xy); 3831 3832 nk_rect_ nk_get_null_rect (); 3833 nk_rect_ nk_rect (float x, float y, float w, float h); 3834 nk_rect_ nk_recti (int x, int y, int w, int h); 3835 nk_rect_ nk_recta (nk_vec2_ pos, nk_vec2_ size); 3836 nk_rect_ nk_rectv (const(float)* xywh); 3837 nk_rect_ nk_rectiv (const(int)* xywh); 3838 nk_vec2_ nk_rect_pos (nk_rect_); 3839 nk_vec2_ nk_rect_size (nk_rect_); 3840 /* ============================================================================= 3841 * 3842 * STRING 3843 * 3844 * ============================================================================= */ 3845 int nk_strlen (const(char)* str); 3846 int nk_stricmp (const(char)* s1, const(char)* s2); 3847 int nk_stricmpn (const(char)* s1, const(char)* s2, int n); 3848 int nk_strtoi (const(char)* str, const(char*)* endptr); 3849 float nk_strtof (const(char)* str, const(char*)* endptr); 3850 3851 alias NK_STRTOD = nk_strtod; 3852 double nk_strtod (const(char)* str, const(char*)* endptr); 3853 3854 int nk_strfilter (const(char)* text, const(char)* regexp); 3855 int nk_strmatch_fuzzy_string (const(char)* str, const(char)* pattern, int* out_score); 3856 int nk_strmatch_fuzzy_text (const(char)* txt, int txt_len, const(char)* pattern, int* out_score); 3857 /* ============================================================================= 3858 * 3859 * UTF-8 3860 * 3861 * ============================================================================= */ 3862 int nk_utf_decode (const(char)*, nk_rune*, int); 3863 int nk_utf_encode (nk_rune, char*, int); 3864 int nk_utf_len (const(char)*, int byte_len); 3865 const(char)* nk_utf_at (const(char)* buffer, int length, int index, nk_rune* unicode, int* len); 3866 /* =============================================================== 3867 * 3868 * FONT 3869 * 3870 * ===============================================================*/ 3871 /* Font handling in this library was designed to be quite customizable and lets 3872 you decide what you want to use and what you want to provide. There are three 3873 different ways to use the font atlas. The first two will use your font 3874 handling scheme and only requires essential data to run nuklear. The next 3875 slightly more advanced features is font handling with vertex buffer output. 3876 Finally the most complex API wise is using nuklear's font baking API. 3877 3878 1.) Using your own implementation without vertex buffer output 3879 -------------------------------------------------------------- 3880 So first up the easiest way to do font handling is by just providing a 3881 `nk_user_font` struct which only requires the height in pixel of the used 3882 font and a callback to calculate the width of a string. This way of handling 3883 fonts is best fitted for using the normal draw shape command API where you 3884 do all the text drawing yourself and the library does not require any kind 3885 of deeper knowledge about which font handling mechanism you use. 3886 IMPORTANT: the `nk_user_font` pointer provided to nuklear has to persist 3887 over the complete life time! I know this sucks but it is currently the only 3888 way to switch between fonts. 3889 3890 float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) 3891 { 3892 your_font_type *type = handle.ptr; 3893 float text_width = ...; 3894 return text_width; 3895 } 3896 3897 struct nk_user_font font; 3898 font.userdata.ptr = &your_font_class_or_struct; 3899 font.height = your_font_height; 3900 font.width = your_text_width_calculation; 3901 3902 struct nk_context ctx; 3903 nk_init_default(&ctx, &font); 3904 3905 2.) Using your own implementation with vertex buffer output 3906 -------------------------------------------------------------- 3907 While the first approach works fine if you don't want to use the optional 3908 vertex buffer output it is not enough if you do. To get font handling working 3909 for these cases you have to provide two additional parameters inside the 3910 `nk_user_font`. First a texture atlas handle used to draw text as subimages 3911 of a bigger font atlas texture and a callback to query a character's glyph 3912 information (offset, size, ...). So it is still possible to provide your own 3913 font and use the vertex buffer output. 3914 3915 float your_text_width_calculation(nk_handle handle, float height, const char *text, int len) 3916 { 3917 your_font_type *type = handle.ptr; 3918 float text_width = ...; 3919 return text_width; 3920 } 3921 void query_your_font_glyph(nk_handle handle, float font_height, struct nk_user_font_glyph *glyph, nk_rune codepoint, nk_rune next_codepoint) 3922 { 3923 your_font_type *type = handle.ptr; 3924 glyph.width = ...; 3925 glyph.height = ...; 3926 glyph.xadvance = ...; 3927 glyph.uv[0].x = ...; 3928 glyph.uv[0].y = ...; 3929 glyph.uv[1].x = ...; 3930 glyph.uv[1].y = ...; 3931 glyph.offset.x = ...; 3932 glyph.offset.y = ...; 3933 } 3934 3935 struct nk_user_font font; 3936 font.userdata.ptr = &your_font_class_or_struct; 3937 font.height = your_font_height; 3938 font.width = your_text_width_calculation; 3939 font.query = query_your_font_glyph; 3940 font.texture.id = your_font_texture; 3941 3942 struct nk_context ctx; 3943 nk_init_default(&ctx, &font); 3944 3945 3.) Nuklear font baker 3946 ------------------------------------ 3947 The final approach if you do not have a font handling functionality or don't 3948 want to use it in this library is by using the optional font baker. 3949 The font baker APIs can be used to create a font plus font atlas texture 3950 and can be used with or without the vertex buffer output. 3951 3952 It still uses the `nk_user_font` struct and the two different approaches 3953 previously stated still work. The font baker is not located inside 3954 `nk_context` like all other systems since it can be understood as more of 3955 an extension to nuklear and does not really depend on any `nk_context` state. 3956 3957 Font baker need to be initialized first by one of the nk_font_atlas_init_xxx 3958 functions. If you don't care about memory just call the default version 3959 `nk_font_atlas_init_default` which will allocate all memory from the standard library. 3960 If you want to control memory allocation but you don't care if the allocated 3961 memory is temporary and therefore can be freed directly after the baking process 3962 is over or permanent you can call `nk_font_atlas_init`. 3963 3964 After successfully initializing the font baker you can add Truetype(.ttf) fonts from 3965 different sources like memory or from file by calling one of the `nk_font_atlas_add_xxx`. 3966 functions. Adding font will permanently store each font, font config and ttf memory block(!) 3967 inside the font atlas and allows to reuse the font atlas. If you don't want to reuse 3968 the font baker by for example adding additional fonts you can call 3969 `nk_font_atlas_cleanup` after the baking process is over (after calling nk_font_atlas_end). 3970 3971 As soon as you added all fonts you wanted you can now start the baking process 3972 for every selected glyph to image by calling `nk_font_atlas_bake`. 3973 The baking process returns image memory, width and height which can be used to 3974 either create your own image object or upload it to any graphics library. 3975 No matter which case you finally have to call `nk_font_atlas_end` which 3976 will free all temporary memory including the font atlas image so make sure 3977 you created our texture beforehand. `nk_font_atlas_end` requires a handle 3978 to your font texture or object and optionally fills a `struct nk_draw_null_texture` 3979 which can be used for the optional vertex output. If you don't want it just 3980 set the argument to `NULL`. 3981 3982 At this point you are done and if you don't want to reuse the font atlas you 3983 can call `nk_font_atlas_cleanup` to free all truetype blobs and configuration 3984 memory. Finally if you don't use the font atlas and any of it's fonts anymore 3985 you need to call `nk_font_atlas_clear` to free all memory still being used. 3986 3987 struct nk_font_atlas atlas; 3988 nk_font_atlas_init_default(&atlas); 3989 nk_font_atlas_begin(&atlas); 3990 nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, 0); 3991 nk_font *font2 = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font2.ttf", 16, 0); 3992 const void* img = nk_font_atlas_bake(&atlas, &img_width, &img_height, NK_FONT_ATLAS_RGBA32); 3993 nk_font_atlas_end(&atlas, nk_handle_id(texture), 0); 3994 3995 struct nk_context ctx; 3996 nk_init_default(&ctx, &font->handle); 3997 while (1) { 3998 3999 } 4000 nk_font_atlas_clear(&atlas); 4001 4002 The font baker API is probably the most complex API inside this library and 4003 I would suggest reading some of my examples `example/` to get a grip on how 4004 to use the font atlas. There are a number of details I left out. For example 4005 how to merge fonts, configure a font with `nk_font_config` to use other languages, 4006 use another texture coordinate format and a lot more: 4007 4008 struct nk_font_config cfg = nk_font_config(font_pixel_height); 4009 cfg.merge_mode = nk_false or nk_true; 4010 cfg.range = nk_font_korean_glyph_ranges(); 4011 cfg.coord_type = NK_COORD_PIXEL; 4012 nk_font *font = nk_font_atlas_add_from_file(&atlas, "Path/To/Your/TTF_Font.ttf", 13, &cfg); 4013 4014 */ 4015 struct nk_user_font_glyph; 4016 alias nk_text_width_f = float function (nk_handle, float h, const(char)*, int len); 4017 alias nk_query_font_glyph_f = void function ( 4018 nk_handle handle, 4019 float font_height, 4020 nk_user_font_glyph* glyph, 4021 nk_rune codepoint, 4022 nk_rune next_codepoint); 4023 4024 /* texture coordinates */ 4025 4026 /* offset between top left and glyph */ 4027 4028 /* size of the glyph */ 4029 4030 /* offset to the next glyph */ 4031 4032 struct nk_user_font 4033 { 4034 nk_handle userdata; 4035 /* user provided font handle */ 4036 float height; 4037 /* max height of the font */ 4038 nk_text_width_f width; 4039 /* font string width in pixel callback */ 4040 4041 /* font glyph callback to query drawing info */ 4042 4043 /* texture handle to the used font atlas or texture */ 4044 } 4045 4046 /* texture coordinates inside font glyphs are clamped between 0-1 */ 4047 /* texture coordinates inside font glyphs are in absolute pixel */ 4048 4049 /* height of the font */ 4050 4051 /* font glyphs ascent and descent */ 4052 4053 /* glyph array offset inside the font glyph baking output array */ 4054 4055 /* number of glyphs of this font inside the glyph baking array output */ 4056 4057 /* font codepoint ranges as pairs of (from/to) and 0 as last element */ 4058 4059 /* NOTE: only used internally */ 4060 4061 /* pointer to loaded TTF file memory block. 4062 * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */ 4063 4064 /* size of the loaded TTF file memory block 4065 * NOTE: not needed for nk_font_atlas_add_from_memory and nk_font_atlas_add_from_file. */ 4066 4067 /* used inside font atlas: default to: 0*/ 4068 4069 /* merges this font into the last font */ 4070 4071 /* align every character to pixel boundary (if true set oversample (1,1)) */ 4072 4073 /* rasterize at high quality for sub-pixel position */ 4074 4075 /* baked pixel height of the font */ 4076 4077 /* texture coordinate format with either pixel or UV coordinates */ 4078 4079 /* extra pixel spacing between glyphs */ 4080 4081 /* list of unicode ranges (2 values per range, zero terminated) */ 4082 4083 /* font to setup in the baking process: NOTE: not needed for font atlas */ 4084 4085 /* fallback glyph to use if a given rune is not found */ 4086 4087 /* some language glyph codepoint ranges */ 4088 4089 /* ============================================================== 4090 * 4091 * MEMORY BUFFER 4092 * 4093 * ===============================================================*/ 4094 /* A basic (double)-buffer with linear allocation and resetting as only 4095 freeing policy. The buffer's main purpose is to control all memory management 4096 inside the GUI toolkit and still leave memory control as much as possible in 4097 the hand of the user while also making sure the library is easy to use if 4098 not as much control is needed. 4099 In general all memory inside this library can be provided from the user in 4100 three different ways. 4101 4102 The first way and the one providing most control is by just passing a fixed 4103 size memory block. In this case all control lies in the hand of the user 4104 since he can exactly control where the memory comes from and how much memory 4105 the library should consume. Of course using the fixed size API removes the 4106 ability to automatically resize a buffer if not enough memory is provided so 4107 you have to take over the resizing. While being a fixed sized buffer sounds 4108 quite limiting, it is very effective in this library since the actual memory 4109 consumption is quite stable and has a fixed upper bound for a lot of cases. 4110 4111 If you don't want to think about how much memory the library should allocate 4112 at all time or have a very dynamic UI with unpredictable memory consumption 4113 habits but still want control over memory allocation you can use the dynamic 4114 allocator based API. The allocator consists of two callbacks for allocating 4115 and freeing memory and optional userdata so you can plugin your own allocator. 4116 4117 The final and easiest way can be used by defining 4118 NK_INCLUDE_DEFAULT_ALLOCATOR which uses the standard library memory 4119 allocation functions malloc and free and takes over complete control over 4120 memory in this library. 4121 */ 4122 struct nk_memory_status 4123 { 4124 void* memory; 4125 uint type; 4126 nk_size size; 4127 nk_size allocated; 4128 nk_size needed; 4129 nk_size calls; 4130 } 4131 4132 enum nk_allocation_type 4133 { 4134 NK_BUFFER_FIXED = 0, 4135 NK_BUFFER_DYNAMIC = 1 4136 } 4137 4138 enum nk_buffer_allocation_type 4139 { 4140 NK_BUFFER_FRONT = 0, 4141 NK_BUFFER_BACK = 1, 4142 NK_BUFFER_MAX = 2 4143 } 4144 4145 struct nk_buffer_marker 4146 { 4147 nk_bool active; 4148 nk_size offset; 4149 } 4150 4151 struct nk_memory 4152 { 4153 void* ptr; 4154 nk_size size; 4155 } 4156 4157 struct nk_buffer 4158 { 4159 nk_buffer_marker[nk_buffer_allocation_type.NK_BUFFER_MAX] marker; 4160 /* buffer marker to free a buffer to a certain offset */ 4161 nk_allocator pool; 4162 /* allocator callback for dynamic buffers */ 4163 nk_allocation_type type; 4164 /* memory management type */ 4165 nk_memory memory; 4166 /* memory and size of the current memory block */ 4167 float grow_factor; 4168 /* growing factor for dynamic memory management */ 4169 nk_size allocated; 4170 /* total amount of memory allocated */ 4171 nk_size needed; 4172 /* totally consumed memory given that enough memory is present */ 4173 nk_size calls; 4174 /* number of allocation calls */ 4175 nk_size size; 4176 /* current size of the buffer */ 4177 } 4178 4179 void nk_buffer_init (nk_buffer*, const(nk_allocator)*, nk_size size); 4180 void nk_buffer_init_fixed (nk_buffer*, void* memory, nk_size size); 4181 void nk_buffer_info (nk_memory_status*, nk_buffer*); 4182 void nk_buffer_push (nk_buffer*, nk_buffer_allocation_type type, const(void)* memory, nk_size size, nk_size align_); 4183 void nk_buffer_mark (nk_buffer*, nk_buffer_allocation_type type); 4184 void nk_buffer_reset (nk_buffer*, nk_buffer_allocation_type type); 4185 void nk_buffer_clear (nk_buffer*); 4186 void nk_buffer_free (nk_buffer*); 4187 void* nk_buffer_memory (nk_buffer*); 4188 const(void)* nk_buffer_memory_const (const(nk_buffer)*); 4189 nk_size nk_buffer_total (nk_buffer*); 4190 4191 /* ============================================================== 4192 * 4193 * STRING 4194 * 4195 * ===============================================================*/ 4196 /* Basic string buffer which is only used in context with the text editor 4197 * to manage and manipulate dynamic or fixed size string content. This is _NOT_ 4198 * the default string handling method. The only instance you should have any contact 4199 * with this API is if you interact with an `nk_text_edit` object inside one of the 4200 * copy and paste functions and even there only for more advanced cases. */ 4201 struct nk_str 4202 { 4203 nk_buffer buffer; 4204 int len; /* in codepoints/runes/glyphs */ 4205 } 4206 4207 void nk_str_init (nk_str*, const(nk_allocator)*, nk_size size); 4208 void nk_str_init_fixed (nk_str*, void* memory, nk_size size); 4209 void nk_str_clear (nk_str*); 4210 void nk_str_free (nk_str*); 4211 4212 int nk_str_append_text_char (nk_str*, const(char)*, int); 4213 int nk_str_append_str_char (nk_str*, const(char)*); 4214 int nk_str_append_text_utf8 (nk_str*, const(char)*, int); 4215 int nk_str_append_str_utf8 (nk_str*, const(char)*); 4216 int nk_str_append_text_runes (nk_str*, const(nk_rune)*, int); 4217 int nk_str_append_str_runes (nk_str*, const(nk_rune)*); 4218 4219 int nk_str_insert_at_char (nk_str*, int pos, const(char)*, int); 4220 int nk_str_insert_at_rune (nk_str*, int pos, const(char)*, int); 4221 4222 int nk_str_insert_text_char (nk_str*, int pos, const(char)*, int); 4223 int nk_str_insert_str_char (nk_str*, int pos, const(char)*); 4224 int nk_str_insert_text_utf8 (nk_str*, int pos, const(char)*, int); 4225 int nk_str_insert_str_utf8 (nk_str*, int pos, const(char)*); 4226 int nk_str_insert_text_runes (nk_str*, int pos, const(nk_rune)*, int); 4227 int nk_str_insert_str_runes (nk_str*, int pos, const(nk_rune)*); 4228 4229 void nk_str_remove_chars (nk_str*, int len); 4230 void nk_str_remove_runes (nk_str* str, int len); 4231 void nk_str_delete_chars (nk_str*, int pos, int len); 4232 void nk_str_delete_runes (nk_str*, int pos, int len); 4233 4234 char* nk_str_at_char (nk_str*, int pos); 4235 char* nk_str_at_rune (nk_str*, int pos, nk_rune* unicode, int* len); 4236 nk_rune nk_str_rune_at (const(nk_str)*, int pos); 4237 const(char)* nk_str_at_char_const (const(nk_str)*, int pos); 4238 const(char)* nk_str_at_const (const(nk_str)*, int pos, nk_rune* unicode, int* len); 4239 4240 char* nk_str_get (nk_str*); 4241 const(char)* nk_str_get_const (const(nk_str)*); 4242 int nk_str_len (nk_str*); 4243 int nk_str_len_char (nk_str*); 4244 4245 /*=============================================================== 4246 * 4247 * TEXT EDITOR 4248 * 4249 * ===============================================================*/ 4250 /* Editing text in this library is handled by either `nk_edit_string` or 4251 * `nk_edit_buffer`. But like almost everything in this library there are multiple 4252 * ways of doing it and a balance between control and ease of use with memory 4253 * as well as functionality controlled by flags. 4254 * 4255 * This library generally allows three different levels of memory control: 4256 * First of is the most basic way of just providing a simple char array with 4257 * string length. This method is probably the easiest way of handling simple 4258 * user text input. Main upside is complete control over memory while the biggest 4259 * downside in comparison with the other two approaches is missing undo/redo. 4260 * 4261 * For UIs that require undo/redo the second way was created. It is based on 4262 * a fixed size nk_text_edit struct, which has an internal undo/redo stack. 4263 * This is mainly useful if you want something more like a text editor but don't want 4264 * to have a dynamically growing buffer. 4265 * 4266 * The final way is using a dynamically growing nk_text_edit struct, which 4267 * has both a default version if you don't care where memory comes from and an 4268 * allocator version if you do. While the text editor is quite powerful for its 4269 * complexity I would not recommend editing gigabytes of data with it. 4270 * It is rather designed for uses cases which make sense for a GUI library not for 4271 * an full blown text editor. 4272 */ 4273 4274 enum NK_TEXTEDIT_UNDOSTATECOUNT = 99; 4275 4276 enum NK_TEXTEDIT_UNDOCHARCOUNT = 999; 4277 4278 struct nk_clipboard 4279 { 4280 nk_handle userdata; 4281 nk_plugin_paste paste; 4282 nk_plugin_copy copy; 4283 } 4284 4285 struct nk_text_undo_record 4286 { 4287 int where; 4288 short insert_length; 4289 short delete_length; 4290 short char_storage; 4291 } 4292 4293 struct nk_text_undo_state 4294 { 4295 nk_text_undo_record[NK_TEXTEDIT_UNDOSTATECOUNT] undo_rec; 4296 nk_rune[NK_TEXTEDIT_UNDOCHARCOUNT] undo_char; 4297 short undo_point; 4298 short redo_point; 4299 short undo_char_point; 4300 short redo_char_point; 4301 } 4302 4303 enum nk_text_edit_type 4304 { 4305 NK_TEXT_EDIT_SINGLE_LINE = 0, 4306 NK_TEXT_EDIT_MULTI_LINE = 1 4307 } 4308 4309 enum nk_text_edit_mode 4310 { 4311 NK_TEXT_EDIT_MODE_VIEW = 0, 4312 NK_TEXT_EDIT_MODE_INSERT = 1, 4313 NK_TEXT_EDIT_MODE_REPLACE = 2 4314 } 4315 4316 struct nk_text_edit 4317 { 4318 nk_clipboard clip; 4319 nk_str string; 4320 nk_plugin_filter filter; 4321 nk_vec2_ scrollbar; 4322 4323 int cursor; 4324 int select_start; 4325 int select_end; 4326 ubyte mode; 4327 ubyte cursor_at_end_of_line; 4328 ubyte initialized; 4329 ubyte has_preferred_x; 4330 ubyte single_line; 4331 ubyte active; 4332 ubyte padding1; 4333 float preferred_x; 4334 nk_text_undo_state undo; 4335 } 4336 4337 /* filter function */ 4338 nk_bool nk_filter_default (const(nk_text_edit)*, nk_rune unicode); 4339 nk_bool nk_filter_ascii (const(nk_text_edit)*, nk_rune unicode); 4340 nk_bool nk_filter_float (const(nk_text_edit)*, nk_rune unicode); 4341 nk_bool nk_filter_decimal (const(nk_text_edit)*, nk_rune unicode); 4342 nk_bool nk_filter_hex (const(nk_text_edit)*, nk_rune unicode); 4343 nk_bool nk_filter_oct (const(nk_text_edit)*, nk_rune unicode); 4344 nk_bool nk_filter_binary (const(nk_text_edit)*, nk_rune unicode); 4345 4346 /* text editor */ 4347 4348 void nk_textedit_init (nk_text_edit*, nk_allocator*, nk_size size); 4349 void nk_textedit_init_fixed (nk_text_edit*, void* memory, nk_size size); 4350 void nk_textedit_free (nk_text_edit*); 4351 void nk_textedit_text (nk_text_edit*, const(char)*, int total_len); 4352 void nk_textedit_delete (nk_text_edit*, int where, int len); 4353 void nk_textedit_delete_selection (nk_text_edit*); 4354 void nk_textedit_select_all (nk_text_edit*); 4355 nk_bool nk_textedit_cut (nk_text_edit*); 4356 nk_bool nk_textedit_paste (nk_text_edit*, const(char)*, int len); 4357 void nk_textedit_undo (nk_text_edit*); 4358 void nk_textedit_redo (nk_text_edit*); 4359 4360 /* =============================================================== 4361 * 4362 * DRAWING 4363 * 4364 * ===============================================================*/ 4365 /* This library was designed to be render backend agnostic so it does 4366 not draw anything to screen. Instead all drawn shapes, widgets 4367 are made of, are buffered into memory and make up a command queue. 4368 Each frame therefore fills the command buffer with draw commands 4369 that then need to be executed by the user and his own render backend. 4370 After that the command buffer needs to be cleared and a new frame can be 4371 started. It is probably important to note that the command buffer is the main 4372 drawing API and the optional vertex buffer API only takes this format and 4373 converts it into a hardware accessible format. 4374 4375 To use the command queue to draw your own widgets you can access the 4376 command buffer of each window by calling `nk_window_get_canvas` after 4377 previously having called `nk_begin`: 4378 4379 void draw_red_rectangle_widget(struct nk_context *ctx) 4380 { 4381 struct nk_command_buffer *canvas; 4382 struct nk_input *input = &ctx->input; 4383 canvas = nk_window_get_canvas(ctx); 4384 4385 struct nk_rect space; 4386 enum nk_widget_layout_states state; 4387 state = nk_widget(&space, ctx); 4388 if (!state) return; 4389 4390 if (state != NK_WIDGET_ROM) 4391 update_your_widget_by_user_input(...); 4392 nk_fill_rect(canvas, space, 0, nk_rgb(255,0,0)); 4393 } 4394 4395 if (nk_begin(...)) { 4396 nk_layout_row_dynamic(ctx, 25, 1); 4397 draw_red_rectangle_widget(ctx); 4398 } 4399 nk_end(..) 4400 4401 Important to know if you want to create your own widgets is the `nk_widget` 4402 call. It allocates space on the panel reserved for this widget to be used, 4403 but also returns the state of the widget space. If your widget is not seen and does 4404 not have to be updated it is '0' and you can just return. If it only has 4405 to be drawn the state will be `NK_WIDGET_ROM` otherwise you can do both 4406 update and draw your widget. The reason for separating is to only draw and 4407 update what is actually necessary which is crucial for performance. 4408 */ 4409 enum nk_command_type 4410 { 4411 NK_COMMAND_NOP = 0, 4412 NK_COMMAND_SCISSOR = 1, 4413 NK_COMMAND_LINE = 2, 4414 NK_COMMAND_CURVE = 3, 4415 NK_COMMAND_RECT = 4, 4416 NK_COMMAND_RECT_FILLED = 5, 4417 NK_COMMAND_RECT_MULTI_COLOR = 6, 4418 NK_COMMAND_CIRCLE = 7, 4419 NK_COMMAND_CIRCLE_FILLED = 8, 4420 NK_COMMAND_ARC = 9, 4421 NK_COMMAND_ARC_FILLED = 10, 4422 NK_COMMAND_TRIANGLE = 11, 4423 NK_COMMAND_TRIANGLE_FILLED = 12, 4424 NK_COMMAND_POLYGON = 13, 4425 NK_COMMAND_POLYGON_FILLED = 14, 4426 NK_COMMAND_POLYLINE = 15, 4427 NK_COMMAND_TEXT = 16, 4428 NK_COMMAND_IMAGE = 17, 4429 NK_COMMAND_CUSTOM = 18 4430 } 4431 4432 /* command base and header of every command inside the buffer */ 4433 struct nk_command 4434 { 4435 nk_command_type type; 4436 nk_size next; 4437 } 4438 4439 struct nk_command_scissor 4440 { 4441 nk_command header; 4442 short x; 4443 short y; 4444 ushort w; 4445 ushort h; 4446 } 4447 4448 struct nk_command_line 4449 { 4450 nk_command header; 4451 ushort line_thickness; 4452 nk_vec2i_ begin; 4453 nk_vec2i_ end; 4454 nk_color color; 4455 } 4456 4457 struct nk_command_curve 4458 { 4459 nk_command header; 4460 ushort line_thickness; 4461 nk_vec2i_ begin; 4462 nk_vec2i_ end; 4463 nk_vec2i_[2] ctrl; 4464 nk_color color; 4465 } 4466 4467 struct nk_command_rect 4468 { 4469 nk_command header; 4470 ushort rounding; 4471 ushort line_thickness; 4472 short x; 4473 short y; 4474 ushort w; 4475 ushort h; 4476 nk_color color; 4477 } 4478 4479 struct nk_command_rect_filled 4480 { 4481 nk_command header; 4482 ushort rounding; 4483 short x; 4484 short y; 4485 ushort w; 4486 ushort h; 4487 nk_color color; 4488 } 4489 4490 struct nk_command_rect_multi_color 4491 { 4492 nk_command header; 4493 short x; 4494 short y; 4495 ushort w; 4496 ushort h; 4497 nk_color left; 4498 nk_color top; 4499 nk_color bottom; 4500 nk_color right; 4501 } 4502 4503 struct nk_command_triangle 4504 { 4505 nk_command header; 4506 ushort line_thickness; 4507 nk_vec2i_ a; 4508 nk_vec2i_ b; 4509 nk_vec2i_ c; 4510 nk_color color; 4511 } 4512 4513 struct nk_command_triangle_filled 4514 { 4515 nk_command header; 4516 nk_vec2i_ a; 4517 nk_vec2i_ b; 4518 nk_vec2i_ c; 4519 nk_color color; 4520 } 4521 4522 struct nk_command_circle 4523 { 4524 nk_command header; 4525 short x; 4526 short y; 4527 ushort line_thickness; 4528 ushort w; 4529 ushort h; 4530 nk_color color; 4531 } 4532 4533 struct nk_command_circle_filled 4534 { 4535 nk_command header; 4536 short x; 4537 short y; 4538 ushort w; 4539 ushort h; 4540 nk_color color; 4541 } 4542 4543 struct nk_command_arc 4544 { 4545 nk_command header; 4546 short cx; 4547 short cy; 4548 ushort r; 4549 ushort line_thickness; 4550 float[2] a; 4551 nk_color color; 4552 } 4553 4554 struct nk_command_arc_filled 4555 { 4556 nk_command header; 4557 short cx; 4558 short cy; 4559 ushort r; 4560 float[2] a; 4561 nk_color color; 4562 } 4563 4564 struct nk_command_polygon 4565 { 4566 nk_command header; 4567 nk_color color; 4568 ushort line_thickness; 4569 ushort point_count; 4570 nk_vec2i_[1] points; 4571 } 4572 4573 struct nk_command_polygon_filled 4574 { 4575 nk_command header; 4576 nk_color color; 4577 ushort point_count; 4578 nk_vec2i_[1] points; 4579 } 4580 4581 struct nk_command_polyline 4582 { 4583 nk_command header; 4584 nk_color color; 4585 ushort line_thickness; 4586 ushort point_count; 4587 nk_vec2i_[1] points; 4588 } 4589 4590 struct nk_command_image 4591 { 4592 nk_command header; 4593 short x; 4594 short y; 4595 ushort w; 4596 ushort h; 4597 nk_image_ img; 4598 nk_color col; 4599 } 4600 4601 alias nk_command_custom_callback = void function ( 4602 void* canvas, 4603 short x, 4604 short y, 4605 ushort w, 4606 ushort h, 4607 nk_handle callback_data); 4608 4609 struct nk_command_custom 4610 { 4611 nk_command header; 4612 short x; 4613 short y; 4614 ushort w; 4615 ushort h; 4616 nk_handle callback_data; 4617 nk_command_custom_callback callback; 4618 } 4619 4620 struct nk_command_text 4621 { 4622 nk_command header; 4623 const(nk_user_font)* font; 4624 nk_color background; 4625 nk_color foreground; 4626 short x; 4627 short y; 4628 ushort w; 4629 ushort h; 4630 float height; 4631 int length; 4632 char[1] string; 4633 } 4634 4635 enum nk_command_clipping 4636 { 4637 NK_CLIPPING_OFF = .nk_false, 4638 NK_CLIPPING_ON = .nk_true 4639 } 4640 4641 struct nk_command_buffer 4642 { 4643 nk_buffer* base; 4644 nk_rect_ clip; 4645 int use_clipping; 4646 nk_handle userdata; 4647 nk_size begin; 4648 nk_size end; 4649 nk_size last; 4650 } 4651 4652 /* shape outlines */ 4653 void nk_stroke_line (nk_command_buffer* b, float x0, float y0, float x1, float y1, float line_thickness, nk_color); 4654 void nk_stroke_curve (nk_command_buffer*, float, float, float, float, float, float, float, float, float line_thickness, nk_color); 4655 void nk_stroke_rect (nk_command_buffer*, nk_rect_, float rounding, float line_thickness, nk_color); 4656 void nk_stroke_circle (nk_command_buffer*, nk_rect_, float line_thickness, nk_color); 4657 void nk_stroke_arc (nk_command_buffer*, float cx, float cy, float radius, float a_min, float a_max, float line_thickness, nk_color); 4658 void nk_stroke_triangle (nk_command_buffer*, float, float, float, float, float, float, float line_thichness, nk_color); 4659 void nk_stroke_polyline (nk_command_buffer*, float* points, int point_count, float line_thickness, nk_color col); 4660 void nk_stroke_polygon (nk_command_buffer*, float*, int point_count, float line_thickness, nk_color); 4661 4662 /* filled shades */ 4663 void nk_fill_rect (nk_command_buffer*, nk_rect_, float rounding, nk_color); 4664 void nk_fill_rect_multi_color (nk_command_buffer*, nk_rect_, nk_color left, nk_color top, nk_color right, nk_color bottom); 4665 void nk_fill_circle (nk_command_buffer*, nk_rect_, nk_color); 4666 void nk_fill_arc (nk_command_buffer*, float cx, float cy, float radius, float a_min, float a_max, nk_color); 4667 void nk_fill_triangle (nk_command_buffer*, float x0, float y0, float x1, float y1, float x2, float y2, nk_color); 4668 void nk_fill_polygon (nk_command_buffer*, float*, int point_count, nk_color); 4669 4670 /* misc */ 4671 void nk_draw_image (nk_command_buffer*, nk_rect_, const(nk_image_)*, nk_color); 4672 void nk_draw_nine_slice (nk_command_buffer*, nk_rect_, const(nk_nine_slice)*, nk_color); 4673 void nk_draw_text (nk_command_buffer*, nk_rect_, const(char)* text, int len, const(nk_user_font)*, nk_color, nk_color); 4674 void nk_push_scissor (nk_command_buffer*, nk_rect_); 4675 void nk_push_custom (nk_command_buffer*, nk_rect_, nk_command_custom_callback, nk_handle usr); 4676 4677 /* =============================================================== 4678 * 4679 * INPUT 4680 * 4681 * ===============================================================*/ 4682 struct nk_mouse_button 4683 { 4684 nk_bool down; 4685 uint clicked; 4686 nk_vec2_ clicked_pos; 4687 } 4688 4689 struct nk_mouse 4690 { 4691 nk_mouse_button[nk_buttons.NK_BUTTON_MAX] buttons; 4692 nk_vec2_ pos; 4693 4694 nk_vec2_ prev; 4695 nk_vec2_ delta; 4696 nk_vec2_ scroll_delta; 4697 ubyte grab; 4698 ubyte grabbed; 4699 ubyte ungrab; 4700 } 4701 4702 struct nk_key 4703 { 4704 nk_bool down; 4705 uint clicked; 4706 } 4707 4708 struct nk_keyboard 4709 { 4710 nk_key[nk_keys.NK_KEY_MAX] keys; 4711 char[NK_INPUT_MAX] text; 4712 int text_len; 4713 } 4714 4715 struct nk_input 4716 { 4717 nk_keyboard keyboard; 4718 nk_mouse mouse; 4719 } 4720 4721 nk_bool nk_input_has_mouse_click (const(nk_input)*, nk_buttons); 4722 nk_bool nk_input_has_mouse_click_in_rect (const(nk_input)*, nk_buttons, nk_rect_); 4723 nk_bool nk_input_has_mouse_click_in_button_rect (const(nk_input)*, nk_buttons, nk_rect_); 4724 nk_bool nk_input_has_mouse_click_down_in_rect (const(nk_input)*, nk_buttons, nk_rect_, nk_bool down); 4725 nk_bool nk_input_is_mouse_click_in_rect (const(nk_input)*, nk_buttons, nk_rect_); 4726 nk_bool nk_input_is_mouse_click_down_in_rect (const(nk_input)* i, nk_buttons id, nk_rect_ b, nk_bool down); 4727 nk_bool nk_input_any_mouse_click_in_rect (const(nk_input)*, nk_rect_); 4728 nk_bool nk_input_is_mouse_prev_hovering_rect (const(nk_input)*, nk_rect_); 4729 nk_bool nk_input_is_mouse_hovering_rect (const(nk_input)*, nk_rect_); 4730 nk_bool nk_input_mouse_clicked (const(nk_input)*, nk_buttons, nk_rect_); 4731 nk_bool nk_input_is_mouse_down (const(nk_input)*, nk_buttons); 4732 nk_bool nk_input_is_mouse_pressed (const(nk_input)*, nk_buttons); 4733 nk_bool nk_input_is_mouse_released (const(nk_input)*, nk_buttons); 4734 nk_bool nk_input_is_key_pressed (const(nk_input)*, nk_keys); 4735 nk_bool nk_input_is_key_released (const(nk_input)*, nk_keys); 4736 nk_bool nk_input_is_key_down (const(nk_input)*, nk_keys); 4737 4738 /* =============================================================== 4739 * 4740 * DRAW LIST 4741 * 4742 * ===============================================================*/ 4743 4744 /* The optional vertex buffer draw list provides a 2D drawing context 4745 with antialiasing functionality which takes basic filled or outlined shapes 4746 or a path and outputs vertexes, elements and draw commands. 4747 The actual draw list API is not required to be used directly while using this 4748 library since converting the default library draw command output is done by 4749 just calling `nk_convert` but I decided to still make this library accessible 4750 since it can be useful. 4751 4752 The draw list is based on a path buffering and polygon and polyline 4753 rendering API which allows a lot of ways to draw 2D content to screen. 4754 In fact it is probably more powerful than needed but allows even more crazy 4755 things than this library provides by default. 4756 */ 4757 4758 /* build up path has no connection back to the beginning */ 4759 4760 /* build up path has a connection back to the beginning */ 4761 4762 /* number of elements in the current draw batch */ 4763 4764 /* current screen clipping rectangle */ 4765 4766 /* current texture to set */ 4767 4768 /* draw list */ 4769 4770 /* drawing */ 4771 4772 /* path */ 4773 4774 /* stroke */ 4775 4776 /* fill */ 4777 4778 /* misc */ 4779 4780 /* =============================================================== 4781 * 4782 * GUI 4783 * 4784 * ===============================================================*/ 4785 enum nk_style_item_type 4786 { 4787 NK_STYLE_ITEM_COLOR = 0, 4788 NK_STYLE_ITEM_IMAGE = 1, 4789 NK_STYLE_ITEM_NINE_SLICE = 2 4790 } 4791 4792 union nk_style_item_data 4793 { 4794 nk_color color; 4795 nk_image_ image; 4796 nk_nine_slice slice; 4797 } 4798 4799 struct nk_style_item 4800 { 4801 nk_style_item_type type; 4802 nk_style_item_data data; 4803 } 4804 4805 struct nk_style_text 4806 { 4807 nk_color color; 4808 nk_vec2_ padding; 4809 } 4810 4811 struct nk_style_button 4812 { 4813 /* background */ 4814 nk_style_item normal; 4815 nk_style_item hover; 4816 nk_style_item active; 4817 nk_color border_color; 4818 4819 /* text */ 4820 nk_color text_background; 4821 nk_color text_normal; 4822 nk_color text_hover; 4823 nk_color text_active; 4824 nk_flags text_alignment; 4825 4826 /* properties */ 4827 float border; 4828 float rounding; 4829 nk_vec2_ padding; 4830 nk_vec2_ image_padding; 4831 nk_vec2_ touch_padding; 4832 4833 /* optional user callbacks */ 4834 nk_handle userdata; 4835 void function (nk_command_buffer*, nk_handle userdata) draw_begin; 4836 void function (nk_command_buffer*, nk_handle userdata) draw_end; 4837 } 4838 4839 struct nk_style_toggle 4840 { 4841 /* background */ 4842 nk_style_item normal; 4843 nk_style_item hover; 4844 nk_style_item active; 4845 nk_color border_color; 4846 4847 /* cursor */ 4848 nk_style_item cursor_normal; 4849 nk_style_item cursor_hover; 4850 4851 /* text */ 4852 nk_color text_normal; 4853 nk_color text_hover; 4854 nk_color text_active; 4855 nk_color text_background; 4856 nk_flags text_alignment; 4857 4858 /* properties */ 4859 nk_vec2_ padding; 4860 nk_vec2_ touch_padding; 4861 float spacing; 4862 float border; 4863 4864 /* optional user callbacks */ 4865 nk_handle userdata; 4866 void function (nk_command_buffer*, nk_handle) draw_begin; 4867 void function (nk_command_buffer*, nk_handle) draw_end; 4868 } 4869 4870 struct nk_style_selectable 4871 { 4872 /* background (inactive) */ 4873 nk_style_item normal; 4874 nk_style_item hover; 4875 nk_style_item pressed; 4876 4877 /* background (active) */ 4878 nk_style_item normal_active; 4879 nk_style_item hover_active; 4880 nk_style_item pressed_active; 4881 4882 /* text color (inactive) */ 4883 nk_color text_normal; 4884 nk_color text_hover; 4885 nk_color text_pressed; 4886 4887 /* text color (active) */ 4888 nk_color text_normal_active; 4889 nk_color text_hover_active; 4890 nk_color text_pressed_active; 4891 nk_color text_background; 4892 nk_flags text_alignment; 4893 4894 /* properties */ 4895 float rounding; 4896 nk_vec2_ padding; 4897 nk_vec2_ touch_padding; 4898 nk_vec2_ image_padding; 4899 4900 /* optional user callbacks */ 4901 nk_handle userdata; 4902 void function (nk_command_buffer*, nk_handle) draw_begin; 4903 void function (nk_command_buffer*, nk_handle) draw_end; 4904 } 4905 4906 struct nk_style_slider 4907 { 4908 /* background */ 4909 nk_style_item normal; 4910 nk_style_item hover; 4911 nk_style_item active; 4912 nk_color border_color; 4913 4914 /* background bar */ 4915 nk_color bar_normal; 4916 nk_color bar_hover; 4917 nk_color bar_active; 4918 nk_color bar_filled; 4919 4920 /* cursor */ 4921 nk_style_item cursor_normal; 4922 nk_style_item cursor_hover; 4923 nk_style_item cursor_active; 4924 4925 /* properties */ 4926 float border; 4927 float rounding; 4928 float bar_height; 4929 nk_vec2_ padding; 4930 nk_vec2_ spacing; 4931 nk_vec2_ cursor_size; 4932 4933 /* optional buttons */ 4934 int show_buttons; 4935 nk_style_button inc_button; 4936 nk_style_button dec_button; 4937 nk_symbol_type inc_symbol; 4938 nk_symbol_type dec_symbol; 4939 4940 /* optional user callbacks */ 4941 nk_handle userdata; 4942 void function (nk_command_buffer*, nk_handle) draw_begin; 4943 void function (nk_command_buffer*, nk_handle) draw_end; 4944 } 4945 4946 struct nk_style_progress 4947 { 4948 /* background */ 4949 nk_style_item normal; 4950 nk_style_item hover; 4951 nk_style_item active; 4952 nk_color border_color; 4953 4954 /* cursor */ 4955 nk_style_item cursor_normal; 4956 nk_style_item cursor_hover; 4957 nk_style_item cursor_active; 4958 nk_color cursor_border_color; 4959 4960 /* properties */ 4961 float rounding; 4962 float border; 4963 float cursor_border; 4964 float cursor_rounding; 4965 nk_vec2_ padding; 4966 4967 /* optional user callbacks */ 4968 nk_handle userdata; 4969 void function (nk_command_buffer*, nk_handle) draw_begin; 4970 void function (nk_command_buffer*, nk_handle) draw_end; 4971 } 4972 4973 struct nk_style_scrollbar 4974 { 4975 /* background */ 4976 nk_style_item normal; 4977 nk_style_item hover; 4978 nk_style_item active; 4979 nk_color border_color; 4980 4981 /* cursor */ 4982 nk_style_item cursor_normal; 4983 nk_style_item cursor_hover; 4984 nk_style_item cursor_active; 4985 nk_color cursor_border_color; 4986 4987 /* properties */ 4988 float border; 4989 float rounding; 4990 float border_cursor; 4991 float rounding_cursor; 4992 nk_vec2_ padding; 4993 4994 /* optional buttons */ 4995 int show_buttons; 4996 nk_style_button inc_button; 4997 nk_style_button dec_button; 4998 nk_symbol_type inc_symbol; 4999 nk_symbol_type dec_symbol; 5000 5001 /* optional user callbacks */ 5002 nk_handle userdata; 5003 void function (nk_command_buffer*, nk_handle) draw_begin; 5004 void function (nk_command_buffer*, nk_handle) draw_end; 5005 } 5006 5007 struct nk_style_edit 5008 { 5009 /* background */ 5010 nk_style_item normal; 5011 nk_style_item hover; 5012 nk_style_item active; 5013 nk_color border_color; 5014 nk_style_scrollbar scrollbar; 5015 5016 /* cursor */ 5017 nk_color cursor_normal; 5018 nk_color cursor_hover; 5019 nk_color cursor_text_normal; 5020 nk_color cursor_text_hover; 5021 5022 /* text (unselected) */ 5023 nk_color text_normal; 5024 nk_color text_hover; 5025 nk_color text_active; 5026 5027 /* text (selected) */ 5028 nk_color selected_normal; 5029 nk_color selected_hover; 5030 nk_color selected_text_normal; 5031 nk_color selected_text_hover; 5032 5033 /* properties */ 5034 float border; 5035 float rounding; 5036 float cursor_size; 5037 nk_vec2_ scrollbar_size; 5038 nk_vec2_ padding; 5039 float row_padding; 5040 } 5041 5042 struct nk_style_property 5043 { 5044 /* background */ 5045 nk_style_item normal; 5046 nk_style_item hover; 5047 nk_style_item active; 5048 nk_color border_color; 5049 5050 /* text */ 5051 nk_color label_normal; 5052 nk_color label_hover; 5053 nk_color label_active; 5054 5055 /* symbols */ 5056 nk_symbol_type sym_left; 5057 nk_symbol_type sym_right; 5058 5059 /* properties */ 5060 float border; 5061 float rounding; 5062 nk_vec2_ padding; 5063 5064 nk_style_edit edit; 5065 nk_style_button inc_button; 5066 nk_style_button dec_button; 5067 5068 /* optional user callbacks */ 5069 nk_handle userdata; 5070 void function (nk_command_buffer*, nk_handle) draw_begin; 5071 void function (nk_command_buffer*, nk_handle) draw_end; 5072 } 5073 5074 struct nk_style_chart 5075 { 5076 /* colors */ 5077 nk_style_item background; 5078 nk_color border_color; 5079 nk_color selected_color; 5080 nk_color color; 5081 5082 /* properties */ 5083 float border; 5084 float rounding; 5085 nk_vec2_ padding; 5086 } 5087 5088 struct nk_style_combo 5089 { 5090 /* background */ 5091 nk_style_item normal; 5092 nk_style_item hover; 5093 nk_style_item active; 5094 nk_color border_color; 5095 5096 /* label */ 5097 nk_color label_normal; 5098 nk_color label_hover; 5099 nk_color label_active; 5100 5101 /* symbol */ 5102 nk_color symbol_normal; 5103 nk_color symbol_hover; 5104 nk_color symbol_active; 5105 5106 /* button */ 5107 nk_style_button button; 5108 nk_symbol_type sym_normal; 5109 nk_symbol_type sym_hover; 5110 nk_symbol_type sym_active; 5111 5112 /* properties */ 5113 float border; 5114 float rounding; 5115 nk_vec2_ content_padding; 5116 nk_vec2_ button_padding; 5117 nk_vec2_ spacing; 5118 } 5119 5120 struct nk_style_tab 5121 { 5122 /* background */ 5123 nk_style_item background; 5124 nk_color border_color; 5125 nk_color text; 5126 5127 /* button */ 5128 nk_style_button tab_maximize_button; 5129 nk_style_button tab_minimize_button; 5130 nk_style_button node_maximize_button; 5131 nk_style_button node_minimize_button; 5132 nk_symbol_type sym_minimize; 5133 nk_symbol_type sym_maximize; 5134 5135 /* properties */ 5136 float border; 5137 float rounding; 5138 float indent; 5139 nk_vec2_ padding; 5140 nk_vec2_ spacing; 5141 } 5142 5143 enum nk_style_header_align 5144 { 5145 NK_HEADER_LEFT = 0, 5146 NK_HEADER_RIGHT = 1 5147 } 5148 5149 struct nk_style_window_header 5150 { 5151 /* background */ 5152 nk_style_item normal; 5153 nk_style_item hover; 5154 nk_style_item active; 5155 5156 /* button */ 5157 nk_style_button close_button; 5158 nk_style_button minimize_button; 5159 nk_symbol_type close_symbol; 5160 nk_symbol_type minimize_symbol; 5161 nk_symbol_type maximize_symbol; 5162 5163 /* title */ 5164 nk_color label_normal; 5165 nk_color label_hover; 5166 nk_color label_active; 5167 5168 /* properties */ 5169 nk_style_header_align align_; 5170 nk_vec2_ padding; 5171 nk_vec2_ label_padding; 5172 nk_vec2_ spacing; 5173 } 5174 5175 struct nk_style_window 5176 { 5177 nk_style_window_header header; 5178 nk_style_item fixed_background; 5179 nk_color background; 5180 5181 nk_color border_color; 5182 nk_color popup_border_color; 5183 nk_color combo_border_color; 5184 nk_color contextual_border_color; 5185 nk_color menu_border_color; 5186 nk_color group_border_color; 5187 nk_color tooltip_border_color; 5188 nk_style_item scaler; 5189 5190 float border; 5191 float combo_border; 5192 float contextual_border; 5193 float menu_border; 5194 float group_border; 5195 float tooltip_border; 5196 float popup_border; 5197 float min_row_height_padding; 5198 5199 float rounding; 5200 nk_vec2_ spacing; 5201 nk_vec2_ scrollbar_size; 5202 nk_vec2_ min_size; 5203 5204 nk_vec2_ padding; 5205 nk_vec2_ group_padding; 5206 nk_vec2_ popup_padding; 5207 nk_vec2_ combo_padding; 5208 nk_vec2_ contextual_padding; 5209 nk_vec2_ menu_padding; 5210 nk_vec2_ tooltip_padding; 5211 } 5212 5213 struct nk_style 5214 { 5215 const(nk_user_font)* font; 5216 const(nk_cursor)*[nk_style_cursor.NK_CURSOR_COUNT] cursors; 5217 const(nk_cursor)* cursor_active; 5218 nk_cursor* cursor_last; 5219 int cursor_visible; 5220 5221 nk_style_text text; 5222 nk_style_button button; 5223 nk_style_button contextual_button; 5224 nk_style_button menu_button; 5225 nk_style_toggle option; 5226 nk_style_toggle checkbox; 5227 nk_style_selectable selectable; 5228 nk_style_slider slider; 5229 nk_style_progress progress; 5230 nk_style_property property; 5231 nk_style_edit edit; 5232 nk_style_chart chart; 5233 nk_style_scrollbar scrollh; 5234 nk_style_scrollbar scrollv; 5235 nk_style_tab tab; 5236 nk_style_combo combo; 5237 nk_style_window window; 5238 } 5239 5240 nk_style_item nk_style_item_color (nk_color); 5241 nk_style_item nk_style_item_image (nk_image_ img); 5242 nk_style_item nk_style_item_nine_slice (nk_nine_slice slice); 5243 nk_style_item nk_style_item_hide (); 5244 5245 /*============================================================== 5246 * PANEL 5247 * =============================================================*/ 5248 5249 enum NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS = 16; 5250 5251 enum NK_CHART_MAX_SLOT = 4; 5252 5253 enum nk_panel_type 5254 { 5255 NK_PANEL_NONE = 0, 5256 NK_PANEL_WINDOW = NK_FLAG(0), 5257 NK_PANEL_GROUP = NK_FLAG(1), 5258 NK_PANEL_POPUP = NK_FLAG(2), 5259 NK_PANEL_CONTEXTUAL = NK_FLAG(4), 5260 NK_PANEL_COMBO = NK_FLAG(5), 5261 NK_PANEL_MENU = NK_FLAG(6), 5262 NK_PANEL_TOOLTIP = NK_FLAG(7) 5263 } 5264 5265 enum nk_panel_set 5266 { 5267 NK_PANEL_SET_NONBLOCK = nk_panel_type.NK_PANEL_CONTEXTUAL | nk_panel_type.NK_PANEL_COMBO | nk_panel_type.NK_PANEL_MENU | nk_panel_type.NK_PANEL_TOOLTIP, 5268 NK_PANEL_SET_POPUP = cast(nk_panel_set)(NK_PANEL_SET_NONBLOCK | nk_panel_type.NK_PANEL_POPUP), 5269 NK_PANEL_SET_SUB = cast(nk_panel_set)(NK_PANEL_SET_POPUP | nk_panel_type.NK_PANEL_GROUP) 5270 } 5271 5272 struct nk_chart_slot 5273 { 5274 nk_chart_type type; 5275 nk_color color; 5276 nk_color highlight; 5277 float min; 5278 float max; 5279 float range; 5280 int count; 5281 nk_vec2_ last; 5282 int index; 5283 } 5284 5285 struct nk_chart 5286 { 5287 int slot; 5288 float x; 5289 float y; 5290 float w; 5291 float h; 5292 nk_chart_slot[NK_CHART_MAX_SLOT] slots; 5293 } 5294 5295 enum nk_panel_row_layout_type 5296 { 5297 NK_LAYOUT_DYNAMIC_FIXED = 0, 5298 NK_LAYOUT_DYNAMIC_ROW = 1, 5299 NK_LAYOUT_DYNAMIC_FREE = 2, 5300 NK_LAYOUT_DYNAMIC = 3, 5301 NK_LAYOUT_STATIC_FIXED = 4, 5302 NK_LAYOUT_STATIC_ROW = 5, 5303 NK_LAYOUT_STATIC_FREE = 6, 5304 NK_LAYOUT_STATIC = 7, 5305 NK_LAYOUT_TEMPLATE = 8, 5306 NK_LAYOUT_COUNT = 9 5307 } 5308 5309 struct nk_row_layout 5310 { 5311 nk_panel_row_layout_type type; 5312 int index; 5313 float height; 5314 float min_height; 5315 int columns; 5316 const(float)* ratio; 5317 float item_width; 5318 float item_height; 5319 float item_offset; 5320 float filled; 5321 nk_rect_ item; 5322 int tree_depth; 5323 float[NK_MAX_LAYOUT_ROW_TEMPLATE_COLUMNS] templates; 5324 } 5325 5326 struct nk_popup_buffer 5327 { 5328 nk_size begin; 5329 nk_size parent; 5330 nk_size last; 5331 nk_size end; 5332 nk_bool active; 5333 } 5334 5335 struct nk_menu_state 5336 { 5337 float x; 5338 float y; 5339 float w; 5340 float h; 5341 nk_scroll offset; 5342 } 5343 5344 struct nk_panel 5345 { 5346 nk_panel_type type; 5347 nk_flags flags; 5348 nk_rect_ bounds; 5349 nk_uint* offset_x; 5350 nk_uint* offset_y; 5351 float at_x; 5352 float at_y; 5353 float max_x; 5354 float footer_height; 5355 float header_height; 5356 float border; 5357 uint has_scrolling; 5358 nk_rect_ clip; 5359 nk_menu_state menu; 5360 nk_row_layout row; 5361 nk_chart chart; 5362 nk_command_buffer* buffer; 5363 nk_panel* parent; 5364 } 5365 5366 /*============================================================== 5367 * WINDOW 5368 * =============================================================*/ 5369 5370 enum NK_WINDOW_MAX_NAME = 64; 5371 5372 enum nk_window_flags 5373 { 5374 NK_WINDOW_PRIVATE = NK_FLAG(11), 5375 NK_WINDOW_DYNAMIC = NK_WINDOW_PRIVATE, 5376 /* special window type growing up in height while being filled to a certain maximum height */ 5377 NK_WINDOW_ROM = NK_FLAG(12), 5378 /* sets window widgets into a read only mode and does not allow input changes */ 5379 NK_WINDOW_NOT_INTERACTIVE = NK_WINDOW_ROM | nk_panel_flags.NK_WINDOW_NO_INPUT, 5380 /* prevents all interaction caused by input to either window or widgets inside */ 5381 NK_WINDOW_HIDDEN = NK_FLAG(13), 5382 /* Hides window and stops any window interaction and drawing */ 5383 NK_WINDOW_CLOSED = NK_FLAG(14), 5384 /* Directly closes and frees the window at the end of the frame */ 5385 NK_WINDOW_MINIMIZED = NK_FLAG(15), 5386 /* marks the window as minimized */ 5387 NK_WINDOW_REMOVE_ROM = NK_FLAG(16) 5388 /* Removes read only mode at the end of the window */ 5389 } 5390 5391 struct nk_popup_state 5392 { 5393 nk_window* win; 5394 nk_panel_type type; 5395 nk_popup_buffer buf; 5396 nk_hash name; 5397 nk_bool active; 5398 uint combo_count; 5399 uint con_count; 5400 uint con_old; 5401 uint active_con; 5402 nk_rect_ header; 5403 } 5404 5405 struct nk_edit_state 5406 { 5407 nk_hash name; 5408 uint seq; 5409 uint old; 5410 int active; 5411 int prev; 5412 int cursor; 5413 int sel_start; 5414 int sel_end; 5415 nk_scroll scrollbar; 5416 ubyte mode; 5417 ubyte single_line; 5418 } 5419 5420 struct nk_property_state 5421 { 5422 int active; 5423 int prev; 5424 char[NK_MAX_NUMBER_BUFFER] buffer; 5425 int length; 5426 int cursor; 5427 int select_start; 5428 int select_end; 5429 nk_hash name; 5430 uint seq; 5431 uint old; 5432 int state; 5433 } 5434 5435 struct nk_window 5436 { 5437 uint seq; 5438 nk_hash name; 5439 char[NK_WINDOW_MAX_NAME] name_string; 5440 nk_flags flags; 5441 5442 nk_rect_ bounds; 5443 nk_scroll scrollbar; 5444 nk_command_buffer buffer; 5445 nk_panel* layout; 5446 float scrollbar_hiding_timer; 5447 5448 /* persistent widget state */ 5449 nk_property_state property; 5450 nk_popup_state popup; 5451 nk_edit_state edit; 5452 uint scrolled; 5453 5454 nk_table* tables; 5455 uint table_count; 5456 5457 /* window list hooks */ 5458 nk_window* next; 5459 nk_window* prev; 5460 nk_window* parent; 5461 } 5462 5463 /*============================================================== 5464 * STACK 5465 * =============================================================*/ 5466 /* The style modifier stack can be used to temporarily change a 5467 * property inside `nk_style`. For example if you want a special 5468 * red button you can temporarily push the old button color onto a stack 5469 * draw the button with a red color and then you just pop the old color 5470 * back from the stack: 5471 * 5472 * nk_style_push_style_item(ctx, &ctx->style.button.normal, nk_style_item_color(nk_rgb(255,0,0))); 5473 * nk_style_push_style_item(ctx, &ctx->style.button.hover, nk_style_item_color(nk_rgb(255,0,0))); 5474 * nk_style_push_style_item(ctx, &ctx->style.button.active, nk_style_item_color(nk_rgb(255,0,0))); 5475 * nk_style_push_vec2(ctx, &cx->style.button.padding, nk_vec2(2,2)); 5476 * 5477 * nk_button(...); 5478 * 5479 * nk_style_pop_style_item(ctx); 5480 * nk_style_pop_style_item(ctx); 5481 * nk_style_pop_style_item(ctx); 5482 * nk_style_pop_vec2(ctx); 5483 * 5484 * Nuklear has a stack for style_items, float properties, vector properties, 5485 * flags, colors, fonts and for button_behavior. Each has it's own fixed size stack 5486 * which can be changed at compile time. 5487 */ 5488 enum NK_BUTTON_BEHAVIOR_STACK_SIZE = 8; 5489 5490 enum NK_FONT_STACK_SIZE = 8; 5491 5492 enum NK_STYLE_ITEM_STACK_SIZE = 16; 5493 5494 enum NK_FLOAT_STACK_SIZE = 32; 5495 5496 enum NK_VECTOR_STACK_SIZE = 16; 5497 5498 enum NK_FLAGS_STACK_SIZE = 32; 5499 5500 enum NK_COLOR_STACK_SIZE = 32; 5501 5502 alias nk_float = float; 5503 5504 // #define NK_CONFIGURATION_STACK_TYPE(prefix, name, type)\ 5505 // struct nk_config_stack_##name##_element {\ 5506 // prefix##_##type *address;\ 5507 // prefix##_##type old_value;\ 5508 // } 5509 // #define NK_CONFIG_STACK(type,size)\ 5510 // struct nk_config_stack_##type {\ 5511 // int head;\ 5512 // struct nk_config_stack_##type##_element elements[size];\ 5513 // } 5514 template NK_CONFIGURATION_STACK_TYPE(string prefix, string name, string type) { 5515 import std.format; 5516 enum NK_CONFIGURATION_STACK_TYPE = 5517 format!"struct nk_config_stack_%s_element { %s_%s *address; %s_%s old_value; }"(name, prefix, type, prefix, type); 5518 } 5519 template NK_CONFIG_STACK(string type, string size) { 5520 import std.format; 5521 enum NK_CONFIG_STACK = format!"struct nk_config_stack_%s { int head; nk_config_stack_%s_element[%s] elements; }"(type, type, size); 5522 } 5523 5524 // NK_CONFIGURATION_STACK_TYPE(struct nk, style_item, style_item); 5525 // NK_CONFIGURATION_STACK_TYPE(nk ,float, float); 5526 // NK_CONFIGURATION_STACK_TYPE(struct nk, vec2, vec2); 5527 // NK_CONFIGURATION_STACK_TYPE(nk ,flags, flags); 5528 // NK_CONFIGURATION_STACK_TYPE(struct nk, color, color); 5529 // NK_CONFIGURATION_STACK_TYPE(const struct nk, user_font, user_font*); 5530 // NK_CONFIGURATION_STACK_TYPE(enum nk, button_behavior, button_behavior); 5531 mixin(NK_CONFIGURATION_STACK_TYPE!("nk", "style_item", "style_item")); 5532 mixin(NK_CONFIGURATION_STACK_TYPE!("nk", "float", "float")); 5533 mixin(NK_CONFIGURATION_STACK_TYPE!("nk", "vec2", "vec2_")); 5534 mixin(NK_CONFIGURATION_STACK_TYPE!("nk", "flags", "flags")); 5535 mixin(NK_CONFIGURATION_STACK_TYPE!("nk", "color", "color")); 5536 mixin(NK_CONFIGURATION_STACK_TYPE!("const nk", "user_font", "user_font*")); 5537 mixin(NK_CONFIGURATION_STACK_TYPE!("nk", "button_behavior", "button_behavior")); 5538 5539 // NK_CONFIG_STACK(style_item, NK_STYLE_ITEM_STACK_SIZE); 5540 // NK_CONFIG_STACK(float, NK_FLOAT_STACK_SIZE); 5541 // NK_CONFIG_STACK(vec2, NK_VECTOR_STACK_SIZE); 5542 // NK_CONFIG_STACK(flags, NK_FLAGS_STACK_SIZE); 5543 // NK_CONFIG_STACK(color, NK_COLOR_STACK_SIZE); 5544 // NK_CONFIG_STACK(user_font, NK_FONT_STACK_SIZE); 5545 // NK_CONFIG_STACK(button_behavior, NK_BUTTON_BEHAVIOR_STACK_SIZE); 5546 mixin(NK_CONFIG_STACK!("style_item", "NK_STYLE_ITEM_STACK_SIZE")); 5547 mixin(NK_CONFIG_STACK!("float", "NK_FLOAT_STACK_SIZE")); 5548 mixin(NK_CONFIG_STACK!("vec2", "NK_VECTOR_STACK_SIZE")); 5549 mixin(NK_CONFIG_STACK!("flags", "NK_FLAGS_STACK_SIZE")); 5550 mixin(NK_CONFIG_STACK!("color", "NK_COLOR_STACK_SIZE")); 5551 mixin(NK_CONFIG_STACK!("user_font", "NK_FONT_STACK_SIZE")); 5552 mixin(NK_CONFIG_STACK!("button_behavior", "NK_BUTTON_BEHAVIOR_STACK_SIZE")); 5553 5554 struct nk_configuration_stacks { 5555 // struct nk_config_stack_style_item style_items; 5556 // struct nk_config_stack_float floats; 5557 // struct nk_config_stack_vec2 vectors; 5558 // struct nk_config_stack_flags flags; 5559 // struct nk_config_stack_color colors; 5560 // struct nk_config_stack_user_font fonts; 5561 // struct nk_config_stack_button_behavior button_behaviors; 5562 nk_config_stack_style_item style_items; 5563 nk_config_stack_float floats; 5564 nk_config_stack_vec2 vectors; 5565 nk_config_stack_flags flags; 5566 nk_config_stack_color colors; 5567 nk_config_stack_user_font fonts; 5568 nk_config_stack_button_behavior button_behaviors; 5569 } 5570 5571 /*============================================================== 5572 * CONTEXT 5573 * =============================================================*/ 5574 enum NK_VALUE_PAGE_CAPACITY = ((NK_MAX(nk_window.sizeof, nk_panel.sizeof) / nk_uint.sizeof)) / 2; 5575 5576 struct nk_table 5577 { 5578 uint seq; 5579 uint size; 5580 nk_hash[59] keys; 5581 nk_uint[59] values; 5582 nk_table* next; 5583 nk_table* prev; 5584 } 5585 5586 union nk_page_data 5587 { 5588 nk_table tbl; 5589 nk_panel pan; 5590 nk_window win; 5591 } 5592 5593 struct nk_page_element 5594 { 5595 nk_page_data data; 5596 nk_page_element* next; 5597 nk_page_element* prev; 5598 } 5599 5600 struct nk_page 5601 { 5602 uint size; 5603 nk_page* next; 5604 nk_page_element[1] win; 5605 } 5606 5607 struct nk_pool 5608 { 5609 nk_allocator alloc; 5610 nk_allocation_type type; 5611 uint page_count; 5612 nk_page* pages; 5613 nk_page_element* freelist; 5614 uint capacity; 5615 nk_size size; 5616 nk_size cap; 5617 } 5618 5619 struct nk_context 5620 { 5621 /* public: can be accessed freely */ 5622 nk_input input; 5623 nk_style style; 5624 nk_buffer memory; 5625 nk_clipboard clip; 5626 nk_flags last_widget_state; 5627 nk_button_behavior button_behavior; 5628 nk_configuration_stacks stacks; 5629 float delta_time_seconds; 5630 5631 /* private: 5632 should only be accessed if you 5633 know what you are doing */ 5634 5635 /* text editor objects are quite big because of an internal 5636 * undo/redo stack. Therefore it does not make sense to have one for 5637 * each window for temporary use cases, so I only provide *one* instance 5638 * for all windows. This works because the content is cleared anyway */ 5639 nk_text_edit text_edit; 5640 /* draw buffer used for overlay drawing operation like cursor */ 5641 nk_command_buffer overlay; 5642 5643 /* windows */ 5644 int build; 5645 int use_pool; 5646 nk_pool pool; 5647 nk_window* begin; 5648 nk_window* end; 5649 nk_window* active; 5650 nk_window* current; 5651 nk_page_element* freelist; 5652 uint count; 5653 uint seq; 5654 } 5655 5656 /* ============================================================== 5657 * MATH 5658 * =============================================================== */ 5659 enum NK_PI = 3.141592654f; 5660 // enum NK_UTF_INVALID = 0xFFFD; 5661 enum NK_MAX_FLOAT_PRECISION = 2; 5662 5663 extern (D) auto NK_UNUSED(T)(auto ref T x) 5664 { 5665 return cast(void) x; 5666 } 5667 5668 extern (D) auto NK_SATURATE(T)(auto ref T x) 5669 { 5670 return NK_MAX(0, NK_MIN(1.0f, x)); 5671 } 5672 5673 extern (D) size_t NK_LEN(T)(auto ref T a) 5674 { 5675 return a.sizeof / (a[0]).sizeof; 5676 } 5677 5678 extern (D) auto NK_ABS(T)(auto ref T a) 5679 { 5680 return (a < 0) ? -a : a; 5681 } 5682 5683 extern (D) auto NK_BETWEEN(T0, T1, T2)(auto ref T0 x, auto ref T1 a, auto ref T2 b) 5684 { 5685 return a <= x && x < b; 5686 } 5687 5688 extern (D) auto NK_INBOX(T0, T1, T2, T3, T4, T5)(auto ref T0 px, auto ref T1 py, auto ref T2 x, auto ref T3 y, auto ref T4 w, auto ref T5 h) 5689 { 5690 return NK_BETWEEN(px, x, x + w) && NK_BETWEEN(py, y, y + h); 5691 } 5692 5693 extern (D) auto NK_INTERSECT(T0, T1, T2, T3, T4, T5, T6, T7)(auto ref T0 x0, auto ref T1 y0, auto ref T2 w0, auto ref T3 h0, auto ref T4 x1, auto ref T5 y1, auto ref T6 w1, auto ref T7 h1) 5694 { 5695 return (x1 < (x0 + w0)) && (x0 < (x1 + w1)) && (y1 < (y0 + h0)) && (y0 < (y1 + h1)); 5696 } 5697 5698 extern (D) auto NK_CONTAINS(T0, T1, T2, T3, T4, T5, T6, T7)(auto ref T0 x, auto ref T1 y, auto ref T2 w, auto ref T3 h, auto ref T4 bx, auto ref T5 by, auto ref T6 bw, auto ref T7 bh) 5699 { 5700 return NK_INBOX(x, y, bx, by, bw, bh) && NK_INBOX(x + w, y + h, bx, by, bw, bh); 5701 } 5702 5703 extern (D) auto nk_vec2_sub(T0, T1)(auto ref T0 a, auto ref T1 b) 5704 { 5705 return nk_vec2(a.x - b.x, a.y - b.y); 5706 } 5707 5708 extern (D) auto nk_vec2_add(T0, T1)(auto ref T0 a, auto ref T1 b) 5709 { 5710 return nk_vec2(a.x + b.x, a.y + b.y); 5711 } 5712 5713 extern (D) auto nk_vec2_len_sqr(T)(auto ref T a) 5714 { 5715 return a.x * a.x + a.y * a.y; 5716 } 5717 5718 extern (D) auto nk_vec2_muls(T0, T1)(auto ref T0 a, auto ref T1 t) 5719 { 5720 return nk_vec2(a.x * t, a.y * t); 5721 } 5722 5723 extern (D) auto nk_zero_struct(T)(auto ref T s) 5724 { 5725 return nk_zero(&s, s.sizeof); 5726 } 5727 5728 /* ============================================================== 5729 * ALIGNMENT 5730 * =============================================================== */ 5731 /* Pointer to Integer type conversion for pointer alignment */ /* This case should work for GCC*/ 5732 extern (D) auto NK_UINT_TO_PTR(T)(auto ref T x) 5733 { 5734 return cast(void*) __PTRDIFF_TYPE__(x); 5735 } 5736 5737 extern (D) auto NK_PTR_TO_UINT(T)(auto ref T x) 5738 { 5739 return cast(nk_size) __PTRDIFF_TYPE__(x); 5740 } 5741 5742 /* works for compilers other than LLVM */ 5743 5744 /* used if we have <stdint.h> */ 5745 5746 /* generates warning but works */ 5747 5748 extern (D) auto NK_ALIGN_PTR(T0, T1)(auto ref T0 x, auto ref T1 mask) 5749 { 5750 return NK_UINT_TO_PTR(NK_PTR_TO_UINT(cast(nk_byte*) x + (mask - 1)) & ~(mask - 1)); 5751 } 5752 5753 extern (D) auto NK_ALIGN_PTR_BACK(T0, T1)(auto ref T0 x, auto ref T1 mask) 5754 { 5755 return NK_UINT_TO_PTR(NK_PTR_TO_UINT(cast(nk_byte*) x) & ~(mask - 1)); 5756 } 5757 5758 /* NK_NUKLEAR_H_ */ 5759 5760 /* standard library headers */ 5761 5762 /* malloc, free */ 5763 5764 /* fopen, fclose,... */ 5765 5766 /* valist, va_start, va_end, ... */ 5767 5768 /* If your compiler does support `vsnprintf` I would highly recommend 5769 * defining this to vsnprintf instead since `vsprintf` is basically 5770 * unbelievable unsafe and should *NEVER* be used. But I have to support 5771 * it since C89 only provides this unsafe version. */ 5772 5773 /* Make sure correct type size: 5774 * This will fire with a negative subscript error if the type sizes 5775 * are set incorrectly by the compiler, and compile out if not */ 5776 5777 /* widget */ 5778 5779 /* math */ 5780 5781 /* util */ 5782 5783 /* buffer */ 5784 5785 /* draw */ 5786 5787 /* buffering */ 5788 5789 /* text editor */ 5790 5791 /* window */ 5792 5793 /* inserts window into the back of list (front of screen) */ 5794 /* inserts window into the front of list (back of screen) */ 5795 5796 /* pool */ 5797 5798 /* page-element */ 5799 5800 /* table */ 5801 5802 /* panel */ 5803 5804 /* layout */ 5805 5806 /* popup */ 5807 5808 /* text */ 5809 5810 /* button */ 5811 5812 /* toggle */ 5813 5814 /* progress */ 5815 5816 /* slider */ 5817 5818 /* scrollbar */ 5819 5820 /* selectable */ 5821 5822 /* edit */ 5823 5824 /* color-picker */ 5825 5826 /* property */ 5827 5828 /* Allow consumer to define own STBTT_malloc/STBTT_free, and use the font atlas' allocator otherwise */ 5829 5830 /* STBTT_malloc */ 5831 5832 /* NK_INCLUDE_FONT_BAKING */ 5833 5834 /* =============================================================== 5835 * 5836 * MATH 5837 * 5838 * ===============================================================*/ 5839 /* Since nuklear is supposed to work on all systems providing floating point 5840 math without any dependencies I also had to implement my own math functions 5841 for sqrt, sin and cos. Since the actual highly accurate implementations for 5842 the standard library functions are quite complex and I do not need high 5843 precision for my use cases I use approximations. 5844 5845 Sqrt 5846 ---- 5847 For square root nuklear uses the famous fast inverse square root: 5848 https://en.wikipedia.org/wiki/Fast_inverse_square_root with 5849 slightly tweaked magic constant. While on today's hardware it is 5850 probably not faster it is still fast and accurate enough for 5851 nuklear's use cases. IMPORTANT: this requires float format IEEE 754 5852 5853 Sine/Cosine 5854 ----------- 5855 All constants inside both function are generated Remez's minimax 5856 approximations for value range 0...2*PI. The reason why I decided to 5857 approximate exactly that range is that nuklear only needs sine and 5858 cosine to generate circles which only requires that exact range. 5859 In addition I used Remez instead of Taylor for additional precision: 5860 www.lolengine.net/blog/2011/12/21/better-function-approximations. 5861 5862 The tool I used to generate constants for both sine and cosine 5863 (it can actually approximate a lot more functions) can be 5864 found here: www.lolengine.net/wiki/oss/lolremez 5865 */ 5866 5867 /* New implementation. Also generated using lolremez. */ 5868 /* Old version significantly deviated from expected results. */ 5869 5870 /* check the sign of n */ 5871 5872 /* =============================================================== 5873 * 5874 * UTIL 5875 * 5876 * ===============================================================*/ 5877 5878 /* only need low bits */ 5879 5880 /* at least 16-bits */ 5881 5882 /* at least 32-bits*/ 5883 5884 /* too small of a word count */ 5885 5886 /* align destination */ 5887 5888 /* fill word */ 5889 5890 /* fill trailing bytes */ 5891 5892 /* skip whitespace */ 5893 5894 /* skip whitespace */ 5895 5896 /* a '* matches zero or more instances */ 5897 5898 /* 5899 c matches any literal character c 5900 . matches any single character 5901 ^ matches the beginning of the input string 5902 $ matches the end of the input string 5903 * matches zero or more occurrences of the previous character*/ 5904 5905 /* must look even if string is empty */ 5906 5907 /* Returns true if each character in pattern is found sequentially within str 5908 * if found then out_score is also set. Score value has no intrinsic meaning. 5909 * Range varies with pattern. Can only compare scores with same search pattern. */ 5910 5911 /* bonus for adjacent matches */ 5912 5913 /* bonus if match occurs after a separator */ 5914 5915 /* bonus if match is uppercase and prev is lower */ 5916 5917 /* penalty applied for every letter in str before the first match */ 5918 5919 /* maximum penalty for leading letters */ 5920 5921 /* penalty for every letter that doesn't matter */ 5922 5923 /* loop variables */ 5924 5925 /* true so if first letter match gets separator bonus*/ 5926 5927 /* use "best" matched letter if multiple string letters match the pattern */ 5928 5929 /* loop over strings */ 5930 5931 /* Apply penalty for each letter before the first pattern match */ 5932 5933 /* apply bonus for consecutive bonuses */ 5934 5935 /* apply bonus for matches after a separator */ 5936 5937 /* apply bonus across camel case boundaries */ 5938 5939 /* update pattern iter IFF the next pattern letter was matched */ 5940 5941 /* update best letter in str which may be for a "next" letter or a rematch */ 5942 5943 /* apply penalty for now skipped letter */ 5944 5945 /* separators should be more easily defined */ 5946 5947 /* apply score for last match */ 5948 5949 /* did not match full pattern */ 5950 5951 /* calculate magnitude */ 5952 5953 /* set up for scientific notation */ 5954 5955 /* convert the number */ 5956 5957 /* convert the exponent */ 5958 5959 /* swap without temporary */ 5960 5961 /* copy all non-format characters */ 5962 5963 /* flag arguments */ 5964 5965 /* width argument */ 5966 5967 /* precision argument */ 5968 5969 /* length modifier */ 5970 5971 /* specifier */ 5972 5973 /* string */ 5974 5975 /* current length callback */ 5976 5977 /* signed integer */ 5978 5979 /* retrieve correct value type */ 5980 5981 /* convert number to string */ 5982 5983 /* fill left padding up to a total of `width` characters */ 5984 5985 /* copy string value representation into buffer */ 5986 5987 /* fill up to precision number of digits with '0' */ 5988 5989 /* copy string value representation into buffer */ 5990 5991 /* fill right padding up to width characters */ 5992 5993 /* unsigned integer */ 5994 5995 /* print oct/hex/dec value */ 5996 5997 /* retrieve correct value type */ 5998 5999 /* convert decimal number into hex/oct number */ 6000 6001 /* fill left padding up to a total of `width` characters */ 6002 6003 /* fill up to precision number of digits */ 6004 6005 /* reverse number direction */ 6006 6007 /* fill right padding up to width characters */ 6008 6009 /* floating point */ 6010 6011 /* calculate padding */ 6012 6013 /* fill left padding up to a total of `width` characters */ 6014 6015 /* copy string value representation into buffer */ 6016 6017 /* fill number up to precision */ 6018 6019 /* fill right padding up to width characters */ 6020 6021 /* Specifier not supported: g,G,e,E,p,z */ 6022 6023 /* 32-Bit MurmurHash3: https://code.google.com/p/smhasher/wiki/MurmurHash3*/ 6024 6025 /* body */ 6026 6027 /* tail */ 6028 6029 /* fallthrough */ 6030 /* fallthrough */ 6031 6032 /* finalization */ 6033 6034 /* fmix32 */ 6035 6036 /* ============================================================== 6037 * 6038 * COLOR 6039 * 6040 * ===============================================================*/ 6041 6042 /* =============================================================== 6043 * 6044 * UTF-8 6045 * 6046 * ===============================================================*/ 6047 6048 /* ============================================================== 6049 * 6050 * BUFFER 6051 * 6052 * ===============================================================*/ 6053 6054 /* no back buffer so just set correct size */ 6055 6056 /* copy back buffer to the end of the new buffer */ 6057 6058 /* calculate total size with needed alignment + size */ 6059 6060 /* check if buffer has enough memory*/ 6061 6062 /* buffer is full so allocate bigger buffer if dynamic */ 6063 6064 /* align newly allocated pointer */ 6065 6066 /* reset back buffer either back to marker or empty */ 6067 6068 /* reset front buffer either back to back marker or empty */ 6069 6070 /* =============================================================== 6071 * 6072 * STRING 6073 * 6074 * ===============================================================*/ 6075 6076 /* memmove */ 6077 6078 /* memmove */ 6079 6080 /* ============================================================== 6081 * 6082 * DRAW 6083 * 6084 * ===============================================================*/ 6085 6086 /* make sure the offset to the next command is aligned */ 6087 6088 /* top-left */ 6089 6090 /* top-center */ 6091 6092 /* top-right */ 6093 6094 /* center-left */ 6095 6096 /* center */ 6097 6098 /* center-right */ 6099 6100 /* bottom-left */ 6101 6102 /* bottom-center */ 6103 6104 /* bottom-right */ 6105 6106 /* make sure text fits inside bounds */ 6107 6108 /* =============================================================== 6109 * 6110 * VERTEX 6111 * 6112 * ===============================================================*/ 6113 6114 /* This assert triggers because your are drawing a lot of stuff and nuklear 6115 * defined `nk_draw_index` as `nk_ushort` to safe space be default. 6116 * 6117 * So you reached the maximum number of indices or rather vertexes. 6118 * To solve this issue please change typedef `nk_draw_index` to `nk_uint` 6119 * and don't forget to specify the new element size in your drawing 6120 * backend (OpenGL, DirectX, ...). For example in OpenGL for `glDrawElements` 6121 * instead of specifying `GL_UNSIGNED_SHORT` you have to define `GL_UNSIGNED_INT`. 6122 * Sorry for the inconvenience. */ 6123 6124 /* if this triggers you tried to provide a value format for a color */ 6125 6126 /* if this triggers you tried to provide a color format for a value */ 6127 6128 /* ANTI-ALIASED STROKE */ 6129 6130 /* allocate vertices and elements */ 6131 6132 /* temporary allocate normals + points */ 6133 6134 /* make sure vertex pointer is still correct */ 6135 6136 /* calculate normals */ 6137 6138 /* vec2 inverted length */ 6139 6140 /* fill elements */ 6141 6142 /* average normals */ 6143 6144 /* fill vertices */ 6145 6146 /* add all elements */ 6147 6148 /* average normals */ 6149 6150 /* add indexes */ 6151 6152 /* add vertices */ 6153 6154 /* free temporary normals + points */ 6155 6156 /* NON ANTI-ALIASED STROKE */ 6157 6158 /* vec2 inverted length */ 6159 6160 /* add vertices */ 6161 6162 /* temporary allocate normals */ 6163 6164 /* add elements */ 6165 6166 /* compute normals */ 6167 6168 /* vec2 inverted length */ 6169 6170 /* add vertices + indexes */ 6171 6172 /* add vertices */ 6173 6174 /* add indexes */ 6175 6176 /* free temporary normals + points */ 6177 6178 /* This algorithm for arc drawing relies on these two trigonometric identities[1]: 6179 sin(a + b) = sin(a) * cos(b) + cos(a) * sin(b) 6180 cos(a + b) = cos(a) * cos(b) - sin(a) * sin(b) 6181 6182 Two coordinates (x, y) of a point on a circle centered on 6183 the origin can be written in polar form as: 6184 x = r * cos(a) 6185 y = r * sin(a) 6186 where r is the radius of the circle, 6187 a is the angle between (x, y) and the origin. 6188 6189 This allows us to rotate the coordinates around the 6190 origin by an angle b using the following transformation: 6191 x' = r * cos(a + b) = x * cos(b) - y * sin(b) 6192 y' = r * sin(a + b) = y * cos(b) + x * sin(b) 6193 6194 [1] https://en.wikipedia.org/wiki/List_of_trigonometric_identities#Angle_sum_and_difference_identities 6195 */ 6196 6197 /* push new command with given texture */ 6198 6199 /* add region inside of the texture */ 6200 6201 /* draw every glyph image */ 6202 6203 /* query currently drawn glyph information */ 6204 6205 /* calculate and draw glyph drawing rectangle and image */ 6206 6207 /* offset next glyph */ 6208 6209 /* stb_rect_pack.h - v1.01 - public domain - rectangle packing */ 6210 /* Sean Barrett 2014 */ 6211 /* */ 6212 /* Useful for e.g. packing rectangular textures into an atlas. */ 6213 /* Does not do rotation. */ 6214 /* */ 6215 /* Before #including, */ 6216 /* */ 6217 /* #define STB_RECT_PACK_IMPLEMENTATION */ 6218 /* */ 6219 /* in the file that you want to have the implementation. */ 6220 /* */ 6221 /* Not necessarily the awesomest packing method, but better than */ 6222 /* the totally naive one in stb_truetype (which is primarily what */ 6223 /* this is meant to replace). */ 6224 /* */ 6225 /* Has only had a few tests run, may have issues. */ 6226 /* */ 6227 /* More docs to come. */ 6228 /* */ 6229 /* No memory allocations; uses qsort() and assert() from stdlib. */ 6230 /* Can override those by defining STBRP_SORT and STBRP_ASSERT. */ 6231 /* */ 6232 /* This library currently uses the Skyline Bottom-Left algorithm. */ 6233 /* */ 6234 /* Please note: better rectangle packers are welcome! Please */ 6235 /* implement them to the same API, but with a different init */ 6236 /* function. */ 6237 /* */ 6238 /* Credits */ 6239 /* */ 6240 /* Library */ 6241 /* Sean Barrett */ 6242 /* Minor features */ 6243 /* Martins Mozeiko */ 6244 /* github:IntellectualKitty */ 6245 /* */ 6246 /* Bugfixes / warning fixes */ 6247 /* Jeremy Jaussaud */ 6248 /* Fabian Giesen */ 6249 /* */ 6250 /* Version history: */ 6251 /* */ 6252 /* 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section */ 6253 /* 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles */ 6254 /* 0.99 (2019-02-07) warning fixes */ 6255 /* 0.11 (2017-03-03) return packing success/fail result */ 6256 /* 0.10 (2016-10-25) remove cast-away-const to avoid warnings */ 6257 /* 0.09 (2016-08-27) fix compiler warnings */ 6258 /* 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0) */ 6259 /* 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0) */ 6260 /* 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort */ 6261 /* 0.05: added STBRP_ASSERT to allow replacing assert */ 6262 /* 0.04: fixed minor bug in STBRP_LARGE_RECTS support */ 6263 /* 0.01: initial release */ 6264 /* */ 6265 /* LICENSE */ 6266 /* */ 6267 /* See end of file for license information. */ 6268 6269 /* //////////////////////////////////////////////////////////////////////////// */ 6270 /* */ 6271 /* INCLUDE SECTION */ 6272 /* */ 6273 6274 /* Mostly for internal use, but this is the maximum supported coordinate value. */ 6275 6276 /* Assign packed locations to rectangles. The rectangles are of type */ 6277 /* 'stbrp_rect' defined below, stored in the array 'rects', and there */ 6278 /* are 'num_rects' many of them. */ 6279 /* */ 6280 /* Rectangles which are successfully packed have the 'was_packed' flag */ 6281 /* set to a non-zero value and 'x' and 'y' store the minimum location */ 6282 /* on each axis (i.e. bottom-left in cartesian coordinates, top-left */ 6283 /* if you imagine y increasing downwards). Rectangles which do not fit */ 6284 /* have the 'was_packed' flag set to 0. */ 6285 /* */ 6286 /* You should not try to access the 'rects' array from another thread */ 6287 /* while this function is running, as the function temporarily reorders */ 6288 /* the array while it executes. */ 6289 /* */ 6290 /* To pack into another rectangle, you need to call stbrp_init_target */ 6291 /* again. To continue packing into the same rectangle, you can call */ 6292 /* this function again. Calling this multiple times with multiple rect */ 6293 /* arrays will probably produce worse packing results than calling it */ 6294 /* a single time with the full rectangle array, but the option is */ 6295 /* available. */ 6296 /* */ 6297 /* The function returns 1 if all of the rectangles were successfully */ 6298 /* packed and 0 otherwise. */ 6299 6300 /* reserved for your use: */ 6301 6302 /* input: */ 6303 6304 /* output: */ 6305 6306 /* non-zero if valid packing */ 6307 6308 /* 16 bytes, nominally */ 6309 6310 /* Initialize a rectangle packer to: */ 6311 /* pack a rectangle that is 'width' by 'height' in dimensions */ 6312 /* using temporary storage provided by the array 'nodes', which is 'num_nodes' long */ 6313 /* */ 6314 /* You must call this function every time you start packing into a new target. */ 6315 /* */ 6316 /* There is no "shutdown" function. The 'nodes' memory must stay valid for */ 6317 /* the following stbrp_pack_rects() call (or calls), but can be freed after */ 6318 /* the call (or calls) finish. */ 6319 /* */ 6320 /* Note: to guarantee best results, either: */ 6321 /* 1. make sure 'num_nodes' >= 'width' */ 6322 /* or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1' */ 6323 /* */ 6324 /* If you don't do either of the above things, widths will be quantized to multiples */ 6325 /* of small integers to guarantee the algorithm doesn't run out of temporary storage. */ 6326 /* */ 6327 /* If you do #2, then the non-quantized algorithm will be used, but the algorithm */ 6328 /* may run out of temporary storage and be unable to pack some rectangles. */ 6329 6330 /* Optionally call this function after init but before doing any packing to */ 6331 /* change the handling of the out-of-temp-memory scenario, described above. */ 6332 /* If you call init again, this will be reset to the default (false). */ 6333 6334 /* Optionally select which packing heuristic the library should use. Different */ 6335 /* heuristics will produce better/worse results for different data sets. */ 6336 /* If you call init again, this will be reset to the default. */ 6337 6338 /* //////////////////////////////////////////////////////////////////////////// */ 6339 /* */ 6340 /* the details of the following structures don't matter to you, but they must */ 6341 /* be visible so you can handle the memory allocations for them */ 6342 6343 /* we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2' */ 6344 6345 /* //////////////////////////////////////////////////////////////////////////// */ 6346 /* */ 6347 /* IMPLEMENTATION SECTION */ 6348 /* */ 6349 6350 /* if it's ok to run out of memory, then don't bother aligning them; */ 6351 /* this gives better packing, but may fail due to OOM (even though */ 6352 /* the rectangles easily fit). @TODO a smarter approach would be to only */ 6353 /* quantize once we've hit OOM, then we could get rid of this parameter. */ 6354 6355 /* if it's not ok to run out of memory, then quantize the widths */ 6356 /* so that num_nodes is always enough nodes. */ 6357 /* */ 6358 /* I.e. num_nodes * align >= width */ 6359 /* align >= width / num_nodes */ 6360 /* align = ceil(width/num_nodes) */ 6361 6362 /* node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly) */ 6363 6364 /* find minimum y position if it starts at x1 */ 6365 6366 /* skip in case we're past the node */ 6367 6368 /* we ended up handling this in the caller for efficiency */ 6369 6370 /* raise min_y higher. */ 6371 /* we've accounted for all waste up to min_y, */ 6372 /* but we'll now add more waste for everything we've visted */ 6373 6374 /* the first time through, visited_width might be reduced */ 6375 6376 /* add waste area */ 6377 6378 /* align to multiple of c->align */ 6379 6380 /* if it can't possibly fit, bail immediately */ 6381 6382 /* actually just want to test BL */ 6383 /* bottom left */ 6384 6385 /* best-fit */ 6386 6387 /* can only use it if it first vertically */ 6388 6389 /* if doing best-fit (BF), we also have to try aligning right edge to each node position */ 6390 /* */ 6391 /* e.g, if fitting */ 6392 /* */ 6393 /* ____________________ */ 6394 /* |____________________| */ 6395 /* */ 6396 /* into */ 6397 /* */ 6398 /* | | */ 6399 /* | ____________| */ 6400 /* |____________| */ 6401 /* */ 6402 /* then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned */ 6403 /* */ 6404 /* This makes BF take about 2x the time */ 6405 6406 /* find first node that's admissible */ 6407 6408 /* find the left position that matches this */ 6409 6410 /* find best position according to heuristic */ 6411 6412 /* bail if: */ 6413 /* 1. it failed */ 6414 /* 2. the best node doesn't fit (we don't always check this) */ 6415 /* 3. we're out of memory */ 6416 6417 /* on success, create new node */ 6418 6419 /* insert the new node into the right starting point, and */ 6420 /* let 'cur' point to the remaining nodes needing to be */ 6421 /* stiched back in */ 6422 6423 /* preserve the existing one, so start testing with the next one */ 6424 6425 /* from here, traverse cur and free the nodes, until we get to one */ 6426 /* that shouldn't be freed */ 6427 6428 /* move the current node to the free list */ 6429 6430 /* stitch the list back in */ 6431 6432 /* we use the 'was_packed' field internally to allow sorting/unsorting */ 6433 6434 /* sort according to heuristic */ 6435 6436 /* empty rect needs no space */ 6437 6438 /* unsort */ 6439 6440 /* set was_packed flags and all_rects_packed status */ 6441 6442 /* return the all_rects_packed status */ 6443 6444 /* 6445 ------------------------------------------------------------------------------ 6446 This software is available under 2 licenses -- choose whichever you prefer. 6447 ------------------------------------------------------------------------------ 6448 ALTERNATIVE A - MIT License 6449 Copyright (c) 2017 Sean Barrett 6450 Permission is hereby granted, free of charge, to any person obtaining a copy of 6451 this software and associated documentation files (the "Software"), to deal in 6452 the Software without restriction, including without limitation the rights to 6453 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 6454 of the Software, and to permit persons to whom the Software is furnished to do 6455 so, subject to the following conditions: 6456 The above copyright notice and this permission notice shall be included in all 6457 copies or substantial portions of the Software. 6458 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6459 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 6460 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 6461 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 6462 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 6463 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 6464 SOFTWARE. 6465 ------------------------------------------------------------------------------ 6466 ALTERNATIVE B - Public Domain (www.unlicense.org) 6467 This is free and unencumbered software released into the public domain. 6468 Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 6469 software, either in source code form or as a compiled binary, for any purpose, 6470 commercial or non-commercial, and by any means. 6471 In jurisdictions that recognize copyright laws, the author or authors of this 6472 software dedicate any and all copyright interest in the software to the public 6473 domain. We make this dedication for the benefit of the public at large and to 6474 the detriment of our heirs and successors. We intend this dedication to be an 6475 overt act of relinquishment in perpetuity of all present and future rights to 6476 this software under copyright law. 6477 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 6478 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 6479 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 6480 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 6481 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 6482 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 6483 ------------------------------------------------------------------------------ 6484 */ 6485 6486 /* stb_truetype.h - v1.26 - public domain */ 6487 /* authored from 2009-2021 by Sean Barrett / RAD Game Tools */ 6488 /* */ 6489 /* ======================================================================= */ 6490 /* */ 6491 /* NO SECURITY GUARANTEE -- DO NOT USE THIS ON UNTRUSTED FONT FILES */ 6492 /* */ 6493 /* This library does no range checking of the offsets found in the file, */ 6494 /* meaning an attacker can use it to read arbitrary memory. */ 6495 /* */ 6496 /* ======================================================================= */ 6497 /* */ 6498 /* This library processes TrueType files: */ 6499 /* parse files */ 6500 /* extract glyph metrics */ 6501 /* extract glyph shapes */ 6502 /* render glyphs to one-channel bitmaps with antialiasing (box filter) */ 6503 /* render glyphs to one-channel SDF bitmaps (signed-distance field/function) */ 6504 /* */ 6505 /* Todo: */ 6506 /* non-MS cmaps */ 6507 /* crashproof on bad data */ 6508 /* hinting? (no longer patented) */ 6509 /* cleartype-style AA? */ 6510 /* optimize: use simple memory allocator for intermediates */ 6511 /* optimize: build edge-list directly from curves */ 6512 /* optimize: rasterize directly from curves? */ 6513 /* */ 6514 /* ADDITIONAL CONTRIBUTORS */ 6515 /* */ 6516 /* Mikko Mononen: compound shape support, more cmap formats */ 6517 /* Tor Andersson: kerning, subpixel rendering */ 6518 /* Dougall Johnson: OpenType / Type 2 font handling */ 6519 /* Daniel Ribeiro Maciel: basic GPOS-based kerning */ 6520 /* */ 6521 /* Misc other: */ 6522 /* Ryan Gordon */ 6523 /* Simon Glass */ 6524 /* github:IntellectualKitty */ 6525 /* Imanol Celaya */ 6526 /* Daniel Ribeiro Maciel */ 6527 /* */ 6528 /* Bug/warning reports/fixes: */ 6529 /* "Zer" on mollyrocket Fabian "ryg" Giesen github:NiLuJe */ 6530 /* Cass Everitt Martins Mozeiko github:aloucks */ 6531 /* stoiko (Haemimont Games) Cap Petschulat github:oyvindjam */ 6532 /* Brian Hook Omar Cornut github:vassvik */ 6533 /* Walter van Niftrik Ryan Griege */ 6534 /* David Gow Peter LaValle */ 6535 /* David Given Sergey Popov */ 6536 /* Ivan-Assen Ivanov Giumo X. Clanjor */ 6537 /* Anthony Pesch Higor Euripedes */ 6538 /* Johan Duparc Thomas Fields */ 6539 /* Hou Qiming Derek Vinyard */ 6540 /* Rob Loach Cort Stratton */ 6541 /* Kenney Phillis Jr. Brian Costabile */ 6542 /* Ken Voskuil (kaesve) */ 6543 /* */ 6544 /* VERSION HISTORY */ 6545 /* */ 6546 /* 1.26 (2021-08-28) fix broken rasterizer */ 6547 /* 1.25 (2021-07-11) many fixes */ 6548 /* 1.24 (2020-02-05) fix warning */ 6549 /* 1.23 (2020-02-02) query SVG data for glyphs; query whole kerning table (but only kern not GPOS) */ 6550 /* 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined */ 6551 /* 1.21 (2019-02-25) fix warning */ 6552 /* 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics() */ 6553 /* 1.19 (2018-02-11) GPOS kerning, STBTT_fmod */ 6554 /* 1.18 (2018-01-29) add missing function */ 6555 /* 1.17 (2017-07-23) make more arguments const; doc fix */ 6556 /* 1.16 (2017-07-12) SDF support */ 6557 /* 1.15 (2017-03-03) make more arguments const */ 6558 /* 1.14 (2017-01-16) num-fonts-in-TTC function */ 6559 /* 1.13 (2017-01-02) support OpenType fonts, certain Apple fonts */ 6560 /* 1.12 (2016-10-25) suppress warnings about casting away const with -Wcast-qual */ 6561 /* 1.11 (2016-04-02) fix unused-variable warning */ 6562 /* 1.10 (2016-04-02) user-defined fabs(); rare memory leak; remove duplicate typedef */ 6563 /* 1.09 (2016-01-16) warning fix; avoid crash on outofmem; use allocation userdata properly */ 6564 /* 1.08 (2015-09-13) document stbtt_Rasterize(); fixes for vertical & horizontal edges */ 6565 /* 1.07 (2015-08-01) allow PackFontRanges to accept arrays of sparse codepoints; */ 6566 /* variant PackFontRanges to pack and render in separate phases; */ 6567 /* fix stbtt_GetFontOFfsetForIndex (never worked for non-0 input?); */ 6568 /* fixed an assert() bug in the new rasterizer */ 6569 /* replace assert() with STBTT_assert() in new rasterizer */ 6570 /* */ 6571 /* Full history can be found at the end of this file. */ 6572 /* */ 6573 /* LICENSE */ 6574 /* */ 6575 /* See end of file for license information. */ 6576 /* */ 6577 /* USAGE */ 6578 /* */ 6579 /* Include this file in whatever places need to refer to it. In ONE C/C++ */ 6580 /* file, write: */ 6581 /* #define STB_TRUETYPE_IMPLEMENTATION */ 6582 /* before the #include of this file. This expands out the actual */ 6583 /* implementation into that C/C++ file. */ 6584 /* */ 6585 /* To make the implementation private to the file that generates the implementation, */ 6586 /* #define STBTT_STATIC */ 6587 /* */ 6588 /* Simple 3D API (don't ship this, but it's fine for tools and quick start) */ 6589 /* stbtt_BakeFontBitmap() -- bake a font to a bitmap for use as texture */ 6590 /* stbtt_GetBakedQuad() -- compute quad to draw for a given char */ 6591 /* */ 6592 /* Improved 3D API (more shippable): */ 6593 /* #include "stb_rect_pack.h" -- optional, but you really want it */ 6594 /* stbtt_PackBegin() */ 6595 /* stbtt_PackSetOversampling() -- for improved quality on small fonts */ 6596 /* stbtt_PackFontRanges() -- pack and renders */ 6597 /* stbtt_PackEnd() */ 6598 /* stbtt_GetPackedQuad() */ 6599 /* */ 6600 /* "Load" a font file from a memory buffer (you have to keep the buffer loaded) */ 6601 /* stbtt_InitFont() */ 6602 /* stbtt_GetFontOffsetForIndex() -- indexing for TTC font collections */ 6603 /* stbtt_GetNumberOfFonts() -- number of fonts for TTC font collections */ 6604 /* */ 6605 /* Render a unicode codepoint to a bitmap */ 6606 /* stbtt_GetCodepointBitmap() -- allocates and returns a bitmap */ 6607 /* stbtt_MakeCodepointBitmap() -- renders into bitmap you provide */ 6608 /* stbtt_GetCodepointBitmapBox() -- how big the bitmap must be */ 6609 /* */ 6610 /* Character advance/positioning */ 6611 /* stbtt_GetCodepointHMetrics() */ 6612 /* stbtt_GetFontVMetrics() */ 6613 /* stbtt_GetFontVMetricsOS2() */ 6614 /* stbtt_GetCodepointKernAdvance() */ 6615 /* */ 6616 /* Starting with version 1.06, the rasterizer was replaced with a new, */ 6617 /* faster and generally-more-precise rasterizer. The new rasterizer more */ 6618 /* accurately measures pixel coverage for anti-aliasing, except in the case */ 6619 /* where multiple shapes overlap, in which case it overestimates the AA pixel */ 6620 /* coverage. Thus, anti-aliasing of intersecting shapes may look wrong. If */ 6621 /* this turns out to be a problem, you can re-enable the old rasterizer with */ 6622 /* #define STBTT_RASTERIZER_VERSION 1 */ 6623 /* which will incur about a 15% speed hit. */ 6624 /* */ 6625 /* ADDITIONAL DOCUMENTATION */ 6626 /* */ 6627 /* Immediately after this block comment are a series of sample programs. */ 6628 /* */ 6629 /* After the sample programs is the "header file" section. This section */ 6630 /* includes documentation for each API function. */ 6631 /* */ 6632 /* Some important concepts to understand to use this library: */ 6633 /* */ 6634 /* Codepoint */ 6635 /* Characters are defined by unicode codepoints, e.g. 65 is */ 6636 /* uppercase A, 231 is lowercase c with a cedilla, 0x7e30 is */ 6637 /* the hiragana for "ma". */ 6638 /* */ 6639 /* Glyph */ 6640 /* A visual character shape (every codepoint is rendered as */ 6641 /* some glyph) */ 6642 /* */ 6643 /* Glyph index */ 6644 /* A font-specific integer ID representing a glyph */ 6645 /* */ 6646 /* Baseline */ 6647 /* Glyph shapes are defined relative to a baseline, which is the */ 6648 /* bottom of uppercase characters. Characters extend both above */ 6649 /* and below the baseline. */ 6650 /* */ 6651 /* Current Point */ 6652 /* As you draw text to the screen, you keep track of a "current point" */ 6653 /* which is the origin of each character. The current point's vertical */ 6654 /* position is the baseline. Even "baked fonts" use this model. */ 6655 /* */ 6656 /* Vertical Font Metrics */ 6657 /* The vertical qualities of the font, used to vertically position */ 6658 /* and space the characters. See docs for stbtt_GetFontVMetrics. */ 6659 /* */ 6660 /* Font Size in Pixels or Points */ 6661 /* The preferred interface for specifying font sizes in stb_truetype */ 6662 /* is to specify how tall the font's vertical extent should be in pixels. */ 6663 /* If that sounds good enough, skip the next paragraph. */ 6664 /* */ 6665 /* Most font APIs instead use "points", which are a common typographic */ 6666 /* measurement for describing font size, defined as 72 points per inch. */ 6667 /* stb_truetype provides a point API for compatibility. However, true */ 6668 /* "per inch" conventions don't make much sense on computer displays */ 6669 /* since different monitors have different number of pixels per */ 6670 /* inch. For example, Windows traditionally uses a convention that */ 6671 /* there are 96 pixels per inch, thus making 'inch' measurements have */ 6672 /* nothing to do with inches, and thus effectively defining a point to */ 6673 /* be 1.333 pixels. Additionally, the TrueType font data provides */ 6674 /* an explicit scale factor to scale a given font's glyphs to points, */ 6675 /* but the author has observed that this scale factor is often wrong */ 6676 /* for non-commercial fonts, thus making fonts scaled in points */ 6677 /* according to the TrueType spec incoherently sized in practice. */ 6678 /* */ 6679 /* DETAILED USAGE: */ 6680 /* */ 6681 /* Scale: */ 6682 /* Select how high you want the font to be, in points or pixels. */ 6683 /* Call ScaleForPixelHeight or ScaleForMappingEmToPixels to compute */ 6684 /* a scale factor SF that will be used by all other functions. */ 6685 /* */ 6686 /* Baseline: */ 6687 /* You need to select a y-coordinate that is the baseline of where */ 6688 /* your text will appear. Call GetFontBoundingBox to get the baseline-relative */ 6689 /* bounding box for all characters. SF*-y0 will be the distance in pixels */ 6690 /* that the worst-case character could extend above the baseline, so if */ 6691 /* you want the top edge of characters to appear at the top of the */ 6692 /* screen where y=0, then you would set the baseline to SF*-y0. */ 6693 /* */ 6694 /* Current point: */ 6695 /* Set the current point where the first character will appear. The */ 6696 /* first character could extend left of the current point; this is font */ 6697 /* dependent. You can either choose a current point that is the leftmost */ 6698 /* point and hope, or add some padding, or check the bounding box or */ 6699 /* left-side-bearing of the first character to be displayed and set */ 6700 /* the current point based on that. */ 6701 /* */ 6702 /* Displaying a character: */ 6703 /* Compute the bounding box of the character. It will contain signed values */ 6704 /* relative to <current_point, baseline>. I.e. if it returns x0,y0,x1,y1, */ 6705 /* then the character should be displayed in the rectangle from */ 6706 /* <current_point+SF*x0, baseline+SF*y0> to <current_point+SF*x1,baseline+SF*y1). */ 6707 /* */ 6708 /* Advancing for the next character: */ 6709 /* Call GlyphHMetrics, and compute 'current_point += SF * advance'. */ 6710 /* */ 6711 /* */ 6712 /* ADVANCED USAGE */ 6713 /* */ 6714 /* Quality: */ 6715 /* */ 6716 /* - Use the functions with Subpixel at the end to allow your characters */ 6717 /* to have subpixel positioning. Since the font is anti-aliased, not */ 6718 /* hinted, this is very import for quality. (This is not possible with */ 6719 /* baked fonts.) */ 6720 /* */ 6721 /* - Kerning is now supported, and if you're supporting subpixel rendering */ 6722 /* then kerning is worth using to give your text a polished look. */ 6723 /* */ 6724 /* Performance: */ 6725 /* */ 6726 /* - Convert Unicode codepoints to glyph indexes and operate on the glyphs; */ 6727 /* if you don't do this, stb_truetype is forced to do the conversion on */ 6728 /* every call. */ 6729 /* */ 6730 /* - There are a lot of memory allocations. We should modify it to take */ 6731 /* a temp buffer and allocate from the temp buffer (without freeing), */ 6732 /* should help performance a lot. */ 6733 /* */ 6734 /* NOTES */ 6735 /* */ 6736 /* The system uses the raw data found in the .ttf file without changing it */ 6737 /* and without building auxiliary data structures. This is a bit inefficient */ 6738 /* on little-endian systems (the data is big-endian), but assuming you're */ 6739 /* caching the bitmaps or glyph shapes this shouldn't be a big deal. */ 6740 /* */ 6741 /* It appears to be very hard to programmatically determine what font a */ 6742 /* given file is in a general way. I provide an API for this, but I don't */ 6743 /* recommend it. */ 6744 /* */ 6745 /* */ 6746 /* PERFORMANCE MEASUREMENTS FOR 1.06: */ 6747 /* */ 6748 /* 32-bit 64-bit */ 6749 /* Previous release: 8.83 s 7.68 s */ 6750 /* Pool allocations: 7.72 s 6.34 s */ 6751 /* Inline sort : 6.54 s 5.65 s */ 6752 /* New rasterizer : 5.63 s 5.00 s */ 6753 6754 /* //////////////////////////////////////////////////////////////////////////// */ 6755 /* //////////////////////////////////////////////////////////////////////////// */ 6756 /* // */ 6757 /* // SAMPLE PROGRAMS */ 6758 /* // */ 6759 /* */ 6760 /* Incomplete text-in-3d-api example, which draws quads properly aligned to be lossless. */ 6761 /* See "tests/truetype_demo_win32.c" for a complete version. */ 6762 6763 /* force following include to generate implementation */ 6764 6765 /* ASCII 32..126 is 95 glyphs */ 6766 6767 /* no guarantee this fits! */ 6768 /* can free ttf_buffer at this point */ 6769 6770 /* can free temp_bitmap at this point */ 6771 6772 /* assume orthographic projection with units = screen pixels, origin at top left */ 6773 6774 /* 1=opengl & d3d10+,0=d3d9 */ 6775 6776 /* */ 6777 /* */ 6778 /* //////////////////////////////////////////////////////////////////////////// */ 6779 /* */ 6780 /* Complete program (this compiles): get a single bitmap, print as ASCII art */ 6781 /* */ 6782 6783 /* force following include to generate implementation */ 6784 6785 /* */ 6786 /* Output: */ 6787 /* */ 6788 /* .ii. */ 6789 /* @@@@@@. */ 6790 /* V@Mio@@o */ 6791 /* :i. V@V */ 6792 /* :oM@@M */ 6793 /* :@@@MM@M */ 6794 /* @@o o@M */ 6795 /* :@@. M@M */ 6796 /* @@@o@@@@ */ 6797 /* :M@@V:@@. */ 6798 /* */ 6799 /* //////////////////////////////////////////////////////////////////////////// */ 6800 /* */ 6801 /* Complete program: print "Hello World!" banner, with bugs */ 6802 /* */ 6803 6804 /* leave a little padding in case the character extends left */ 6805 /* intentionally misspelled to show 'lj' brokenness */ 6806 6807 /* note that this stomps the old data, so where character boxes overlap (e.g. 'lj') it's wrong */ 6808 /* because this API is really for baking character bitmaps into textures. if you want to render */ 6809 /* a sequence of characters, you really need to render each bitmap to a temp buffer, then */ 6810 /* "alpha blend" that into the working buffer */ 6811 6812 /* //////////////////////////////////////////////////////////////////////////// */ 6813 /* //////////////////////////////////////////////////////////////////////////// */ 6814 /* // */ 6815 /* // INTEGRATION WITH YOUR CODEBASE */ 6816 /* // */ 6817 /* // The following sections allow you to supply alternate definitions */ 6818 /* // of C library functions used by stb_truetype, e.g. if you don't */ 6819 /* // link with the C runtime library. */ 6820 6821 /* #define your own (u)stbtt_int8/16/32 before including to override this */ 6822 6823 /* e.g. #define your own STBTT_ifloor/STBTT_iceil() to avoid math.h */ 6824 6825 /* #define your own functions "STBTT_malloc" / "STBTT_free" to avoid malloc.h */ 6826 6827 /* ///////////////////////////////////////////////////////////////////////////// */ 6828 /* ///////////////////////////////////////////////////////////////////////////// */ 6829 /* // */ 6830 /* // INTERFACE */ 6831 /* // */ 6832 /* // */ 6833 6834 /* private structure */ 6835 6836 /* //////////////////////////////////////////////////////////////////////////// */ 6837 /* */ 6838 /* TEXTURE BAKING API */ 6839 /* */ 6840 /* If you use this API, you only have to call two functions ever. */ 6841 /* */ 6842 6843 /* coordinates of bbox in bitmap */ 6844 6845 /* font location (use offset=0 for plain .ttf) */ 6846 /* height of font in pixels */ 6847 /* bitmap to be filled in */ 6848 /* characters to bake */ 6849 /* you allocate this, it's num_chars long */ 6850 /* if return is positive, the first unused row of the bitmap */ 6851 /* if return is negative, returns the negative of the number of characters that fit */ 6852 /* if return is 0, no characters fit and no rows were used */ 6853 /* This uses a very crappy packing. */ 6854 6855 /* top-left */ 6856 /* bottom-right */ 6857 6858 /* same data as above */ 6859 /* character to display */ 6860 /* pointers to current position in screen pixel space */ 6861 /* output: quad to draw */ 6862 /* true if opengl fill rule; false if DX9 or earlier */ 6863 /* Call GetBakedQuad with char_index = 'character - first_char', and it */ 6864 /* creates the quad you need to draw and advances the current position. */ 6865 /* */ 6866 /* The coordinate system used assumes y increases downwards. */ 6867 /* */ 6868 /* Characters will extend both above and below the current position; */ 6869 /* see discussion of "BASELINE" above. */ 6870 /* */ 6871 /* It's inefficient; you might want to c&p it and optimize it. */ 6872 6873 /* Query the font vertical metrics without having to create a font first. */ 6874 6875 /* //////////////////////////////////////////////////////////////////////////// */ 6876 /* */ 6877 /* NEW TEXTURE BAKING API */ 6878 /* */ 6879 /* This provides options for packing multiple fonts into one atlas, not */ 6880 /* perfectly but better than nothing. */ 6881 6882 /* coordinates of bbox in bitmap */ 6883 6884 /* Initializes a packing context stored in the passed-in stbtt_pack_context. */ 6885 /* Future calls using this context will pack characters into the bitmap passed */ 6886 /* in here: a 1-channel bitmap that is width * height. stride_in_bytes is */ 6887 /* the distance from one row to the next (or 0 to mean they are packed tightly */ 6888 /* together). "padding" is the amount of padding to leave between each */ 6889 /* character (normally you want '1' for bitmaps you'll use as textures with */ 6890 /* bilinear filtering). */ 6891 /* */ 6892 /* Returns 0 on failure, 1 on success. */ 6893 6894 /* Cleans up the packing context and frees all memory. */ 6895 6896 /* Creates character bitmaps from the font_index'th font found in fontdata (use */ 6897 /* font_index=0 if you don't know what that is). It creates num_chars_in_range */ 6898 /* bitmaps for characters with unicode values starting at first_unicode_char_in_range */ 6899 /* and increasing. Data for how to render them is stored in chardata_for_range; */ 6900 /* pass these to stbtt_GetPackedQuad to get back renderable quads. */ 6901 /* */ 6902 /* font_size is the full height of the character from ascender to descender, */ 6903 /* as computed by stbtt_ScaleForPixelHeight. To use a point size as computed */ 6904 /* by stbtt_ScaleForMappingEmToPixels, wrap the point size in STBTT_POINT_SIZE() */ 6905 /* and pass that result as 'font_size': */ 6906 /* ..., 20 , ... // font max minus min y is 20 pixels tall */ 6907 /* ..., STBTT_POINT_SIZE(20), ... // 'M' is 20 pixels tall */ 6908 6909 /* if non-zero, then the chars are continuous, and this is the first codepoint */ 6910 /* if non-zero, then this is an array of unicode codepoints */ 6911 6912 /* output */ 6913 /* don't set these, they're used internally */ 6914 6915 /* Creates character bitmaps from multiple ranges of characters stored in */ 6916 /* ranges. This will usually create a better-packed bitmap than multiple */ 6917 /* calls to stbtt_PackFontRange. Note that you can call this multiple */ 6918 /* times within a single PackBegin/PackEnd. */ 6919 6920 /* Oversampling a font increases the quality by allowing higher-quality subpixel */ 6921 /* positioning, and is especially valuable at smaller text sizes. */ 6922 /* */ 6923 /* This function sets the amount of oversampling for all following calls to */ 6924 /* stbtt_PackFontRange(s) or stbtt_PackFontRangesGatherRects for a given */ 6925 /* pack context. The default (no oversampling) is achieved by h_oversample=1 */ 6926 /* and v_oversample=1. The total number of pixels required is */ 6927 /* h_oversample*v_oversample larger than the default; for example, 2x2 */ 6928 /* oversampling requires 4x the storage of 1x1. For best results, render */ 6929 /* oversampled textures with bilinear filtering. Look at the readme in */ 6930 /* stb/tests/oversample for information about oversampled fonts */ 6931 /* */ 6932 /* To use with PackFontRangesGather etc., you must set it before calls */ 6933 /* call to PackFontRangesGatherRects. */ 6934 6935 /* If skip != 0, this tells stb_truetype to skip any codepoints for which */ 6936 /* there is no corresponding glyph. If skip=0, which is the default, then */ 6937 /* codepoints without a glyph recived the font's "missing character" glyph, */ 6938 /* typically an empty box by convention. */ 6939 6940 /* same data as above */ 6941 /* character to display */ 6942 /* pointers to current position in screen pixel space */ 6943 /* output: quad to draw */ 6944 6945 /* Calling these functions in sequence is roughly equivalent to calling */ 6946 /* stbtt_PackFontRanges(). If you more control over the packing of multiple */ 6947 /* fonts, or if you want to pack custom data into a font texture, take a look */ 6948 /* at the source to of stbtt_PackFontRanges() and create a custom version */ 6949 /* using these functions, e.g. call GatherRects multiple times, */ 6950 /* building up a single array of rects, then call PackRects once, */ 6951 /* then call RenderIntoRects repeatedly. This may result in a */ 6952 /* better packing than calling PackFontRanges multiple times */ 6953 /* (or it may not). */ 6954 6955 /* this is an opaque structure that you shouldn't mess with which holds */ 6956 /* all the context needed from PackBegin to PackEnd. */ 6957 6958 /* //////////////////////////////////////////////////////////////////////////// */ 6959 /* */ 6960 /* FONT LOADING */ 6961 /* */ 6962 /* */ 6963 6964 /* This function will determine the number of fonts in a font file. TrueType */ 6965 /* collection (.ttc) files may contain multiple fonts, while TrueType font */ 6966 /* (.ttf) files only contain one font. The number of fonts can be used for */ 6967 /* indexing with the previous function where the index is between zero and one */ 6968 /* less than the total fonts. If an error occurs, -1 is returned. */ 6969 6970 /* Each .ttf/.ttc file may have more than one font. Each font has a sequential */ 6971 /* index number starting from 0. Call this function to get the font offset for */ 6972 /* a given index; it returns -1 if the index is out of range. A regular .ttf */ 6973 /* file will only define one font and it always be at offset 0, so it will */ 6974 /* return '0' for index 0, and -1 for all other indices. */ 6975 6976 /* The following structure is defined publicly so you can declare one on */ 6977 /* the stack or as a global or etc, but you should treat it as opaque. */ 6978 6979 /* pointer to .ttf file */ 6980 /* offset of start of font */ 6981 6982 /* number of glyphs, needed for range checking */ 6983 6984 /* table locations as offset from start of .ttf */ 6985 /* a cmap mapping for our chosen character encoding */ 6986 /* format needed to map from glyph index to glyph */ 6987 6988 /* cff font data */ 6989 /* the charstring index */ 6990 /* global charstring subroutines index */ 6991 /* private charstring subroutines index */ 6992 /* array of font dicts */ 6993 /* map from glyph to fontdict */ 6994 6995 /* Given an offset into the file that defines a font, this function builds */ 6996 /* the necessary cached info for the rest of the system. You must allocate */ 6997 /* the stbtt_fontinfo yourself, and stbtt_InitFont will fill it out. You don't */ 6998 /* need to do anything special to free it, because the contents are pure */ 6999 /* value data with no additional data structures. Returns 0 on failure. */ 7000 7001 /* //////////////////////////////////////////////////////////////////////////// */ 7002 /* */ 7003 /* CHARACTER TO GLYPH-INDEX CONVERSIOn */ 7004 7005 /* If you're going to perform multiple operations on the same character */ 7006 /* and you want a speed-up, call this function with the character you're */ 7007 /* going to process, then use glyph-based functions instead of the */ 7008 /* codepoint-based functions. */ 7009 /* Returns 0 if the character codepoint is not defined in the font. */ 7010 7011 /* //////////////////////////////////////////////////////////////////////////// */ 7012 /* */ 7013 /* CHARACTER PROPERTIES */ 7014 /* */ 7015 7016 /* computes a scale factor to produce a font whose "height" is 'pixels' tall. */ 7017 /* Height is measured as the distance from the highest ascender to the lowest */ 7018 /* descender; in other words, it's equivalent to calling stbtt_GetFontVMetrics */ 7019 /* and computing: */ 7020 /* scale = pixels / (ascent - descent) */ 7021 /* so if you prefer to measure height by the ascent only, use a similar calculation. */ 7022 7023 /* computes a scale factor to produce a font whose EM size is mapped to */ 7024 /* 'pixels' tall. This is probably what traditional APIs compute, but */ 7025 /* I'm not positive. */ 7026 7027 /* ascent is the coordinate above the baseline the font extends; descent */ 7028 /* is the coordinate below the baseline the font extends (i.e. it is typically negative) */ 7029 /* lineGap is the spacing between one row's descent and the next row's ascent... */ 7030 /* so you should advance the vertical position by "*ascent - *descent + *lineGap" */ 7031 /* these are expressed in unscaled coordinates, so you must multiply by */ 7032 /* the scale factor for a given size */ 7033 7034 /* analogous to GetFontVMetrics, but returns the "typographic" values from the OS/2 */ 7035 /* table (specific to MS/Windows TTF files). */ 7036 /* */ 7037 /* Returns 1 on success (table present), 0 on failure. */ 7038 7039 /* the bounding box around all possible characters */ 7040 7041 /* leftSideBearing is the offset from the current horizontal position to the left edge of the character */ 7042 /* advanceWidth is the offset from the current horizontal position to the next horizontal position */ 7043 /* these are expressed in unscaled coordinates */ 7044 7045 /* an additional amount to add to the 'advance' value between ch1 and ch2 */ 7046 7047 /* Gets the bounding box of the visible part of the glyph, in unscaled coordinates */ 7048 7049 /* as above, but takes one or more glyph indices for greater efficiency */ 7050 7051 /* use stbtt_FindGlyphIndex */ 7052 7053 /* Retrieves a complete list of all of the kerning pairs provided by the font */ 7054 /* stbtt_GetKerningTable never writes more than table_length entries and returns how many entries it did write. */ 7055 /* The table will be sorted by (a.glyph1 == b.glyph1)?(a.glyph2 < b.glyph2):(a.glyph1 < b.glyph1) */ 7056 7057 /* //////////////////////////////////////////////////////////////////////////// */ 7058 /* */ 7059 /* GLYPH SHAPES (you probably don't need these, but they have to go before */ 7060 /* the bitmaps for C declaration-order reasons) */ 7061 /* */ 7062 7063 /* you can predefine these to use different values (but why?) */ 7064 7065 /* you can predefine this to use different values */ 7066 /* (we share this with other code at RAD) */ 7067 /* can't use stbtt_int16 because that's not visible in the header file */ 7068 7069 /* returns non-zero if nothing is drawn for this glyph */ 7070 7071 /* returns # of vertices and fills *vertices with the pointer to them */ 7072 /* these are expressed in "unscaled" coordinates */ 7073 /* */ 7074 /* The shape is a series of contours. Each one starts with */ 7075 /* a STBTT_moveto, then consists of a series of mixed */ 7076 /* STBTT_lineto and STBTT_curveto segments. A lineto */ 7077 /* draws a line from previous endpoint to its x,y; a curveto */ 7078 /* draws a quadratic bezier from previous endpoint to */ 7079 /* its x,y, using cx,cy as the bezier control point. */ 7080 7081 /* frees the data allocated above */ 7082 7083 /* fills svg with the character's SVG data. */ 7084 /* returns data size or 0 if SVG not found. */ 7085 7086 /* //////////////////////////////////////////////////////////////////////////// */ 7087 /* */ 7088 /* BITMAP RENDERING */ 7089 /* */ 7090 7091 /* frees the bitmap allocated below */ 7092 7093 /* allocates a large-enough single-channel 8bpp bitmap and renders the */ 7094 /* specified character/glyph at the specified scale into it, with */ 7095 /* antialiasing. 0 is no coverage (transparent), 255 is fully covered (opaque). */ 7096 /* *width & *height are filled out with the width & height of the bitmap, */ 7097 /* which is stored left-to-right, top-to-bottom. */ 7098 /* */ 7099 /* xoff/yoff are the offset it pixel space from the glyph origin to the top-left of the bitmap */ 7100 7101 /* the same as stbtt_GetCodepoitnBitmap, but you can specify a subpixel */ 7102 /* shift for the character */ 7103 7104 /* the same as stbtt_GetCodepointBitmap, but you pass in storage for the bitmap */ 7105 /* in the form of 'output', with row spacing of 'out_stride' bytes. the bitmap */ 7106 /* is clipped to out_w/out_h bytes. Call stbtt_GetCodepointBitmapBox to get the */ 7107 /* width and height and positioning info for it first. */ 7108 7109 /* same as stbtt_MakeCodepointBitmap, but you can specify a subpixel */ 7110 /* shift for the character */ 7111 7112 /* same as stbtt_MakeCodepointBitmapSubpixel, but prefiltering */ 7113 /* is performed (see stbtt_PackSetOversampling) */ 7114 7115 /* get the bbox of the bitmap centered around the glyph origin; so the */ 7116 /* bitmap width is ix1-ix0, height is iy1-iy0, and location to place */ 7117 /* the bitmap top left is (leftSideBearing*scale,iy0). */ 7118 /* (Note that the bitmap uses y-increases-down, but the shape uses */ 7119 /* y-increases-up, so CodepointBitmapBox and CodepointBox are inverted.) */ 7120 7121 /* same as stbtt_GetCodepointBitmapBox, but you can specify a subpixel */ 7122 /* shift for the character */ 7123 7124 /* the following functions are equivalent to the above functions, but operate */ 7125 /* on glyph indices instead of Unicode codepoints (for efficiency) */ 7126 7127 /* @TODO: don't expose this structure */ 7128 7129 /* rasterize a shape with quadratic beziers into a bitmap */ 7130 /* 1-channel bitmap to draw into */ 7131 /* allowable error of curve in pixels */ 7132 /* array of vertices defining shape */ 7133 /* number of vertices in above array */ 7134 /* scale applied to input vertices */ 7135 /* translation applied to input vertices */ 7136 /* another translation applied to input */ 7137 /* if non-zero, vertically flip shape */ 7138 /* context for to STBTT_MALLOC */ 7139 7140 /* //////////////////////////////////////////////////////////////////////////// */ 7141 /* */ 7142 /* Signed Distance Function (or Field) rendering */ 7143 7144 /* frees the SDF bitmap allocated below */ 7145 7146 /* These functions compute a discretized SDF field for a single character, suitable for storing */ 7147 /* in a single-channel texture, sampling with bilinear filtering, and testing against */ 7148 /* larger than some threshold to produce scalable fonts. */ 7149 /* info -- the font */ 7150 /* scale -- controls the size of the resulting SDF bitmap, same as it would be creating a regular bitmap */ 7151 /* glyph/codepoint -- the character to generate the SDF for */ 7152 /* padding -- extra "pixels" around the character which are filled with the distance to the character (not 0), */ 7153 /* which allows effects like bit outlines */ 7154 /* onedge_value -- value 0-255 to test the SDF against to reconstruct the character (i.e. the isocontour of the character) */ 7155 /* pixel_dist_scale -- what value the SDF should increase by when moving one SDF "pixel" away from the edge (on the 0..255 scale) */ 7156 /* if positive, > onedge_value is inside; if negative, < onedge_value is inside */ 7157 /* width,height -- output height & width of the SDF bitmap (including padding) */ 7158 /* xoff,yoff -- output origin of the character */ 7159 /* return value -- a 2D array of bytes 0..255, width*height in size */ 7160 /* */ 7161 /* pixel_dist_scale & onedge_value are a scale & bias that allows you to make */ 7162 /* optimal use of the limited 0..255 for your application, trading off precision */ 7163 /* and special effects. SDF values outside the range 0..255 are clamped to 0..255. */ 7164 /* */ 7165 /* Example: */ 7166 /* scale = stbtt_ScaleForPixelHeight(22) */ 7167 /* padding = 5 */ 7168 /* onedge_value = 180 */ 7169 /* pixel_dist_scale = 180/5.0 = 36.0 */ 7170 /* */ 7171 /* This will create an SDF bitmap in which the character is about 22 pixels */ 7172 /* high but the whole bitmap is about 22+5+5=32 pixels high. To produce a filled */ 7173 /* shape, sample the SDF at each pixel and fill the pixel if the SDF value */ 7174 /* is greater than or equal to 180/255. (You'll actually want to antialias, */ 7175 /* which is beyond the scope of this example.) Additionally, you can compute */ 7176 /* offset outlines (e.g. to stroke the character border inside & outside, */ 7177 /* or only outside). For example, to fill outside the character up to 3 SDF */ 7178 /* pixels, you would compare against (180-36.0*3)/255 = 72/255. The above */ 7179 /* choice of variables maps a range from 5 pixels outside the shape to */ 7180 /* 2 pixels inside the shape to 0..255; this is intended primarily for apply */ 7181 /* outside effects only (the interior range is needed to allow proper */ 7182 /* antialiasing of the font at *smaller* sizes) */ 7183 /* */ 7184 /* The function computes the SDF analytically at each SDF pixel, not by e.g. */ 7185 /* building a higher-res bitmap and approximating it. In theory the quality */ 7186 /* should be as high as possible for an SDF of this size & representation, but */ 7187 /* unclear if this is true in practice (perhaps building a higher-res bitmap */ 7188 /* and computing from that can allow drop-out prevention). */ 7189 /* */ 7190 /* The algorithm has not been optimized at all, so expect it to be slow */ 7191 /* if computing lots of characters or very large sizes. */ 7192 7193 /* //////////////////////////////////////////////////////////////////////////// */ 7194 /* */ 7195 /* Finding the right font... */ 7196 /* */ 7197 /* You should really just solve this offline, keep your own tables */ 7198 /* of what font is what, and don't try to get it out of the .ttf file. */ 7199 /* That's because getting it out of the .ttf file is really hard, because */ 7200 /* the names in the file can appear in many possible encodings, in many */ 7201 /* possible languages, and e.g. if you need a case-insensitive comparison, */ 7202 /* the details of that depend on the encoding & language in a complex way */ 7203 /* (actually underspecified in truetype, but also gigantic). */ 7204 /* */ 7205 /* But you can use the provided functions in two possible ways: */ 7206 /* stbtt_FindMatchingFont() will use *case-sensitive* comparisons on */ 7207 /* unicode-encoded names to try to find the font you want; */ 7208 /* you can run this before calling stbtt_InitFont() */ 7209 /* */ 7210 /* stbtt_GetFontNameString() lets you get any of the various strings */ 7211 /* from the file yourself and do your own comparisons on them. */ 7212 /* You have to have called stbtt_InitFont() first. */ 7213 7214 /* returns the offset (not index) of the font that matches, or -1 if none */ 7215 /* if you use STBTT_MACSTYLE_DONTCARE, use a font name like "Arial Bold". */ 7216 /* if you use any other flag, use a font name like "Arial"; this checks */ 7217 /* the 'macStyle' header field; i don't know if fonts set this consistently */ 7218 7219 /* <= not same as 0, this makes us check the bitfield is 0 */ 7220 7221 /* returns 1/0 whether the first string interpreted as utf8 is identical to */ 7222 /* the second string interpreted as big-endian utf16... useful for strings from next func */ 7223 7224 /* returns the string (which may be big-endian double byte, e.g. for unicode) */ 7225 /* and puts the length in bytes in *length. */ 7226 /* */ 7227 /* some of the values for the IDs are below; for more see the truetype spec: */ 7228 /* http://developer.apple.com/textfonts/TTRefMan/RM06/Chap6name.html */ 7229 /* http://www.microsoft.com/typography/otspec/name.htm */ 7230 7231 /* platformID */ 7232 7233 /* encodingID for STBTT_PLATFORM_ID_UNICODE */ 7234 7235 /* encodingID for STBTT_PLATFORM_ID_MICROSOFT */ 7236 7237 /* encodingID for STBTT_PLATFORM_ID_MAC; same as Script Manager codes */ 7238 7239 /* languageID for STBTT_PLATFORM_ID_MICROSOFT; same as LCID... */ 7240 /* problematic because there are e.g. 16 english LCIDs and 16 arabic LCIDs */ 7241 7242 /* languageID for STBTT_PLATFORM_ID_MAC */ 7243 7244 /* __STB_INCLUDE_STB_TRUETYPE_H__ */ 7245 7246 /* ///////////////////////////////////////////////////////////////////////////// */ 7247 /* ///////////////////////////////////////////////////////////////////////////// */ 7248 /* // */ 7249 /* // IMPLEMENTATION */ 7250 /* // */ 7251 /* // */ 7252 7253 /* //////////////////////////////////////////////////////////////////////// */ 7254 /* */ 7255 /* stbtt__buf helpers to parse data from file */ 7256 /* */ 7257 7258 /* //////////////////////////////////////////////////////////////////////// */ 7259 /* */ 7260 /* accessors to parse data from file */ 7261 /* */ 7262 7263 /* on platforms that don't allow misaligned reads, if we want to allow */ 7264 /* truetype fonts that aren't padded to alignment, define ALLOW_UNALIGNED_TRUETYPE */ 7265 7266 /* check the version number */ 7267 /* TrueType 1 */ 7268 /* TrueType with type 1 font -- we don't support this! */ 7269 /* OpenType with CFF */ 7270 /* OpenType 1.0 */ 7271 /* Apple specification for TrueType fonts */ 7272 7273 /* @OPTIMIZE: binary search */ 7274 7275 /* if it's just a font, there's only one valid index */ 7276 7277 /* check if it's a TTC */ 7278 7279 /* version 1? */ 7280 7281 /* if it's just a font, there's only one valid font */ 7282 7283 /* check if it's a TTC */ 7284 7285 /* version 1? */ 7286 7287 /* since most people won't use this, find this table the first time it's needed */ 7288 7289 /* required */ 7290 /* required */ 7291 /* required */ 7292 /* required */ 7293 /* required */ 7294 /* required */ 7295 /* not required */ 7296 /* not required */ 7297 7298 /* required for truetype */ 7299 7300 /* initialization for CFF / Type2 fonts (OTF) */ 7301 7302 /* @TODO this should use size from table (not 512MB) */ 7303 7304 /* read the header */ 7305 7306 /* hdrsize */ 7307 7308 /* @TODO the name INDEX could list multiple fonts, */ 7309 /* but we just use the first one. */ 7310 /* name INDEX */ 7311 7312 /* string INDEX */ 7313 7314 /* we only support Type 2 charstrings */ 7315 7316 /* looks like a CID font */ 7317 7318 /* find a cmap encoding table we understand *now* to avoid searching */ 7319 /* later. (todo: could make this installable) */ 7320 /* the same regardless of glyph. */ 7321 7322 /* find an encoding we understand: */ 7323 7324 /* MS/Unicode */ 7325 7326 /* Mac/iOS has these */ 7327 /* all the encodingIDs are unicode, so we don't bother to check it */ 7328 7329 /* apple byte encoding */ 7330 7331 /* @TODO: high-byte mapping for japanese/chinese/korean */ 7332 7333 /* standard mapping for windows fonts: binary search collection of ranges */ 7334 7335 /* do a binary search of the segments */ 7336 7337 /* they lie from endCount .. endCount + segCount */ 7338 /* but searchRange is the nearest power of two, so... */ 7339 7340 /* now decrement to bias correctly to find smallest */ 7341 7342 /* Binary search the right group. */ 7343 7344 /* rounds down, so low <= mid < high */ 7345 7346 /* format == 13 */ 7347 7348 /* not found */ 7349 7350 /* @TODO */ 7351 7352 /* glyph index out of range */ 7353 /* unknown index->glyph map format */ 7354 7355 /* if length is 0, return -1 */ 7356 7357 /* a loose bound on how many vertices we might need */ 7358 7359 /* in first pass, we load uninterpreted data into the allocated array */ 7360 /* above, shifted to the end of the array so we won't overwrite it when */ 7361 /* we create our final data starting from the front */ 7362 7363 /* starting offset for uninterpreted data, regardless of how m ends up being calculated */ 7364 7365 /* first load flags */ 7366 7367 /* now load x coordinates */ 7368 7369 /* ??? */ 7370 7371 /* now load y coordinates */ 7372 7373 /* ??? */ 7374 7375 /* now convert them to our format */ 7376 7377 /* now start the new one */ 7378 7379 /* if we start off with an off-curve point, then when we need to find a point on the curve */ 7380 /* where we can start, and we need to save some state for when we wraparound. */ 7381 7382 /* next point is also a curve point, so interpolate an on-point curve */ 7383 7384 /* otherwise just use the next point as our start point */ 7385 7386 /* we're using point i+1 as the starting point, so skip it */ 7387 7388 /* if it's a curve */ 7389 /* two off-curve control points in a row means interpolate an on-curve midpoint */ 7390 7391 /* Compound shapes. */ 7392 7393 /* XY values */ 7394 /* shorts */ 7395 7396 /* @TODO handle matching point */ 7397 7398 /* WE_HAVE_A_SCALE */ 7399 7400 /* WE_HAVE_AN_X_AND_YSCALE */ 7401 7402 /* WE_HAVE_A_TWO_BY_TWO */ 7403 7404 /* Find transformation scales. */ 7405 7406 /* Get indexed glyph. */ 7407 7408 /* Transform vertices. */ 7409 7410 /* Append vertices. */ 7411 7412 /* More components ? */ 7413 7414 /* numberOfCounters == 0, do nothing */ 7415 7416 /* untested */ 7417 7418 /* this currently ignores the initial width value, which isn't needed if we have hmtx */ 7419 7420 /* @TODO implement hinting */ 7421 /* hintmask */ 7422 /* cntrmask */ 7423 7424 /* implicit "vstem" */ 7425 7426 /* hstem */ 7427 /* vstem */ 7428 /* hstemhm */ 7429 /* vstemhm */ 7430 7431 /* rmoveto */ 7432 7433 /* vmoveto */ 7434 7435 /* hmoveto */ 7436 7437 /* rlineto */ 7438 7439 /* hlineto/vlineto and vhcurveto/hvcurveto alternate horizontal and vertical */ 7440 /* starting from a different place. */ 7441 7442 /* vlineto */ 7443 7444 /* hlineto */ 7445 7446 /* hvcurveto */ 7447 7448 /* vhcurveto */ 7449 7450 /* rrcurveto */ 7451 7452 /* rcurveline */ 7453 7454 /* rlinecurve */ 7455 7456 /* vvcurveto */ 7457 /* hhcurveto */ 7458 7459 /* callsubr */ 7460 7461 /* FALLTHROUGH */ 7462 /* callgsubr */ 7463 7464 /* return */ 7465 7466 /* endchar */ 7467 7468 /* two-byte escape */ 7469 7470 /* @TODO These "flex" implementations ignore the flex-depth and resolution, */ 7471 /* and always draw beziers. */ 7472 /* hflex */ 7473 7474 /* flex */ 7475 7476 /* fd is s[12] */ 7477 7478 /* hflex1 */ 7479 7480 /* flex1 */ 7481 7482 /* push immediate */ 7483 7484 /* runs the charstring twice, once to count and once to output (to avoid realloc) */ 7485 7486 /* we only look at the first table. it must be 'horizontal' and format 0. */ 7487 7488 /* number of tables, need at least 1 */ 7489 7490 /* horizontal flag must be set in format */ 7491 7492 /* we only look at the first table. it must be 'horizontal' and format 0. */ 7493 7494 /* number of tables, need at least 1 */ 7495 7496 /* horizontal flag must be set in format */ 7497 7498 /* we only look at the first table. it must be 'horizontal' and format 0. */ 7499 7500 /* number of tables, need at least 1 */ 7501 7502 /* horizontal flag must be set in format */ 7503 7504 /* note: unaligned read */ 7505 7506 /* Binary search. */ 7507 7508 /* Binary search. */ 7509 7510 /* unsupported */ 7511 7512 /* Binary search. */ 7513 7514 /* Unsupported definition type, return an error. */ 7515 7516 /* "All glyphs not assigned to a class fall into class 0". (OpenType spec) */ 7517 7518 /* Define to STBTT_assert(x) if you want to break on unimplemented formats. */ 7519 7520 /* Major version 1 */ 7521 /* Minor version 0 */ 7522 7523 /* Pair Adjustment Positioning Subtable */ 7524 7525 /* Support more formats? */ 7526 7527 /* Binary search. */ 7528 7529 /* Support more formats? */ 7530 7531 /* malformed */ 7532 /* malformed */ 7533 7534 /* Unsupported position format */ 7535 7536 /* if no kerning table, don't waste time looking up both codepoint->glyphs */ 7537 7538 /* //////////////////////////////////////////////////////////////////////////// */ 7539 /* */ 7540 /* antialiasing software rasterizer */ 7541 /* */ 7542 7543 /* =0 suppresses compiler warning */ 7544 7545 /* e.g. space character */ 7546 7547 /* move to integral bboxes (treating pixels as little squares, what pixels get touched)? */ 7548 7549 /* //////////////////////////////////////////////////////////////////////////// */ 7550 /* */ 7551 /* Rasterizer */ 7552 7553 /* round dx down to avoid overshooting */ 7554 7555 /* use z->dx so when we offset later it's by the same amount */ 7556 7557 /* STBTT_assert(e->y0 <= start_point); */ 7558 7559 /* note: this routine clips fills that extend off the edges... ideally this */ 7560 /* wouldn't happen, but it could happen if the truetype glyph bounding boxes */ 7561 /* are wrong, or if the user supplies a too-small bitmap */ 7562 7563 /* non-zero winding fill */ 7564 7565 /* if we're currently at zero, we need to record the edge start point */ 7566 7567 /* if we went to zero, we need to draw */ 7568 7569 /* x0,x1 are the same pixel, so compute combined coverage */ 7570 7571 /* add antialiasing for x0 */ 7572 7573 /* clip */ 7574 7575 /* add antialiasing for x1 */ 7576 7577 /* clip */ 7578 7579 /* fill pixels between x0 and x1 */ 7580 7581 /* weight per vertical scanline */ 7582 /* vertical subsample index */ 7583 7584 /* find center of pixel for this scanline */ 7585 7586 /* update all active edges; */ 7587 /* remove all active edges that terminate before the center of this scanline */ 7588 7589 /* delete from list */ 7590 7591 /* advance to position for current scanline */ 7592 /* advance through list */ 7593 7594 /* resort the list if needed */ 7595 7596 /* insert all edges that start before the center of this scanline -- omit ones that also end on this scanline */ 7597 7598 /* find insertion point */ 7599 7600 /* insert at front */ 7601 7602 /* find thing to insert AFTER */ 7603 7604 /* at this point, p->next->x is NOT < z->x */ 7605 7606 /* now process all active edges in XOR fashion */ 7607 7608 /* the edge passed in here does not cross the vertical line at x or the vertical line at x+1 */ 7609 /* (i.e. it has already been clipped to those) */ 7610 7611 /* coverage = 1 - average x position */ 7612 7613 /* brute force every pixel */ 7614 7615 /* compute intersection points with top & bottom */ 7616 7617 /* compute endpoints of line segment clipped to this scanline (if the */ 7618 /* line segment starts on this scanline. x0 is the intersection of the */ 7619 /* line with y_top, but that may be off the line segment. */ 7620 7621 /* from here on, we don't have to range check x values */ 7622 7623 /* simple case, only spans one pixel */ 7624 7625 /* everything right of this pixel is filled */ 7626 7627 /* covers 2+ pixels */ 7628 7629 /* flip scanline vertically; signed area is the same */ 7630 7631 /* compute intersection with y axis at x1+1 */ 7632 7633 /* compute intersection with y axis at x2 */ 7634 7635 /* x1 x_top x2 x_bottom */ 7636 /* y_top +------|-----+------------+------------+--------|---+------------+ */ 7637 /* | | | | | | */ 7638 /* | | | | | | */ 7639 /* sy0 | Txxxxx|............|............|............|............| */ 7640 /* y_crossing | *xxxxx.......|............|............|............| */ 7641 /* | | xxxxx..|............|............|............| */ 7642 /* | | /- xx*xxxx........|............|............| */ 7643 /* | | dy < | xxxxxx..|............|............| */ 7644 /* y_final | | \- | xx*xxx.........|............| */ 7645 /* sy1 | | | | xxxxxB...|............| */ 7646 /* | | | | | | */ 7647 /* | | | | | | */ 7648 /* y_bottom +------------+------------+------------+------------+------------+ */ 7649 /* */ 7650 /* goal is to measure the area covered by '.' in each pixel */ 7651 7652 /* if x2 is right at the right edge of x1, y_crossing can blow up, github #1057 */ 7653 /* @TODO: maybe test against sy1 rather than y_bottom? */ 7654 7655 /* area of the rectangle covered from sy0..y_crossing */ 7656 7657 /* area of the triangle (x_top,sy0), (x1+1,sy0), (x1+1,y_crossing) */ 7658 7659 /* check if final y_crossing is blown up; no test case for this */ 7660 7661 /* if denom=0, y_final = y_crossing, so y_final <= y_bottom */ 7662 7663 /* in second pixel, area covered by line segment found in first pixel */ 7664 /* is always a rectangle 1 wide * the height of that line segment; this */ 7665 /* is exactly what the variable 'area' stores. it also gets a contribution */ 7666 /* from the line segment within it. the THIRD pixel will get the first */ 7667 /* pixel's rectangle contribution, the second pixel's rectangle contribution, */ 7668 /* and its own contribution. the 'own contribution' is the same in every pixel except */ 7669 /* the leftmost and rightmost, a trapezoid that slides down in each pixel. */ 7670 /* the second pixel's contribution to the third pixel will be the */ 7671 /* rectangle 1 wide times the height change in the second pixel, which is dy. */ 7672 7673 /* dy is dy/dx, change in y for every 1 change in x, */ 7674 /* which multiplied by 1-pixel-width is how much pixel area changes for each step in x */ 7675 /* so the area advances by 'step' every time */ 7676 7677 /* area of trapezoid is 1*step/2 */ 7678 7679 /* accumulated error from area += step unless we round step down */ 7680 7681 /* area covered in the last pixel is the rectangle from all the pixels to the left, */ 7682 /* plus the trapezoid filled by the line segment in this pixel all the way to the right edge */ 7683 7684 /* the rest of the line is filled based on the total height of the line segment in this pixel */ 7685 7686 /* if edge goes outside of box we're drawing, we require */ 7687 /* clipping logic. since this does not match the intended use */ 7688 /* of this library, we use a different, very slow brute */ 7689 /* force implementation */ 7690 /* note though that this does happen some of the time because */ 7691 /* x_top and x_bottom can be extrapolated at the top & bottom of */ 7692 /* the shape and actually lie outside the bounding box */ 7693 7694 /* cases: */ 7695 /* */ 7696 /* there can be up to two intersections with the pixel. any intersection */ 7697 /* with left or right edges can be handled by splitting into two (or three) */ 7698 /* regions. intersections with top & bottom do not necessitate case-wise logic. */ 7699 /* */ 7700 /* the old way of doing this found the intersections with the left & right edges, */ 7701 /* then used some simple logic to produce up to three segments in sorted order */ 7702 /* from top-to-bottom. however, this had a problem: if an x edge was epsilon */ 7703 /* across the x border, then the corresponding y position might not be distinct */ 7704 /* from the other y segment, and it might ignored as an empty segment. to avoid */ 7705 /* that, we need to explicitly produce segments based on x positions. */ 7706 7707 /* rename variables to clearly-defined pairs */ 7708 7709 /* x = e->x + e->dx * (y-y_top) */ 7710 /* (y-y_top) = (x - e->x) / e->dx */ 7711 /* y = (x - e->x) / e->dx + y_top */ 7712 7713 /* three segments descending down-right */ 7714 7715 /* three segments descending down-left */ 7716 7717 /* two segments across x, down-right */ 7718 7719 /* two segments across x, down-left */ 7720 7721 /* two segments across x+1, down-right */ 7722 7723 /* two segments across x+1, down-left */ 7724 7725 /* one segment */ 7726 7727 /* directly AA rasterize edges w/o supersampling */ 7728 7729 /* find center of pixel for this scanline */ 7730 7731 /* update all active edges; */ 7732 /* remove all active edges that terminate before the top of this scanline */ 7733 7734 /* delete from list */ 7735 7736 /* advance through list */ 7737 7738 /* insert all edges that start before the bottom of this scanline */ 7739 7740 /* this can happen due to subpixel positioning and some kind of fp rounding error i think */ 7741 7742 /* if we get really unlucky a tiny bit of an edge can be out of bounds */ 7743 /* insert at front */ 7744 7745 /* now process all active edges */ 7746 7747 /* advance all the edges */ 7748 7749 /* advance to position for current scanline */ 7750 /* advance through list */ 7751 7752 /* threshold for transitioning to insertion sort */ 7753 7754 /* compute median of three */ 7755 7756 /* if 0 >= mid >= end, or 0 < mid < end, then use mid */ 7757 7758 /* otherwise, we'll need to swap something else to middle */ 7759 7760 /* 0>mid && mid<n: 0>n => n; 0<n => 0 */ 7761 /* 0<mid && mid>n: 0>n => 0; 0<n => n */ 7762 7763 /* now p[m] is the median-of-three */ 7764 /* swap it to the beginning so it won't move around */ 7765 7766 /* partition loop */ 7767 7768 /* handling of equality is crucial here */ 7769 /* for sentinels & efficiency with duplicates */ 7770 7771 /* make sure we haven't crossed */ 7772 7773 /* recurse on smaller side, iterate on larger */ 7774 7775 /* vsubsample should divide 255 evenly; otherwise we won't reach full opacity */ 7776 7777 /* now we have to blow out the windings into explicit edge lists */ 7778 7779 /* add an extra one as a sentinel */ 7780 7781 /* skip the edge if horizontal */ 7782 7783 /* add edge from j to k to the list */ 7784 7785 /* now sort the edges by their highest point (should snap to integer, and then by x) */ 7786 /* STBTT_sort(e, n, sizeof(e[0]), stbtt__edge_compare); */ 7787 7788 /* now, traverse the scanlines and find the intersections on each scanline, use xor winding rule */ 7789 7790 /* during first pass, it's unallocated */ 7791 7792 /* tessellate until threshold p is happy... @TODO warped to compensate for non-linear stretching */ 7793 7794 /* midpoint */ 7795 7796 /* versus directly drawn line */ 7797 7798 /* 65536 segments on one curve better be enough! */ 7799 7800 /* half-pixel error allowed... need to be smaller if AA */ 7801 7802 /* @TODO this "flatness" calculation is just made-up nonsense that seems to work well enough */ 7803 7804 /* 65536 segments on one curve better be enough! */ 7805 7806 /* returns number of contours */ 7807 7808 /* count how many "moves" there are to get the contour count */ 7809 7810 /* make two passes through the points so we don't need to realloc */ 7811 7812 /* start the next contour */ 7813 7814 /* now we get the size */ 7815 7816 /* in case we error */ 7817 7818 /* //////////////////////////////////////////////////////////////////////////// */ 7819 /* */ 7820 /* bitmap baking */ 7821 /* */ 7822 /* This is SUPER-CRAPPY packing to keep source code small */ 7823 7824 /* font location (use offset=0 for plain .ttf) */ 7825 /* height of font in pixels */ 7826 /* bitmap to be filled in */ 7827 /* characters to bake */ 7828 7829 /* background of 0 around pixels */ 7830 7831 /* advance to next row */ 7832 /* check if it fits vertically AFTER potentially moving to next row */ 7833 7834 /* //////////////////////////////////////////////////////////////////////////// */ 7835 /* */ 7836 /* rectangle packing replacement routines if you don't have stb_rect_pack.h */ 7837 /* */ 7838 7839 /* ////////////////////////////////////////////////////////////////////////////////// */ 7840 /* // */ 7841 /* // */ 7842 /* COMPILER WARNING ?!?!? // */ 7843 /* // */ 7844 /* // */ 7845 /* if you get a compile warning due to these symbols being defined more than // */ 7846 /* once, move #include "stb_rect_pack.h" before #include "stb_truetype.h" // */ 7847 /* // */ 7848 /* ////////////////////////////////////////////////////////////////////////////////// */ 7849 7850 /* //////////////////////////////////////////////////////////////////////////// */ 7851 /* */ 7852 /* bitmap baking */ 7853 /* */ 7854 /* This is SUPER-AWESOME (tm Ryan Gordon) packing using stb_rect_pack.h. If */ 7855 /* stb_rect_pack.h isn't available, it uses the BakeFontBitmap strategy. */ 7856 7857 /* background of 0 around pixels */ 7858 7859 /* suppress bogus warning from VS2013 -analyze */ 7860 7861 /* make kernel_width a constant in common cases so compiler can optimize out the divide */ 7862 7863 /* suppress bogus warning from VS2013 -analyze */ 7864 7865 /* make kernel_width a constant in common cases so compiler can optimize out the divide */ 7866 7867 /* The prefilter is a box filter of width "oversample", */ 7868 /* which shifts phase by (oversample - 1)/2 pixels in */ 7869 /* oversampled space. We want to shift in the opposite */ 7870 /* direction to counter this. */ 7871 7872 /* rects array must be big enough to accommodate all characters in the given ranges */ 7873 7874 /* rects array must be big enough to accommodate all characters in the given ranges */ 7875 7876 /* save current values */ 7877 7878 /* pad on left and top */ 7879 7880 /* if any fail, report failure */ 7881 7882 /* restore original values */ 7883 7884 /* stbrp_context *context = (stbrp_context *) spc->pack_info; */ 7885 7886 /* flag all characters as NOT packed */ 7887 7888 /* //////////////////////////////////////////////////////////////////////////// */ 7889 /* */ 7890 /* sdf computation */ 7891 /* */ 7892 7893 /* 2*b*s + c = 0 */ 7894 /* s = -c / (2*b) */ 7895 7896 /* make sure y never passes through a vertex of the shape */ 7897 7898 /* test a ray from (-infinity,y) to (x,y) */ 7899 7900 /* x^3 + a*x^2 + b*x + c = 0 */ 7901 7902 /* p3 must be negative, since d is negative */ 7903 7904 /* STBTT_assert( STBTT_fabs(((r[0]+a)*r[0]+b)*r[0]+c) < 0.05f); // these asserts may not be safe at all scales, though they're in bezier t parameter units so maybe? */ 7905 /* STBTT_assert( STBTT_fabs(((r[1]+a)*r[1]+b)*r[1]+c) < 0.05f); */ 7906 /* STBTT_assert( STBTT_fabs(((r[2]+a)*r[2]+b)*r[2]+c) < 0.05f); */ 7907 7908 /* if empty, return NULL */ 7909 7910 /* invert for y-downwards bitmaps */ 7911 7912 /* @OPTIMIZE: this could just be a rasterization, but needs to be line vs. non-tesselated curves so a new path */ 7913 7914 /* coarse culling against bbox */ 7915 /* if (sx > STBTT_min(x0,x1)-min_dist && sx < STBTT_max(x0,x1)+min_dist && */ 7916 /* sy > STBTT_min(y0,y1)-min_dist && sy < STBTT_max(y0,y1)+min_dist) */ 7917 7918 /* check position along line */ 7919 /* x' = x0 + t*(x1-x0), y' = y0 + t*(y1-y0) */ 7920 /* minimize (x'-sx)*(x'-sx)+(y'-sy)*(y'-sy) */ 7921 7922 /* minimize (px+t*dx)^2 + (py+t*dy)^2 = px*px + 2*px*dx*t + t^2*dx*dx + py*py + 2*py*dy*t + t^2*dy*dy */ 7923 /* derivative: 2*px*dx + 2*py*dy + (2*dx*dx+2*dy*dy)*t, set to 0 and solve */ 7924 7925 /* coarse culling against bbox to avoid computing cubic unnecessarily */ 7926 7927 /* if a_inv is 0, it's 2nd degree so use quadratic formula */ 7928 7929 /* if a is 0, it's linear */ 7930 7931 /* don't bother distinguishing 1-solution case, as code below will still work */ 7932 7933 /* could precompute this as it doesn't depend on sample point */ 7934 7935 /* if outside the shape, value is negative */ 7936 7937 /* //////////////////////////////////////////////////////////////////////////// */ 7938 /* */ 7939 /* font name matching -- recommended not to use this */ 7940 /* */ 7941 7942 /* check if a utf8 string contains a prefix which is the utf16 string; if so return length of matching utf8 string */ 7943 7944 /* convert utf16 to utf8 and compare the results while converting */ 7945 7946 /* plus another 2 below */ 7947 7948 /* returns results in whatever encoding you request... but note that 2-byte encodings */ 7949 /* will be BIG-ENDIAN... use stbtt_CompareUTF8toUTF16_bigendian() to compare */ 7950 7951 /* find the encoding */ 7952 7953 /* is this a Unicode encoding? */ 7954 7955 /* check if there's a prefix match */ 7956 7957 /* check for target_id+1 immediately following, with same encoding & language */ 7958 7959 /* if nothing immediately following */ 7960 7961 /* @TODO handle other encodings */ 7962 7963 /* check italics/bold/underline flags in macStyle... */ 7964 7965 /* if we checked the macStyle flags, then just check the family and ignore the subfamily */ 7966 7967 /* STB_TRUETYPE_IMPLEMENTATION */ 7968 7969 /* FULL VERSION HISTORY */ 7970 /* */ 7971 /* 1.25 (2021-07-11) many fixes */ 7972 /* 1.24 (2020-02-05) fix warning */ 7973 /* 1.23 (2020-02-02) query SVG data for glyphs; query whole kerning table (but only kern not GPOS) */ 7974 /* 1.22 (2019-08-11) minimize missing-glyph duplication; fix kerning if both 'GPOS' and 'kern' are defined */ 7975 /* 1.21 (2019-02-25) fix warning */ 7976 /* 1.20 (2019-02-07) PackFontRange skips missing codepoints; GetScaleFontVMetrics() */ 7977 /* 1.19 (2018-02-11) OpenType GPOS kerning (horizontal only), STBTT_fmod */ 7978 /* 1.18 (2018-01-29) add missing function */ 7979 /* 1.17 (2017-07-23) make more arguments const; doc fix */ 7980 /* 1.16 (2017-07-12) SDF support */ 7981 /* 1.15 (2017-03-03) make more arguments const */ 7982 /* 1.14 (2017-01-16) num-fonts-in-TTC function */ 7983 /* 1.13 (2017-01-02) support OpenType fonts, certain Apple fonts */ 7984 /* 1.12 (2016-10-25) suppress warnings about casting away const with -Wcast-qual */ 7985 /* 1.11 (2016-04-02) fix unused-variable warning */ 7986 /* 1.10 (2016-04-02) allow user-defined fabs() replacement */ 7987 /* fix memory leak if fontsize=0.0 */ 7988 /* fix warning from duplicate typedef */ 7989 /* 1.09 (2016-01-16) warning fix; avoid crash on outofmem; use alloc userdata for PackFontRanges */ 7990 /* 1.08 (2015-09-13) document stbtt_Rasterize(); fixes for vertical & horizontal edges */ 7991 /* 1.07 (2015-08-01) allow PackFontRanges to accept arrays of sparse codepoints; */ 7992 /* allow PackFontRanges to pack and render in separate phases; */ 7993 /* fix stbtt_GetFontOFfsetForIndex (never worked for non-0 input?); */ 7994 /* fixed an assert() bug in the new rasterizer */ 7995 /* replace assert() with STBTT_assert() in new rasterizer */ 7996 /* 1.06 (2015-07-14) performance improvements (~35% faster on x86 and x64 on test machine) */ 7997 /* also more precise AA rasterizer, except if shapes overlap */ 7998 /* remove need for STBTT_sort */ 7999 /* 1.05 (2015-04-15) fix misplaced definitions for STBTT_STATIC */ 8000 /* 1.04 (2015-04-15) typo in example */ 8001 /* 1.03 (2015-04-12) STBTT_STATIC, fix memory leak in new packing, various fixes */ 8002 /* 1.02 (2014-12-10) fix various warnings & compile issues w/ stb_rect_pack, C++ */ 8003 /* 1.01 (2014-12-08) fix subpixel position when oversampling to exactly match */ 8004 /* non-oversampled; STBTT_POINT_SIZE for packed case only */ 8005 /* 1.00 (2014-12-06) add new PackBegin etc. API, w/ support for oversampling */ 8006 /* 0.99 (2014-09-18) fix multiple bugs with subpixel rendering (ryg) */ 8007 /* 0.9 (2014-08-07) support certain mac/iOS fonts without an MS platformID */ 8008 /* 0.8b (2014-07-07) fix a warning */ 8009 /* 0.8 (2014-05-25) fix a few more warnings */ 8010 /* 0.7 (2013-09-25) bugfix: subpixel glyph bug fixed in 0.5 had come back */ 8011 /* 0.6c (2012-07-24) improve documentation */ 8012 /* 0.6b (2012-07-20) fix a few more warnings */ 8013 /* 0.6 (2012-07-17) fix warnings; added stbtt_ScaleForMappingEmToPixels, */ 8014 /* stbtt_GetFontBoundingBox, stbtt_IsGlyphEmpty */ 8015 /* 0.5 (2011-12-09) bugfixes: */ 8016 /* subpixel glyph renderer computed wrong bounding box */ 8017 /* first vertex of shape can be off-curve (FreeSans) */ 8018 /* 0.4b (2011-12-03) fixed an error in the font baking example */ 8019 /* 0.4 (2011-12-01) kerning, subpixel rendering (tor) */ 8020 /* bugfixes for: */ 8021 /* codepoint-to-glyph conversion using table fmt=12 */ 8022 /* codepoint-to-glyph conversion using table fmt=4 */ 8023 /* stbtt_GetBakedQuad with non-square texture (Zer) */ 8024 /* updated Hello World! sample to use kerning and subpixel */ 8025 /* fixed some warnings */ 8026 /* 0.3 (2009-06-24) cmap fmt=12, compound shapes (MM) */ 8027 /* userdata, malloc-from-userdata, non-zero fill (stb) */ 8028 /* 0.2 (2009-03-11) Fix unsigned/signed char warnings */ 8029 /* 0.1 (2009-03-09) First public release */ 8030 /* */ 8031 8032 /* 8033 ------------------------------------------------------------------------------ 8034 This software is available under 2 licenses -- choose whichever you prefer. 8035 ------------------------------------------------------------------------------ 8036 ALTERNATIVE A - MIT License 8037 Copyright (c) 2017 Sean Barrett 8038 Permission is hereby granted, free of charge, to any person obtaining a copy of 8039 this software and associated documentation files (the "Software"), to deal in 8040 the Software without restriction, including without limitation the rights to 8041 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 8042 of the Software, and to permit persons to whom the Software is furnished to do 8043 so, subject to the following conditions: 8044 The above copyright notice and this permission notice shall be included in all 8045 copies or substantial portions of the Software. 8046 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 8047 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 8048 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 8049 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 8050 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 8051 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 8052 SOFTWARE. 8053 ------------------------------------------------------------------------------ 8054 ALTERNATIVE B - Public Domain (www.unlicense.org) 8055 This is free and unencumbered software released into the public domain. 8056 Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 8057 software, either in source code form or as a compiled binary, for any purpose, 8058 commercial or non-commercial, and by any means. 8059 In jurisdictions that recognize copyright laws, the author or authors of this 8060 software dedicate any and all copyright interest in the software to the public 8061 domain. We make this dedication for the benefit of the public at large and to 8062 the detriment of our heirs and successors. We intend this dedication to be an 8063 overt act of relinquishment in perpetuity of all present and future rights to 8064 this software under copyright law. 8065 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 8066 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 8067 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 8068 AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 8069 ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 8070 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8071 ------------------------------------------------------------------------------ 8072 */ 8073 8074 /* ------------------------------------------------------------- 8075 * 8076 * RECT PACK 8077 * 8078 * --------------------------------------------------------------*/ 8079 8080 /* 8081 * ============================================================== 8082 * 8083 * TRUETYPE 8084 * 8085 * =============================================================== 8086 */ 8087 8088 /* ------------------------------------------------------------- 8089 * 8090 * FONT BAKING 8091 * 8092 * --------------------------------------------------------------*/ 8093 8094 /* setup baker inside a memory block */ 8095 8096 /* setup font baker from temporary memory */ 8097 8098 /* pack custom user data first so it will be in the upper left corner*/ 8099 8100 /* first font pass: pack all glyphs */ 8101 8102 /* count glyphs + ranges in current font */ 8103 8104 /* setup ranges */ 8105 8106 /* pack */ 8107 8108 /* texture height */ 8109 8110 /* second font pass: render glyphs */ 8111 8112 /* third pass: setup font and glyphs */ 8113 8114 /* fill baked font */ 8115 8116 /* 8117 Need to zero this, or it will carry over from a previous 8118 bake, and cause a segfault when accessing glyphs[]. 8119 */ 8120 8121 /* fill own baked font glyph array */ 8122 8123 /* query glyph bounds from stb_truetype */ 8124 8125 /* fill own glyph type with data */ 8126 8127 /* ------------------------------------------------------------- 8128 * 8129 * FONT 8130 * 8131 * --------------------------------------------------------------*/ 8132 8133 /* query currently drawn glyph information */ 8134 8135 /* offset next glyph */ 8136 8137 /* --------------------------------------------------------------------------- 8138 * 8139 * DEFAULT FONT 8140 * 8141 * ProggyClean.ttf 8142 * Copyright (c) 2004, 2005 Tristan Grimmer 8143 * MIT license (see License.txt in http://www.upperbounds.net/download/ProggyClean.ttf.zip) 8144 * Download and more information at http://upperbounds.net 8145 *-----------------------------------------------------------------------------*/ 8146 8147 /* NK_INCLUDE_DEFAULT_FONT */ 8148 8149 /* INVERSE of memmove... write each byte before copying the next...*/ 8150 8151 /* use fewer if's for cases that expand small */ 8152 8153 /* *i >= 0x20 */ 8154 /* more ifs for cases that expand large, since overhead is amortized */ 8155 8156 /* error! stream is > 4GB */ 8157 8158 /* NOTREACHED */ 8159 8160 /* we can't assume little-endianess. */ 8161 8162 /* ------------------------------------------------------------- 8163 * 8164 * FONT ATLAS 8165 * 8166 * --------------------------------------------------------------*/ 8167 8168 /* allocate font config */ 8169 8170 /* insert font config into list */ 8171 8172 /* allocate new font */ 8173 8174 /* insert font into list */ 8175 8176 /* extend previously added font */ 8177 8178 /* create own copy of .TTF font blob */ 8179 8180 /* no font added so just use default font */ 8181 8182 /* allocate temporary baker memory required for the baking process */ 8183 8184 /* allocate glyph memory for all fonts */ 8185 8186 /* pack all glyphs into a tight fit space */ 8187 8188 /* allocate memory for the baked image font atlas */ 8189 8190 /* bake glyphs and custom white pixel into image */ 8191 8192 /* convert alpha8 image into rgba32 image */ 8193 8194 /* initialize each font */ 8195 8196 /* initialize each cursor */ 8197 8198 /* Pos Size Offset */ 8199 8200 /* free temporary memory */ 8201 8202 /* error so cleanup all memory */ 8203 8204 /* =============================================================== 8205 * 8206 * INPUT 8207 * 8208 * ===============================================================*/ 8209 8210 /* =============================================================== 8211 * 8212 * STYLE 8213 * 8214 * ===============================================================*/ 8215 8216 /* default text */ 8217 8218 /* default button */ 8219 8220 /* contextual button */ 8221 8222 /* menu button */ 8223 8224 /* checkbox toggle */ 8225 8226 /* option toggle */ 8227 8228 /* selectable */ 8229 8230 /* slider */ 8231 8232 /* slider buttons */ 8233 8234 /* progressbar */ 8235 8236 /* scrollbars */ 8237 8238 /* scrollbars buttons */ 8239 8240 /* edit */ 8241 8242 /* property */ 8243 8244 /* property buttons */ 8245 8246 /* property edit */ 8247 8248 /* chart */ 8249 8250 /* combo */ 8251 8252 /* combo button */ 8253 8254 /* tab */ 8255 8256 /* tab button */ 8257 8258 /* node button */ 8259 8260 /* window header */ 8261 8262 /* window header close button */ 8263 8264 /* window header minimize button */ 8265 8266 /* window */ 8267 8268 /* ============================================================== 8269 * 8270 * CONTEXT 8271 * 8272 * ===============================================================*/ 8273 8274 /* take memory from buffer and alloc fixed pool */ 8275 8276 /* create dynamic pool from buffer allocator */ 8277 8278 /* garbage collector */ 8279 8280 /* make sure valid minimized windows do not get removed */ 8281 8282 /* remove hotness from hidden or closed windows*/ 8283 8284 /* free unused popup windows */ 8285 8286 /* remove unused window state tables */ 8287 8288 /* window itself is not used anymore so free */ 8289 8290 /* save buffer fill state for popup */ 8291 8292 /* draw cursor overlay */ 8293 8294 /* build one big draw command list out of all window buffers */ 8295 8296 /* skip empty command buffers */ 8297 8298 /* append all popup draw commands into lists */ 8299 8300 /* append overlay commands */ 8301 8302 /* =============================================================== 8303 * 8304 * POOL 8305 * 8306 * ===============================================================*/ 8307 8308 /* first nk_page_element is embedded in nk_page, additional elements follow in adjacent space */ 8309 8310 /* allocate new page */ 8311 8312 /* =============================================================== 8313 * 8314 * PAGE ELEMENT 8315 * 8316 * ===============================================================*/ 8317 8318 /* unlink page element from free list */ 8319 8320 /* allocate page element from memory pool */ 8321 8322 /* allocate new page element from back of fixed size memory buffer */ 8323 8324 /* link table into freelist */ 8325 8326 /* we have a pool so just add to free list */ 8327 8328 /* if possible remove last element from back of fixed memory buffer */ 8329 8330 /* =============================================================== 8331 * 8332 * TABLE 8333 * 8334 * ===============================================================*/ 8335 8336 /* =============================================================== 8337 * 8338 * PANEL 8339 * 8340 * ===============================================================*/ 8341 8342 /* pull state into local stack */ 8343 8344 /* pull style configuration into local stack */ 8345 8346 /* window movement */ 8347 8348 /* calculate draggable window space */ 8349 8350 /* window movement by dragging */ 8351 8352 /* setup panel */ 8353 8354 /* panel header */ 8355 8356 /* calculate header bounds */ 8357 8358 /* shrink panel by header */ 8359 8360 /* select correct header background and text color */ 8361 8362 /* draw header background */ 8363 8364 /* window close button */ 8365 8366 /* window minimize button */ 8367 8368 /* window header title */ 8369 8370 /* draw window background */ 8371 8372 /* set clipping rectangle */ 8373 8374 /* cache configuration data */ 8375 8376 /* update the current cursor Y-position to point over the last added widget */ 8377 8378 /* dynamic panels */ 8379 8380 /* update panel height to fit dynamic growth */ 8381 8382 /* fill top empty space */ 8383 8384 /* fill left empty space */ 8385 8386 /* fill right empty space */ 8387 8388 /* fill bottom empty space */ 8389 8390 /* scrollbars */ 8391 8392 /* mouse wheel scrolling */ 8393 8394 /* sub-window mouse wheel scrolling */ 8395 8396 /* only allow scrolling if parent window is active */ 8397 8398 /* and panel is being hovered and inside clip rect*/ 8399 8400 /* deactivate all parent scrolling */ 8401 8402 /* window mouse wheel scrolling */ 8403 8404 /* vertical scrollbar */ 8405 8406 /* horizontal scrollbar */ 8407 8408 /* hide scroll if no user input */ 8409 8410 /* window border */ 8411 8412 /* scaler */ 8413 8414 /* calculate scaler bounds */ 8415 8416 /* draw scaler */ 8417 8418 /* do window scaling */ 8419 8420 /* dragging in x-direction */ 8421 8422 /* dragging in y-direction (only possible if static window) */ 8423 8424 /* window is hidden so clear command buffer */ 8425 8426 /* window is visible and not tab */ 8427 8428 /* NK_WINDOW_REMOVE_ROM flag was set so remove NK_WINDOW_ROM */ 8429 8430 /* property garbage collector */ 8431 8432 /* edit garbage collector */ 8433 8434 /* contextual garbage collector */ 8435 8436 /* helper to make sure you have a 'nk_tree_push' for every 'nk_tree_pop' */ 8437 8438 /* =============================================================== 8439 * 8440 * WINDOW 8441 * 8442 * ===============================================================*/ 8443 8444 /* unlink windows from list */ 8445 8446 /*free window state tables */ 8447 8448 /* link windows into freelist */ 8449 8450 /*ctx->end->flags |= NK_WINDOW_ROM;*/ 8451 8452 /* find or create window */ 8453 8454 /* create new window */ 8455 8456 /* update window */ 8457 8458 /* If this assert triggers you either: 8459 * 8460 * I.) Have more than one window with the same name or 8461 * II.) You forgot to actually draw the window. 8462 * More specific you did not call `nk_clear` (nk_clear will be 8463 * automatically called for you if you are using one of the 8464 * provided demo backends). */ 8465 8466 /* window overlapping */ 8467 8468 /* activate window if hovered and no other window is overlapping this window */ 8469 8470 /* activate window if clicked */ 8471 8472 /* try to find a panel with higher priority in the same position */ 8473 8474 /* current window is active in that position so transfer to top 8475 * at the highest priority in stack */ 8476 8477 /* current window is active in that position so transfer to top 8478 * at the highest priority in stack */ 8479 8480 /* check if window is being hovered */ 8481 8482 /* check if window popup is being hovered */ 8483 8484 /* =============================================================== 8485 * 8486 * POPUP 8487 * 8488 * ===============================================================*/ 8489 8490 /* make sure we have correct popup */ 8491 8492 /* popup position is local to window */ 8493 8494 /* setup popup data */ 8495 8496 /* popup is running therefore invalidate parent panels */ 8497 8498 /* popup was closed/is invalid so cleanup */ 8499 8500 /* popups cannot have popups */ 8501 8502 /* create window for nonblocking popup */ 8503 8504 /* close the popup if user pressed outside or in the header */ 8505 8506 /* remove read only mode from all parent panels */ 8507 8508 /* set read only mode to all parent panels */ 8509 8510 /* ============================================================== 8511 * 8512 * CONTEXTUAL 8513 * 8514 * ===============================================================*/ 8515 8516 /* check if currently active contextual is active */ 8517 8518 /* calculate contextual position on click */ 8519 8520 /* start nonblocking contextual popup */ 8521 8522 /* Close behavior 8523 This is a bit of a hack solution since we do not know before we end our popup 8524 how big it will be. We therefore do not directly know when a 8525 click outside the non-blocking popup must close it at that direct frame. 8526 Instead it will be closed in the next frame.*/ 8527 8528 /* =============================================================== 8529 * 8530 * MENU 8531 * 8532 * ===============================================================*/ 8533 8534 /* if this assert triggers you allocated space between nk_begin and nk_menubar_begin. 8535 If you want a menubar the first nuklear function after `nk_begin` has to be a 8536 `nk_menubar_begin` call. Inside the menubar you then have to allocate space for 8537 widgets (also supports multiple rows). 8538 Example: 8539 if (nk_begin(...)) { 8540 nk_menubar_begin(...); 8541 nk_layout_xxxx(...); 8542 nk_button(...); 8543 nk_layout_xxxx(...); 8544 nk_button(...); 8545 nk_menubar_end(...); 8546 } 8547 nk_end(...); 8548 */ 8549 8550 /* =============================================================== 8551 * 8552 * LAYOUT 8553 * 8554 * ===============================================================*/ 8555 8556 /* calculate the usable panel space */ 8557 8558 /* prefetch some configuration data */ 8559 8560 /* if one of these triggers you forgot to add an `if` condition around either 8561 a window, group, popup, combobox or contextual menu `begin` and `end` block. 8562 Example: 8563 if (nk_begin(...) {...} nk_end(...); or 8564 if (nk_group_begin(...) { nk_group_end(...);} */ 8565 8566 /* update the current row and set the current row layout */ 8567 8568 /* draw background for dynamic panels */ 8569 8570 /* update the current row and set the current row layout */ 8571 8572 /* calculate width of undefined widget ratios */ 8573 8574 /* will be used to remove fookin gaps */ 8575 /* calculate the width of one item inside the current layout space */ 8576 8577 /* scaling fixed size widgets item width */ 8578 8579 /* scaling single ratio widget width */ 8580 8581 /* panel width depended free widget placing */ 8582 8583 /* scaling arrays of panel width ratios for every widget */ 8584 8585 /* non-scaling fixed widgets item width */ 8586 8587 /* scaling single ratio widget width */ 8588 8589 /* free widget placing */ 8590 8591 /* non-scaling array of panel pixel width for every widget */ 8592 8593 /* stretchy row layout with combined dynamic/static widget width*/ 8594 8595 /* set the bounds of the newly allocated widget */ 8596 8597 /* check if the end of the row has been hit and begin new row if so */ 8598 8599 /* calculate widget position and size */ 8600 8601 /* =============================================================== 8602 * 8603 * TREE 8604 * 8605 * ===============================================================*/ 8606 8607 /* cache some data */ 8608 8609 /* calculate header bounds and draw background */ 8610 8611 /* update node state */ 8612 8613 /* select correct button style */ 8614 8615 /* draw triangle button */ 8616 8617 /* draw optional image icon */ 8618 8619 /* draw label */ 8620 8621 /* increase x-axis cursor widget position pointer */ 8622 8623 /* retrieve tree state from internal widget state tables */ 8624 8625 /* cache some data */ 8626 8627 /* calculate header bounds and draw background */ 8628 8629 /* select correct button style */ 8630 8631 /* draw triangle button */ 8632 8633 /* draw label */ 8634 8635 /* calculate size of the text and tooltip */ 8636 8637 /* increase x-axis cursor widget position pointer */ 8638 8639 /* retrieve tree state from internal widget state tables */ 8640 8641 /* =============================================================== 8642 * 8643 * GROUP 8644 * 8645 * ===============================================================*/ 8646 8647 /* initialize a fake window to create the panel from */ 8648 8649 /* make sure nk_group_begin was called correctly */ 8650 8651 /* dummy window */ 8652 8653 /* make sure group has correct clipping rectangle */ 8654 8655 /* find persistent group scrollbar value */ 8656 8657 /* find persistent group scrollbar value */ 8658 8659 /* find persistent group scrollbar value */ 8660 8661 /* =============================================================== 8662 * 8663 * LIST VIEW 8664 * 8665 * ===============================================================*/ 8666 8667 /* find persistent list view scrollbar offset */ 8668 8669 /* =============================================================== 8670 * 8671 * WIDGET 8672 * 8673 * ===============================================================*/ 8674 8675 /* allocate space and check if the widget needs to be updated and drawn */ 8676 8677 /* if one of these triggers you forgot to add an `if` condition around either 8678 a window, group, popup, combobox or contextual menu `begin` and `end` block. 8679 Example: 8680 if (nk_begin(...) {...} nk_end(...); or 8681 if (nk_group_begin(...) { nk_group_end(...);} */ 8682 8683 /* need to convert to int here to remove floating point errors */ 8684 8685 /* update the bounds to stand without padding */ 8686 8687 /* spacing over row boundaries */ 8688 8689 /* non table layout need to allocate space */ 8690 8691 /* =============================================================== 8692 * 8693 * TEXT 8694 * 8695 * ===============================================================*/ 8696 8697 /* align in x-axis */ 8698 8699 /* align in y-axis */ 8700 8701 /* =============================================================== 8702 * 8703 * IMAGE 8704 * 8705 * ===============================================================*/ 8706 8707 /* =============================================================== 8708 * 8709 * 9-SLICE 8710 * 8711 * ===============================================================*/ 8712 8713 /* ============================================================== 8714 * 8715 * BUTTON 8716 * 8717 * ===============================================================*/ 8718 8719 /* single character text symbol */ 8720 8721 /* simple empty/filled shapes */ 8722 8723 /* calculate button content space */ 8724 8725 /* execute button behavior */ 8726 8727 /* select correct colors/images */ 8728 8729 /* select correct colors/images */ 8730 8731 /* select correct background colors/images */ 8732 8733 /* select correct text colors */ 8734 8735 /* draw button */ 8736 8737 /* select correct colors */ 8738 8739 /* =============================================================== 8740 * 8741 * TOGGLE 8742 * 8743 * ===============================================================*/ 8744 8745 /* select correct colors/images */ 8746 8747 /* draw background and cursor */ 8748 8749 /* select correct colors/images */ 8750 8751 /* draw background and cursor */ 8752 8753 /* add additional touch padding for touch screen devices */ 8754 8755 /* calculate the selector space */ 8756 8757 /* calculate the bounds of the cursor inside the selector */ 8758 8759 /* label behind the selector */ 8760 8761 /* update selector */ 8762 8763 /* draw selector */ 8764 8765 /*---------------------------------------------------------------- 8766 * 8767 * CHECKBOX 8768 * 8769 * --------------------------------------------------------------*/ 8770 8771 /*---------------------------------------------------------------- 8772 * 8773 * OPTION 8774 * 8775 * --------------------------------------------------------------*/ 8776 8777 /* =============================================================== 8778 * 8779 * SELECTABLE 8780 * 8781 * ===============================================================*/ 8782 8783 /* select correct colors/images */ 8784 8785 /* draw selectable background and text */ 8786 8787 /* remove padding */ 8788 8789 /* update button */ 8790 8791 /* draw selectable */ 8792 8793 /* toggle behavior */ 8794 8795 /* draw selectable */ 8796 8797 /* toggle behavior */ 8798 8799 /* draw selectable */ 8800 8801 /* =============================================================== 8802 * 8803 * SLIDER 8804 * 8805 * ===============================================================*/ 8806 8807 /* check if visual cursor is being dragged */ 8808 8809 /* only update value if the next slider step is reached */ 8810 8811 /* slider widget state */ 8812 8813 /* select correct slider images/colors */ 8814 8815 /* calculate slider background bar */ 8816 8817 /* filled background bar style */ 8818 8819 /* draw background */ 8820 8821 /* draw slider bar */ 8822 8823 /* draw cursor */ 8824 8825 /* remove padding from slider bounds */ 8826 8827 /* optional buttons */ 8828 8829 /* decrement button */ 8830 8831 /* increment button */ 8832 8833 /* remove one cursor size to support visual cursor */ 8834 8835 /* make sure the provided values are correct */ 8836 8837 /* calculate cursor 8838 Basically you have two cursors. One for visual representation and interaction 8839 and one for updating the actual cursor value. */ 8840 8841 /* draw slider */ 8842 8843 /*state == NK_WIDGET_ROM || */ 8844 8845 /* =============================================================== 8846 * 8847 * PROGRESS 8848 * 8849 * ===============================================================*/ 8850 8851 /* set progressbar widget state */ 8852 8853 /* select correct colors/images to draw */ 8854 8855 /* draw background */ 8856 8857 /* draw cursor */ 8858 8859 /* calculate progressbar cursor */ 8860 8861 /* update progressbar */ 8862 8863 /* draw progressbar */ 8864 8865 /* =============================================================== 8866 * 8867 * SCROLLBAR 8868 * 8869 * ===============================================================*/ 8870 8871 /* update cursor by mouse dragging */ 8872 8873 /* scroll page up by click on empty space or shortcut */ 8874 8875 /* scroll page down by click on empty space or shortcut */ 8876 8877 /* update cursor by mouse scrolling */ 8878 8879 /* update cursor to the beginning */ 8880 8881 /* update cursor to the end */ 8882 8883 /* select correct colors/images to draw */ 8884 8885 /* draw background */ 8886 8887 /* draw cursor */ 8888 8889 /* optional scrollbar buttons */ 8890 8891 /* decrement button */ 8892 8893 /* increment button */ 8894 8895 /* calculate scrollbar constants */ 8896 8897 /* calculate scrollbar cursor bounds */ 8898 8899 /* calculate empty space around cursor */ 8900 8901 /* update scrollbar */ 8902 8903 /* draw scrollbar */ 8904 8905 /* scrollbar background */ 8906 8907 /* optional scrollbar buttons */ 8908 8909 /* decrement button */ 8910 8911 /* increment button */ 8912 8913 /* calculate scrollbar constants */ 8914 8915 /* calculate cursor bounds */ 8916 8917 /* calculate empty space around cursor */ 8918 8919 /* update scrollbar */ 8920 8921 /* draw scrollbar */ 8922 8923 /* =============================================================== 8924 * 8925 * TEXT EDITOR 8926 * 8927 * ===============================================================*/ 8928 /* stb_textedit.h - v1.8 - public domain - Sean Barrett */ 8929 8930 /* position of n'th character */ 8931 /* height of line */ 8932 /* first char of row, and length */ 8933 /*_ first char of previous row */ 8934 8935 /* starting x location, end x location (allows for align=right, etc) */ 8936 8937 /* position of baseline relative to previous row's baseline*/ 8938 8939 /* height of row above and below baseline */ 8940 8941 /* forward declarations */ 8942 8943 /* search rows to find one that straddles 'y' */ 8944 8945 /* below all text, return 'after' last character */ 8946 8947 /* check if it's before the beginning of the line */ 8948 8949 /* check if it's before the end of the line */ 8950 8951 /* search characters in row for one that straddles 'x' */ 8952 8953 /* shouldn't happen, but if it does, fall through to end-of-line case */ 8954 8955 /* if the last character is a newline, return that. 8956 * otherwise return 'after' the last character */ 8957 8958 /* API click: on mouse down, move the cursor to the clicked location, 8959 * and reset the selection */ 8960 8961 /* API drag: on mouse drag, move the cursor and selection endpoint 8962 * to the clicked location */ 8963 8964 /* find the x/y location of a character, and remember info about the previous 8965 * row in case we get a move-up event (for page up, we'll have to rescan) */ 8966 8967 /* if it's at the end, then find the last line -- simpler than trying to 8968 explicitly handle this case in the regular code */ 8969 8970 /* search rows to find the one that straddles character n */ 8971 8972 /* now scan to find xpos */ 8973 8974 /* make the selection/cursor state valid if client altered the string */ 8975 8976 /* if clamping forced them to be equal, move the cursor to match */ 8977 8978 /* delete characters while updating undo */ 8979 8980 /* delete the section */ 8981 8982 /* canonicalize the selection so start <= end */ 8983 8984 /* move cursor to first character of selection */ 8985 8986 /* move cursor to last character of selection */ 8987 8988 /* update selection and cursor to match each other */ 8989 8990 /* API cut: delete selection */ 8991 8992 /* implicitly clamps */ 8993 8994 /* API paste: replace existing selection with passed-in text */ 8995 8996 /* if there's a selection, the paste should delete it */ 8997 8998 /* try to insert the characters */ 8999 9000 /* remove the undo since we didn't actually insert the characters */ 9001 9002 /* don't insert a backward delete, just process the event */ 9003 9004 /* can't add newline in single-line mode */ 9005 9006 /* filter incoming text */ 9007 9008 /* implicitly clamps */ 9009 9010 /* move selection left */ 9011 9012 /* if currently there's a selection, 9013 * move cursor to start of selection */ 9014 9015 /* move selection right */ 9016 9017 /* if currently there's a selection, 9018 * move cursor to end of selection */ 9019 9020 /* on windows, up&down in single-line behave like left&right */ 9021 9022 /* compute current position of cursor point */ 9023 9024 /* now find character position down a row */ 9025 9026 /* on windows, up&down become left&right */ 9027 9028 /* compute current position of cursor point */ 9029 9030 /* can only go up if there's a previous row */ 9031 9032 /* now find character position up a row */ 9033 9034 /* discard the oldest entry in the undo list */ 9035 9036 /* if the 0th undo state has characters, clean those up */ 9037 9038 /* delete n characters from all other records */ 9039 9040 /* discard the oldest entry in the redo list--it's bad if this 9041 ever happens, but because undo & redo have to store the actual 9042 characters in different cases, the redo character buffer can 9043 fill up even though the undo buffer didn't */ 9044 9045 /* if the k'th undo state has characters, clean those up */ 9046 9047 /* delete n characters from all other records */ 9048 9049 /* any time we create a new undo record, we discard redo*/ 9050 9051 /* if we have no free records, we have to make room, 9052 * by sliding the existing records down */ 9053 9054 /* if the characters to store won't possibly fit in the buffer, 9055 * we can't undo */ 9056 9057 /* if we don't have enough free characters in the buffer, 9058 * we have to make room */ 9059 9060 /* we need to do two things: apply the undo record, and create a redo record */ 9061 9062 /* if the undo record says to delete characters, then the redo record will 9063 need to re-insert the characters that get deleted, so we need to store 9064 them. 9065 there are three cases: 9066 - there's enough room to store the characters 9067 - characters stored for *redoing* don't leave room for redo 9068 - characters stored for *undoing* don't leave room for redo 9069 if the last is true, we have to bail */ 9070 9071 /* the undo records take up too much character space; there's no space 9072 * to store the redo characters */ 9073 9074 /* there's definitely room to store the characters eventually */ 9075 9076 /* there's currently not enough room, so discard a redo record */ 9077 9078 /* should never happen: */ 9079 9080 /* now save the characters */ 9081 9082 /* now we can carry out the deletion */ 9083 9084 /* check type of recorded action: */ 9085 9086 /* easy case: was a deletion, so we need to insert n characters */ 9087 9088 /* we need to do two things: apply the redo record, and create an undo record */ 9089 9090 /* we KNOW there must be room for the undo record, because the redo record 9091 was derived from an undo record */ 9092 9093 /* the redo record requires us to delete characters, so the undo record 9094 needs to store the characters */ 9095 9096 /* now save the characters */ 9097 9098 /* easy case: need to insert n characters */ 9099 9100 /* reset the state to default */ 9101 9102 /* =============================================================== 9103 * 9104 * FILTER 9105 * 9106 * ===============================================================*/ 9107 9108 /* =============================================================== 9109 * 9110 * EDIT 9111 * 9112 * ===============================================================*/ 9113 9114 /* new line separator so draw previous line */ 9115 9116 /* selection needs to draw different background color */ 9117 9118 /* draw last line */ 9119 9120 /* visible text area calculation */ 9121 9122 /* calculate clipping rectangle */ 9123 9124 /* update edit state */ 9125 9126 /* (de)activate text editor */ 9127 9128 /* keep scroll position when re-activating edit widget */ 9129 9130 /* handle user input */ 9131 9132 /* mouse click handler */ 9133 9134 /* keyboard input */ 9135 9136 /* special case */ 9137 9138 /* text input */ 9139 9140 /* enter key handler */ 9141 9142 /* cut & copy handler */ 9143 9144 /* paste handler */ 9145 9146 /* tab handler */ 9147 9148 /* set widget state */ 9149 9150 /* DRAW EDIT */ 9151 9152 /* select background colors/images */ 9153 9154 /* draw background frame */ 9155 9156 /* text pointer positions */ 9157 9158 /* 2D pixel positions */ 9159 9160 /* calculate total line count + total space + cursor/selection position */ 9161 9162 /* utf8 encoding */ 9163 9164 /* iterate all lines */ 9165 9166 /* set cursor 2D position and line */ 9167 9168 /* calculate 2d position */ 9169 9170 /* set start selection 2D position and line */ 9171 9172 /* calculate 2d position */ 9173 9174 /* set end selection 2D position and line */ 9175 9176 /* calculate 2d position */ 9177 9178 /* handle case when cursor is at end of text buffer */ 9179 9180 /* scrollbar */ 9181 9182 /* update scrollbar to follow cursor */ 9183 9184 /* horizontal scroll */ 9185 9186 /* vertical scroll */ 9187 9188 /* scrollbar widget */ 9189 9190 /* draw text */ 9191 9192 /* select correct colors to draw */ 9193 9194 /* no selection so just draw the complete text */ 9195 9196 /* edit has selection so draw 1-3 text chunks */ 9197 9198 /* draw unselected text before selection */ 9199 9200 /* draw selected text */ 9201 9202 /* draw unselected text after selected text */ 9203 9204 /* cursor */ 9205 9206 /* draw cursor at end of line */ 9207 9208 /* draw cursor inside text */ 9209 9210 /* not active so just draw text */ 9211 9212 /* make sure correct values */ 9213 9214 /* check if edit is currently hot item */ 9215 9216 /* current edit is now hot */ 9217 9218 /* current edit is now cold */ 9219 9220 /* =============================================================== 9221 * 9222 * PROPERTY 9223 * 9224 * ===============================================================*/ 9225 9226 /* select correct background and text color */ 9227 9228 /* draw background */ 9229 9230 /* draw label */ 9231 9232 /* left decrement button */ 9233 9234 /* text label */ 9235 9236 /* right increment button */ 9237 9238 /* edit */ 9239 9240 /* empty left space activator */ 9241 9242 /* update property */ 9243 9244 /* draw property */ 9245 9246 /* execute right button */ 9247 9248 /* execute left button */ 9249 9250 /* property has been activated so setup buffer */ 9251 9252 /* execute and run text edit field */ 9253 9254 /* property is now not active so convert edit text to value*/ 9255 9256 /* calculate hash from name */ 9257 9258 /* special number hash */ 9259 9260 /* check if property is currently hot item */ 9261 9262 /* execute property widget */ 9263 9264 /* current property is now hot */ 9265 9266 /* check if previously active property is now inactive */ 9267 9268 /* ============================================================== 9269 * 9270 * CHART 9271 * 9272 * ===============================================================*/ 9273 9274 /* setup basic generic chart */ 9275 9276 /* add first slot into chart */ 9277 9278 /* draw chart background */ 9279 9280 /* add another slot into the graph */ 9281 9282 /* first data point does not have a connection */ 9283 9284 /* draw a line between the last data point and the new one */ 9285 9286 /* user selection of current data point */ 9287 9288 /* save current data point position */ 9289 9290 /* calculate bounds of current bar chart entry */ 9291 9292 /* user chart bar selection */ 9293 9294 /* ============================================================== 9295 * 9296 * COLOR PICKER 9297 * 9298 * ===============================================================*/ 9299 9300 /* color matrix */ 9301 9302 /* hue bar */ 9303 9304 /* alpha bar */ 9305 9306 /* set color picker widget state */ 9307 9308 /* draw hue bar */ 9309 9310 /* draw alpha bar */ 9311 9312 /* draw color matrix */ 9313 9314 /* draw cross-hair */ 9315 9316 /* ============================================================== 9317 * 9318 * COMBO 9319 * 9320 * ===============================================================*/ 9321 9322 /* draw combo box header background and border */ 9323 9324 /* print currently selected text item */ 9325 9326 /* represents whether or not the combo's button symbol should be drawn */ 9327 9328 /* calculate button */ 9329 9330 /* draw selected label */ 9331 9332 /* draw open/close button */ 9333 9334 /* draw combo box header background and border */ 9335 9336 /* represents whether or not the combo's button symbol should be drawn */ 9337 9338 /* calculate button */ 9339 9340 /* draw color */ 9341 9342 /* draw open/close button */ 9343 9344 /* draw combo box header background and border */ 9345 9346 /* calculate button */ 9347 9348 /* draw symbol */ 9349 9350 /* draw open/close button */ 9351 9352 /* draw combo box header background and border */ 9353 9354 /* calculate button */ 9355 9356 /* draw symbol */ 9357 9358 /* draw label */ 9359 9360 /* draw combo box header background and border */ 9361 9362 /* represents whether or not the combo's button symbol should be drawn */ 9363 9364 /* calculate button */ 9365 9366 /* draw image */ 9367 9368 /* draw open/close button */ 9369 9370 /* draw combo box header background and border */ 9371 9372 /* represents whether or not the combo's button symbol should be drawn */ 9373 9374 /* calculate button */ 9375 9376 /* draw image */ 9377 9378 /* draw label */ 9379 9380 /* calculate popup window */ 9381 9382 /* find selected item */ 9383 9384 /* calculate popup window */ 9385 9386 /* =============================================================== 9387 * 9388 * TOOLTIP 9389 * 9390 * ===============================================================*/ 9391 9392 /* make sure that no nonblocking popup is currently active */ 9393 9394 /* fetch configuration data */ 9395 9396 /* calculate size of the text and tooltip */ 9397 9398 /* execute tooltip and fill with text */ 9399 9400 /* NK_IMPLEMENTATION */ 9401 9402 /* 9403 /// ## License 9404 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~none 9405 /// ------------------------------------------------------------------------------ 9406 /// This software is available under 2 licenses -- choose whichever you prefer. 9407 /// ------------------------------------------------------------------------------ 9408 /// ALTERNATIVE A - MIT License 9409 /// Copyright (c) 2016-2018 Micha Mettke 9410 /// Permission is hereby granted, free of charge, to any person obtaining a copy of 9411 /// this software and associated documentation files (the "Software"), to deal in 9412 /// the Software without restriction, including without limitation the rights to 9413 /// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9414 /// of the Software, and to permit persons to whom the Software is furnished to do 9415 /// so, subject to the following conditions: 9416 /// The above copyright notice and this permission notice shall be included in all 9417 /// copies or substantial portions of the Software. 9418 /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 9419 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 9420 /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 9421 /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 9422 /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 9423 /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 9424 /// SOFTWARE. 9425 /// ------------------------------------------------------------------------------ 9426 /// ALTERNATIVE B - Public Domain (www.unlicense.org) 9427 /// This is free and unencumbered software released into the public domain. 9428 /// Anyone is free to copy, modify, publish, use, compile, sell, or distribute this 9429 /// software, either in source code form or as a compiled binary, for any purpose, 9430 /// commercial or non-commercial, and by any means. 9431 /// In jurisdictions that recognize copyright laws, the author or authors of this 9432 /// software dedicate any and all copyright interest in the software to the public 9433 /// domain. We make this dedication for the benefit of the public at large and to 9434 /// the detriment of our heirs and successors. We intend this dedication to be an 9435 /// overt act of relinquishment in perpetuity of all present and future rights to 9436 /// this software under copyright law. 9437 /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 9438 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 9439 /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 9440 /// AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 9441 /// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 9442 /// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9443 /// ------------------------------------------------------------------------------ 9444 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9445 9446 /// ## Changelog 9447 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~none 9448 /// [date] ([x.y.z]) - [description] 9449 /// - [date]: date on which the change has been pushed 9450 /// - [x.y.z]: Version string, represented in Semantic Versioning format 9451 /// - [x]: Major version with API and library breaking changes 9452 /// - [y]: Minor version with non-breaking API and library changes 9453 /// - [z]: Patch version with no direct changes to the API 9454 /// 9455 /// - 2022/08/28 (4.10.3) - Renamed the `null` texture variable to `tex_null` 9456 /// - 2022/08/01 (4.10.2) - Fix Apple Silicon with incorrect NK_SITE_TYPE and NK_POINTER_TYPE 9457 /// - 2022/08/01 (4.10.1) - Fix cursor jumping back to beginning of text when typing more than 9458 /// nk_edit_xxx limit 9459 /// - 2022/05/27 (4.10.0) - Add nk_input_has_mouse_click_in_button_rect() to fix window move bug 9460 /// - 2022/04/18 (4.9.7) - Change button behavior when NK_BUTTON_TRIGGER_ON_RELEASE is defined to 9461 /// only trigger when the mouse position was inside the same button on down 9462 /// - 2022/02/03 (4.9.6) - Allow overriding the NK_INV_SQRT function, similar to NK_SIN and NK_COS 9463 /// - 2021/12/22 (4.9.5) - Revert layout bounds not accounting for padding due to regressions 9464 /// - 2021/12/22 (4.9.4) - Fix checking hovering when window is minimized 9465 /// - 2021/12/22 (4.09.3) - Fix layout bounds not accounting for padding 9466 /// - 2021/12/19 (4.09.2) - Update to stb_rect_pack.h v1.01 and stb_truetype.h v1.26 9467 /// - 2021/12/16 (4.09.1) - Fix the majority of GCC warnings 9468 /// - 2021/10/16 (4.09.0) - Added nk_spacer() widget 9469 /// - 2021/09/22 (4.08.6) - Fix "may be used uninitialized" warnings in nk_widget 9470 /// - 2021/09/22 (4.08.5) - GCC __builtin_offsetof only exists in version 4 and later 9471 /// - 2021/09/15 (4.08.4) - Fix "'num_len' may be used uninitialized" in nk_do_property 9472 /// - 2021/09/15 (4.08.3) - Fix "Templates cannot be declared to have 'C' Linkage" 9473 /// - 2021/09/08 (4.08.2) - Fix warnings in C89 builds 9474 /// - 2021/09/08 (4.08.1) - Use compiler builtins for NK_OFFSETOF when possible 9475 /// - 2021/08/17 (4.08.0) - Implemented 9-slice scaling support for widget styles 9476 /// - 2021/08/16 (4.07.5) - Replace usage of memset in nk_font_atlas_bake with NK_MEMSET 9477 /// - 2021/08/15 (4.07.4) - Fix conversion and sign conversion warnings 9478 /// - 2021/08/08 (4.07.3) - Fix crash when baking merged fonts 9479 /// - 2021/08/08 (4.07.2) - Fix Multiline Edit wrong offset 9480 /// - 2021/03/17 (4.07.1) - Fix warning about unused parameter 9481 /// - 2021/03/17 (4.07.0) - Fix nk_property hover bug 9482 /// - 2021/03/15 (4.06.4) - Change nk_propertyi back to int 9483 /// - 2021/03/15 (4.06.3) - Update documentation for functions that now return nk_bool 9484 /// - 2020/12/19 (4.06.2) - Fix additional C++ style comments which are not allowed in ISO C90. 9485 /// - 2020/10/11 (4.06.1) - Fix C++ style comments which are not allowed in ISO C90. 9486 /// - 2020/10/07 (4.06.0) - Fix nk_combo return type wrongly changed to nk_bool 9487 /// - 2020/09/05 (4.05.0) - Use the nk_font_atlas allocator for stb_truetype memory management. 9488 /// - 2020/09/04 (4.04.1) - Replace every boolean int by nk_bool 9489 /// - 2020/09/04 (4.04.0) - Add nk_bool with NK_INCLUDE_STANDARD_BOOL 9490 /// - 2020/06/13 (4.03.1) - Fix nk_pool allocation sizes. 9491 /// - 2020/06/04 (4.03.0) - Made nk_combo header symbols optional. 9492 /// - 2020/05/27 (4.02.5) - Fix nk_do_edit: Keep scroll position when re-activating edit widget. 9493 /// - 2020/05/09 (4.02.4) - Fix nk_menubar height calculation bug 9494 /// - 2020/05/08 (4.02.3) - Fix missing stdarg.h with NK_INCLUDE_STANDARD_VARARGS 9495 /// - 2020/04/30 (4.02.2) - Fix nk_edit border drawing bug 9496 /// - 2020/04/09 (4.02.1) - Removed unused nk_sqrt function to fix compiler warnings 9497 /// - Fixed compiler warnings if you bring your own methods for 9498 /// nk_cos/nk_sin/nk_strtod/nk_memset/nk_memcopy/nk_dtoa 9499 /// - 2020/04/06 (4.01.10) - Fix bug: Do not use pool before checking for NULL 9500 /// - 2020/03/22 (4.01.9) - Fix bug where layout state wasn't restored correctly after 9501 /// popping a tree. 9502 /// - 2020/03/11 (4.01.8) - Fix bug where padding is subtracted from widget 9503 /// - 2020/03/06 (4.01.7) - Fix bug where width padding was applied twice 9504 /// - 2020/02/06 (4.01.6) - Update stb_truetype.h and stb_rect_pack.h and separate them 9505 /// - 2019/12/10 (4.01.5) - Fix off-by-one error in NK_INTERSECT 9506 /// - 2019/10/09 (4.01.4) - Fix bug for autoscrolling in nk_do_edit 9507 /// - 2019/09/20 (4.01.3) - Fixed a bug wherein combobox cannot be closed by clicking the header 9508 /// when NK_BUTTON_TRIGGER_ON_RELEASE is defined. 9509 /// - 2019/09/10 (4.01.2) - Fixed the nk_cos function, which deviated significantly. 9510 /// - 2019/09/08 (4.01.1) - Fixed a bug wherein re-baking of fonts caused a segmentation 9511 /// fault due to dst_font->glyph_count not being zeroed on subsequent 9512 /// bakes of the same set of fonts. 9513 /// - 2019/06/23 (4.01.0) - Added nk_***_get_scroll and nk_***_set_scroll for groups, windows, and popups. 9514 /// - 2019/06/12 (4.00.3) - Fix panel background drawing bug. 9515 /// - 2018/10/31 (4.00.2) - Added NK_KEYSTATE_BASED_INPUT to "fix" state based backends 9516 /// like GLFW without breaking key repeat behavior on event based. 9517 /// - 2018/04/01 (4.00.1) - Fixed calling `nk_convert` multiple time per single frame. 9518 /// - 2018/04/01 (4.00.0) - BREAKING CHANGE: nk_draw_list_clear no longer tries to 9519 /// clear provided buffers. So make sure to either free 9520 /// or clear each passed buffer after calling nk_convert. 9521 /// - 2018/02/23 (3.00.6) - Fixed slider dragging behavior. 9522 /// - 2018/01/31 (3.00.5) - Fixed overcalculation of cursor data in font baking process. 9523 /// - 2018/01/31 (3.00.4) - Removed name collision with stb_truetype. 9524 /// - 2018/01/28 (3.00.3) - Fixed panel window border drawing bug. 9525 /// - 2018/01/12 (3.00.2) - Added `nk_group_begin_titled` for separated group identifier and title. 9526 /// - 2018/01/07 (3.00.1) - Started to change documentation style. 9527 /// - 2018/01/05 (3.00.0) - BREAKING CHANGE: The previous color picker API was broken 9528 /// because of conversions between float and byte color representation. 9529 /// Color pickers now use floating point values to represent 9530 /// HSV values. To get back the old behavior I added some additional 9531 /// color conversion functions to cast between nk_color and 9532 /// nk_colorf. 9533 /// - 2017/12/23 (2.00.7) - Fixed small warning. 9534 /// - 2017/12/23 (2.00.7) - Fixed `nk_edit_buffer` behavior if activated to allow input. 9535 /// - 2017/12/23 (2.00.7) - Fixed modifyable progressbar dragging visuals and input behavior. 9536 /// - 2017/12/04 (2.00.6) - Added formatted string tooltip widget. 9537 /// - 2017/11/18 (2.00.5) - Fixed window becoming hidden with flag `NK_WINDOW_NO_INPUT`. 9538 /// - 2017/11/15 (2.00.4) - Fixed font merging. 9539 /// - 2017/11/07 (2.00.3) - Fixed window size and position modifier functions. 9540 /// - 2017/09/14 (2.00.2) - Fixed `nk_edit_buffer` and `nk_edit_focus` behavior. 9541 /// - 2017/09/14 (2.00.1) - Fixed window closing behavior. 9542 /// - 2017/09/14 (2.00.0) - BREAKING CHANGE: Modifying window position and size functions now 9543 /// require the name of the window and must happen outside the window 9544 /// building process (between function call nk_begin and nk_end). 9545 /// - 2017/09/11 (1.40.9) - Fixed window background flag if background window is declared last. 9546 /// - 2017/08/27 (1.40.8) - Fixed `nk_item_is_any_active` for hidden windows. 9547 /// - 2017/08/27 (1.40.7) - Fixed window background flag. 9548 /// - 2017/07/07 (1.40.6) - Fixed missing clipping rect check for hovering/clicked 9549 /// query for widgets. 9550 /// - 2017/07/07 (1.40.5) - Fixed drawing bug for vertex output for lines and stroked 9551 /// and filled rectangles. 9552 /// - 2017/07/07 (1.40.4) - Fixed bug in nk_convert trying to add windows that are in 9553 /// process of being destroyed. 9554 /// - 2017/07/07 (1.40.3) - Fixed table internal bug caused by storing table size in 9555 /// window instead of directly in table. 9556 /// - 2017/06/30 (1.40.2) - Removed unneeded semicolon in C++ NK_ALIGNOF macro. 9557 /// - 2017/06/30 (1.40.1) - Fixed drawing lines smaller or equal zero. 9558 /// - 2017/06/08 (1.40.0) - Removed the breaking part of last commit. Auto layout now only 9559 /// comes in effect if you pass in zero was row height argument. 9560 /// - 2017/06/08 (1.40.0) - BREAKING CHANGE: while not directly API breaking it will change 9561 /// how layouting works. From now there will be an internal minimum 9562 /// row height derived from font height. If you need a row smaller than 9563 /// that you can directly set it by `nk_layout_set_min_row_height` and 9564 /// reset the value back by calling `nk_layout_reset_min_row_height. 9565 /// - 2017/06/08 (1.39.1) - Fixed property text edit handling bug caused by past `nk_widget` fix. 9566 /// - 2017/06/08 (1.39.0) - Added function to retrieve window space without calling a `nk_layout_xxx` function. 9567 /// - 2017/06/06 (1.38.5) - Fixed `nk_convert` return flag for command buffer. 9568 /// - 2017/05/23 (1.38.4) - Fixed activation behavior for widgets partially clipped. 9569 /// - 2017/05/10 (1.38.3) - Fixed wrong min window size mouse scaling over boundaries. 9570 /// - 2017/05/09 (1.38.2) - Fixed vertical scrollbar drawing with not enough space. 9571 /// - 2017/05/09 (1.38.1) - Fixed scaler dragging behavior if window size hits minimum size. 9572 /// - 2017/05/06 (1.38.0) - Added platform double-click support. 9573 /// - 2017/04/20 (1.37.1) - Fixed key repeat found inside glfw demo backends. 9574 /// - 2017/04/20 (1.37.0) - Extended properties with selection and clipboard support. 9575 /// - 2017/04/20 (1.36.2) - Fixed #405 overlapping rows with zero padding and spacing. 9576 /// - 2017/04/09 (1.36.1) - Fixed #403 with another widget float error. 9577 /// - 2017/04/09 (1.36.0) - Added window `NK_WINDOW_NO_INPUT` and `NK_WINDOW_NOT_INTERACTIVE` flags. 9578 /// - 2017/04/09 (1.35.3) - Fixed buffer heap corruption. 9579 /// - 2017/03/25 (1.35.2) - Fixed popup overlapping for `NK_WINDOW_BACKGROUND` windows. 9580 /// - 2017/03/25 (1.35.1) - Fixed windows closing behavior. 9581 /// - 2017/03/18 (1.35.0) - Added horizontal scroll requested in #377. 9582 /// - 2017/03/18 (1.34.3) - Fixed long window header titles. 9583 /// - 2017/03/04 (1.34.2) - Fixed text edit filtering. 9584 /// - 2017/03/04 (1.34.1) - Fixed group closable flag. 9585 /// - 2017/02/25 (1.34.0) - Added custom draw command for better language binding support. 9586 /// - 2017/01/24 (1.33.0) - Added programmatic way to remove edit focus. 9587 /// - 2017/01/24 (1.32.3) - Fixed wrong define for basic type definitions for windows. 9588 /// - 2017/01/21 (1.32.2) - Fixed input capture from hidden or closed windows. 9589 /// - 2017/01/21 (1.32.1) - Fixed slider behavior and drawing. 9590 /// - 2017/01/13 (1.32.0) - Added flag to put scaler into the bottom left corner. 9591 /// - 2017/01/13 (1.31.0) - Added additional row layouting method to combine both 9592 /// dynamic and static widgets. 9593 /// - 2016/12/31 (1.30.0) - Extended scrollbar offset from 16-bit to 32-bit. 9594 /// - 2016/12/31 (1.29.2) - Fixed closing window bug of minimized windows. 9595 /// - 2016/12/03 (1.29.1) - Fixed wrapped text with no seperator and C89 error. 9596 /// - 2016/12/03 (1.29.0) - Changed text wrapping to process words not characters. 9597 /// - 2016/11/22 (1.28.6) - Fixed window minimized closing bug. 9598 /// - 2016/11/19 (1.28.5) - Fixed abstract combo box closing behavior. 9599 /// - 2016/11/19 (1.28.4) - Fixed tooltip flickering. 9600 /// - 2016/11/19 (1.28.3) - Fixed memory leak caused by popup repeated closing. 9601 /// - 2016/11/18 (1.28.2) - Fixed memory leak caused by popup panel allocation. 9602 /// - 2016/11/10 (1.28.1) - Fixed some warnings and C++ error. 9603 /// - 2016/11/10 (1.28.0) - Added additional `nk_button` versions which allows to directly 9604 /// pass in a style struct to change buttons visual. 9605 /// - 2016/11/10 (1.27.0) - Added additional `nk_tree` versions to support external state 9606 /// storage. Just like last the `nk_group` commit the main 9607 /// advantage is that you optionally can minimize nuklears runtime 9608 /// memory consumption or handle hash collisions. 9609 /// - 2016/11/09 (1.26.0) - Added additional `nk_group` version to support external scrollbar 9610 /// offset storage. Main advantage is that you can externalize 9611 /// the memory management for the offset. It could also be helpful 9612 /// if you have a hash collision in `nk_group_begin` but really 9613 /// want the name. In addition I added `nk_list_view` which allows 9614 /// to draw big lists inside a group without actually having to 9615 /// commit the whole list to nuklear (issue #269). 9616 /// - 2016/10/30 (1.25.1) - Fixed clipping rectangle bug inside `nk_draw_list`. 9617 /// - 2016/10/29 (1.25.0) - Pulled `nk_panel` memory management into nuklear and out of 9618 /// the hands of the user. From now on users don't have to care 9619 /// about panels unless they care about some information. If you 9620 /// still need the panel just call `nk_window_get_panel`. 9621 /// - 2016/10/21 (1.24.0) - Changed widget border drawing to stroked rectangle from filled 9622 /// rectangle for less overdraw and widget background transparency. 9623 /// - 2016/10/18 (1.23.0) - Added `nk_edit_focus` for manually edit widget focus control. 9624 /// - 2016/09/29 (1.22.7) - Fixed deduction of basic type in non `<stdint.h>` compilation. 9625 /// - 2016/09/29 (1.22.6) - Fixed edit widget UTF-8 text cursor drawing bug. 9626 /// - 2016/09/28 (1.22.5) - Fixed edit widget UTF-8 text appending/inserting/removing. 9627 /// - 2016/09/28 (1.22.4) - Fixed drawing bug inside edit widgets which offset all text 9628 /// text in every edit widget if one of them is scrolled. 9629 /// - 2016/09/28 (1.22.3) - Fixed small bug in edit widgets if not active. The wrong 9630 /// text length is passed. It should have been in bytes but 9631 /// was passed as glyphs. 9632 /// - 2016/09/20 (1.22.2) - Fixed color button size calculation. 9633 /// - 2016/09/20 (1.22.1) - Fixed some `nk_vsnprintf` behavior bugs and removed `<stdio.h>` 9634 /// again from `NK_INCLUDE_STANDARD_VARARGS`. 9635 /// - 2016/09/18 (1.22.0) - C89 does not support vsnprintf only C99 and newer as well 9636 /// as C++11 and newer. In addition to use vsnprintf you have 9637 /// to include <stdio.h>. So just defining `NK_INCLUDE_STD_VAR_ARGS` 9638 /// is not enough. That behavior is now fixed. By default if 9639 /// both varargs as well as stdio is selected I try to use 9640 /// vsnprintf if not possible I will revert to vsprintf. If 9641 /// varargs but not stdio was defined I will use my own function. 9642 /// - 2016/09/15 (1.21.2) - Fixed panel `close` behavior for deeper panel levels. 9643 /// - 2016/09/15 (1.21.1) - Fixed C++ errors and wrong argument to `nk_panel_get_xxxx`. 9644 /// - 2016/09/13 (1.21.0) - !BREAKING! Fixed nonblocking popup behavior in menu, combo, 9645 /// and contextual which prevented closing in y-direction if 9646 /// popup did not reach max height. 9647 /// In addition the height parameter was changed into vec2 9648 /// for width and height to have more control over the popup size. 9649 /// - 2016/09/13 (1.20.3) - Cleaned up and extended type selection. 9650 /// - 2016/09/13 (1.20.2) - Fixed slider behavior hopefully for the last time. This time 9651 /// all calculation are correct so no more hackery. 9652 /// - 2016/09/13 (1.20.1) - Internal change to divide window/panel flags into panel flags and types. 9653 /// Suprisinly spend years in C and still happened to confuse types 9654 /// with flags. Probably something to take note. 9655 /// - 2016/09/08 (1.20.0) - Added additional helper function to make it easier to just 9656 /// take the produced buffers from `nk_convert` and unplug the 9657 /// iteration process from `nk_context`. So now you can 9658 /// just use the vertex,element and command buffer + two pointer 9659 /// inside the command buffer retrieved by calls `nk__draw_begin` 9660 /// and `nk__draw_end` and macro `nk_draw_foreach_bounded`. 9661 /// - 2016/09/08 (1.19.0) - Added additional asserts to make sure every `nk_xxx_begin` call 9662 /// for windows, popups, combobox, menu and contextual is guarded by 9663 /// `if` condition and does not produce false drawing output. 9664 /// - 2016/09/08 (1.18.0) - Changed confusing name for `NK_SYMBOL_RECT_FILLED`, `NK_SYMBOL_RECT` 9665 /// to hopefully easier to understand `NK_SYMBOL_RECT_FILLED` and 9666 /// `NK_SYMBOL_RECT_OUTLINE`. 9667 /// - 2016/09/08 (1.17.0) - Changed confusing name for `NK_SYMBOL_CIRLCE_FILLED`, `NK_SYMBOL_CIRCLE` 9668 /// to hopefully easier to understand `NK_SYMBOL_CIRCLE_FILLED` and 9669 /// `NK_SYMBOL_CIRCLE_OUTLINE`. 9670 /// - 2016/09/08 (1.16.0) - Added additional checks to select correct types if `NK_INCLUDE_FIXED_TYPES` 9671 /// is not defined by supporting the biggest compiler GCC, clang and MSVC. 9672 /// - 2016/09/07 (1.15.3) - Fixed `NK_INCLUDE_COMMAND_USERDATA` define to not cause an error. 9673 /// - 2016/09/04 (1.15.2) - Fixed wrong combobox height calculation. 9674 /// - 2016/09/03 (1.15.1) - Fixed gaps inside combo boxes in OpenGL. 9675 /// - 2016/09/02 (1.15.0) - Changed nuklear to not have any default vertex layout and 9676 /// instead made it user provided. The range of types to convert 9677 /// to is quite limited at the moment, but I would be more than 9678 /// happy to accept PRs to add additional. 9679 /// - 2016/08/30 (1.14.2) - Removed unused variables. 9680 /// - 2016/08/30 (1.14.1) - Fixed C++ build errors. 9681 /// - 2016/08/30 (1.14.0) - Removed mouse dragging from SDL demo since it does not work correctly. 9682 /// - 2016/08/30 (1.13.4) - Tweaked some default styling variables. 9683 /// - 2016/08/30 (1.13.3) - Hopefully fixed drawing bug in slider, in general I would 9684 /// refrain from using slider with a big number of steps. 9685 /// - 2016/08/30 (1.13.2) - Fixed close and minimize button which would fire even if the 9686 /// window was in Read Only Mode. 9687 /// - 2016/08/30 (1.13.1) - Fixed popup panel padding handling which was previously just 9688 /// a hack for combo box and menu. 9689 /// - 2016/08/30 (1.13.0) - Removed `NK_WINDOW_DYNAMIC` flag from public API since 9690 /// it is bugged and causes issues in window selection. 9691 /// - 2016/08/30 (1.12.0) - Removed scaler size. The size of the scaler is now 9692 /// determined by the scrollbar size. 9693 /// - 2016/08/30 (1.11.2) - Fixed some drawing bugs caused by changes from 1.11.0. 9694 /// - 2016/08/30 (1.11.1) - Fixed overlapping minimized window selection. 9695 /// - 2016/08/30 (1.11.0) - Removed some internal complexity and overly complex code 9696 /// handling panel padding and panel border. 9697 /// - 2016/08/29 (1.10.0) - Added additional height parameter to `nk_combobox_xxx`. 9698 /// - 2016/08/29 (1.10.0) - Fixed drawing bug in dynamic popups. 9699 /// - 2016/08/29 (1.10.0) - Added experimental mouse scrolling to popups, menus and comboboxes. 9700 /// - 2016/08/26 (1.10.0) - Added window name string prepresentation to account for 9701 /// hash collisions. Currently limited to `NK_WINDOW_MAX_NAME` 9702 /// which in term can be redefined if not big enough. 9703 /// - 2016/08/26 (1.10.0) - Added stacks for temporary style/UI changes in code. 9704 /// - 2016/08/25 (1.10.0) - Changed `nk_input_is_key_pressed` and 'nk_input_is_key_released' 9705 /// to account for key press and release happening in one frame. 9706 /// - 2016/08/25 (1.10.0) - Added additional nk_edit flag to directly jump to the end on activate. 9707 /// - 2016/08/17 (1.09.6) - Removed invalid check for value zero in `nk_propertyx`. 9708 /// - 2016/08/16 (1.09.5) - Fixed ROM mode for deeper levels of popup windows parents. 9709 /// - 2016/08/15 (1.09.4) - Editbox are now still active if enter was pressed with flag 9710 /// `NK_EDIT_SIG_ENTER`. Main reasoning is to be able to keep 9711 /// typing after committing. 9712 /// - 2016/08/15 (1.09.4) - Removed redundant code. 9713 /// - 2016/08/15 (1.09.4) - Fixed negative numbers in `nk_strtoi` and remove unused variable. 9714 /// - 2016/08/15 (1.09.3) - Fixed `NK_WINDOW_BACKGROUND` flag behavior to select a background 9715 /// window only as selected by hovering and not by clicking. 9716 /// - 2016/08/14 (1.09.2) - Fixed a bug in font atlas which caused wrong loading 9717 /// of glyphs for font with multiple ranges. 9718 /// - 2016/08/12 (1.09.1) - Added additional function to check if window is currently 9719 /// hidden and therefore not visible. 9720 /// - 2016/08/12 (1.09.1) - nk_window_is_closed now queries the correct flag `NK_WINDOW_CLOSED` 9721 /// instead of the old flag `NK_WINDOW_HIDDEN`. 9722 /// - 2016/08/09 (1.09.0) - Added additional double version to nk_property and changed 9723 /// the underlying implementation to not cast to float and instead 9724 /// work directly on the given values. 9725 /// - 2016/08/09 (1.08.0) - Added additional define to overwrite library internal 9726 /// floating pointer number to string conversion for additional 9727 /// precision. 9728 /// - 2016/08/09 (1.08.0) - Added additional define to overwrite library internal 9729 /// string to floating point number conversion for additional 9730 /// precision. 9731 /// - 2016/08/08 (1.07.2) - Fixed compiling error without define `NK_INCLUDE_FIXED_TYPE`. 9732 /// - 2016/08/08 (1.07.1) - Fixed possible floating point error inside `nk_widget` leading 9733 /// to wrong wiget width calculation which results in widgets falsely 9734 /// becoming tagged as not inside window and cannot be accessed. 9735 /// - 2016/08/08 (1.07.0) - Nuklear now differentiates between hiding a window (NK_WINDOW_HIDDEN) and 9736 /// closing a window (NK_WINDOW_CLOSED). A window can be hidden/shown 9737 /// by using `nk_window_show` and closed by either clicking the close 9738 /// icon in a window or by calling `nk_window_close`. Only closed 9739 /// windows get removed at the end of the frame while hidden windows 9740 /// remain. 9741 /// - 2016/08/08 (1.06.0) - Added `nk_edit_string_zero_terminated` as a second option to 9742 /// `nk_edit_string` which takes, edits and outputs a '\0' terminated string. 9743 /// - 2016/08/08 (1.05.4) - Fixed scrollbar auto hiding behavior. 9744 /// - 2016/08/08 (1.05.3) - Fixed wrong panel padding selection in `nk_layout_widget_space`. 9745 /// - 2016/08/07 (1.05.2) - Fixed old bug in dynamic immediate mode layout API, calculating 9746 /// wrong item spacing and panel width. 9747 /// - 2016/08/07 (1.05.1) - Hopefully finally fixed combobox popup drawing bug. 9748 /// - 2016/08/07 (1.05.0) - Split varargs away from `NK_INCLUDE_STANDARD_IO` into own 9749 /// define `NK_INCLUDE_STANDARD_VARARGS` to allow more fine 9750 /// grained controlled over library includes. 9751 /// - 2016/08/06 (1.04.5) - Changed memset calls to `NK_MEMSET`. 9752 /// - 2016/08/04 (1.04.4) - Fixed fast window scaling behavior. 9753 /// - 2016/08/04 (1.04.3) - Fixed window scaling, movement bug which appears if you 9754 /// move/scale a window and another window is behind it. 9755 /// If you are fast enough then the window behind gets activated 9756 /// and the operation is blocked. I now require activating 9757 /// by hovering only if mouse is not pressed. 9758 /// - 2016/08/04 (1.04.2) - Fixed changing fonts. 9759 /// - 2016/08/03 (1.04.1) - Fixed `NK_WINDOW_BACKGROUND` behavior. 9760 /// - 2016/08/03 (1.04.0) - Added color parameter to `nk_draw_image`. 9761 /// - 2016/08/03 (1.04.0) - Added additional window padding style attributes for 9762 /// sub windows (combo, menu, ...). 9763 /// - 2016/08/03 (1.04.0) - Added functions to show/hide software cursor. 9764 /// - 2016/08/03 (1.04.0) - Added `NK_WINDOW_BACKGROUND` flag to force a window 9765 /// to be always in the background of the screen. 9766 /// - 2016/08/03 (1.03.2) - Removed invalid assert macro for NK_RGB color picker. 9767 /// - 2016/08/01 (1.03.1) - Added helper macros into header include guard. 9768 /// - 2016/07/29 (1.03.0) - Moved the window/table pool into the header part to 9769 /// simplify memory management by removing the need to 9770 /// allocate the pool. 9771 /// - 2016/07/29 (1.02.0) - Added auto scrollbar hiding window flag which if enabled 9772 /// will hide the window scrollbar after NK_SCROLLBAR_HIDING_TIMEOUT 9773 /// seconds without window interaction. To make it work 9774 /// you have to also set a delta time inside the `nk_context`. 9775 /// - 2016/07/25 (1.01.1) - Fixed small panel and panel border drawing bugs. 9776 /// - 2016/07/15 (1.01.0) - Added software cursor to `nk_style` and `nk_context`. 9777 /// - 2016/07/15 (1.01.0) - Added const correctness to `nk_buffer_push' data argument. 9778 /// - 2016/07/15 (1.01.0) - Removed internal font baking API and simplified 9779 /// font atlas memory management by converting pointer 9780 /// arrays for fonts and font configurations to lists. 9781 /// - 2016/07/15 (1.00.0) - Changed button API to use context dependent button 9782 /// behavior instead of passing it for every function call. 9783 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 9784 /// ## Gallery 9785 /// ![Figure [blue]: Feature overview with blue color styling](https://cloud.githubusercontent.com/assets/8057201/13538240/acd96876-e249-11e5-9547-5ac0b19667a0.png) 9786 /// ![Figure [red]: Feature overview with red color styling](https://cloud.githubusercontent.com/assets/8057201/13538243/b04acd4c-e249-11e5-8fd2-ad7744a5b446.png) 9787 /// ![Figure [widgets]: Widget overview](https://cloud.githubusercontent.com/assets/8057201/11282359/3325e3c6-8eff-11e5-86cb-cf02b0596087.png) 9788 /// ![Figure [blackwhite]: Black and white](https://cloud.githubusercontent.com/assets/8057201/11033668/59ab5d04-86e5-11e5-8091-c56f16411565.png) 9789 /// ![Figure [filexp]: File explorer](https://cloud.githubusercontent.com/assets/8057201/10718115/02a9ba08-7b6b-11e5-950f-adacdd637739.png) 9790 /// ![Figure [opengl]: OpenGL Editor](https://cloud.githubusercontent.com/assets/8057201/12779619/2a20d72c-ca69-11e5-95fe-4edecf820d5c.png) 9791 /// ![Figure [nodedit]: Node Editor](https://cloud.githubusercontent.com/assets/8057201/9976995/e81ac04a-5ef7-11e5-872b-acd54fbeee03.gif) 9792 /// ![Figure [skinning]: Using skinning in Nuklear](https://cloud.githubusercontent.com/assets/8057201/15991632/76494854-30b8-11e6-9555-a69840d0d50b.png) 9793 /// ![Figure [bf]: Heavy modified version](https://cloud.githubusercontent.com/assets/8057201/14902576/339926a8-0d9c-11e6-9fee-a8b73af04473.png) 9794 /// 9795 /// ## Credits 9796 /// Developed by Micha Mettke and every direct or indirect github contributor. <br /><br /> 9797 /// 9798 /// Embeds [stb_texedit](https://github.com/nothings/stb/blob/master/stb_textedit.h), [stb_truetype](https://github.com/nothings/stb/blob/master/stb_truetype.h) and [stb_rectpack](https://github.com/nothings/stb/blob/master/stb_rect_pack.h) by Sean Barret (public domain) <br /> 9799 /// Uses [stddoc.c](https://github.com/r-lyeh/stddoc.c) from r-lyeh@github.com for documentation generation <br /><br /> 9800 /// Embeds ProggyClean.ttf font by Tristan Grimmer (MIT license). <br /> 9801 /// 9802 /// Big thank you to Omar Cornut (ocornut@github) for his [imgui library](https://github.com/ocornut/imgui) and 9803 /// giving me the inspiration for this library, Casey Muratori for handmade hero 9804 /// and his original immediate mode graphical user interface idea and Sean 9805 /// Barret for his amazing single header libraries which restored my faith 9806 /// in libraries and brought me to create some of my own. Finally Apoorva Joshi 9807 /// for his single header file packer. 9808 */