nuklear.html 139 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352
  1. <meta charset='utf-8' emacsmode='-*- markdown -*-'>
  2. <link rel='stylesheet' href='https://casual-effects.com/markdeep/latest/apidoc.css?'>
  3. # Nuklear
  4. ![](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif)
  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. License section
  22. 8. Changelog section
  23. 9. Gallery section
  24. 10. Credits section
  25. ## About
  26. This is a minimal state immediate mode graphical user interface toolkit
  27. written in ANSI C and licensed under public domain. It was designed as a simple
  28. embeddable user interface for application and does not have any dependencies,
  29. a default renderbackend or OS window and input handling but instead provides a very modular
  30. library approach by using simple input state for input and draw
  31. commands describing primitive shapes as output. So instead of providing a
  32. layered library that tries to abstract over a number of platform and
  33. render backends it only focuses on the actual UI.
  34. ## Highlights
  35. - Graphical user interface toolkit
  36. - Single header library
  37. - Written in C89 (a.k.a. ANSI C or ISO C90)
  38. - Small codebase (~18kLOC)
  39. - Focus on portability, efficiency and simplicity
  40. - No dependencies (not even the standard library if not wanted)
  41. - Fully skinnable and customizable
  42. - Low memory footprint with total memory control if needed or wanted
  43. - UTF-8 support
  44. - No global or hidden state
  45. - Customizable library modules (you can compile and use only what you need)
  46. - Optional font baker and vertex buffer output
  47. ## Features
  48. - Absolutely no platform dependent code
  49. - Memory management control ranging from/to
  50. - Ease of use by allocating everything from standard library
  51. - Control every byte of memory inside the library
  52. - Font handling control ranging from/to
  53. - Use your own font implementation for everything
  54. - Use this libraries internal font baking and handling API
  55. - Drawing output control ranging from/to
  56. - Simple shapes for more high level APIs which already have drawing capabilities
  57. - Hardware accessible anti-aliased vertex buffer output
  58. - Customizable colors and properties ranging from/to
  59. - Simple changes to color by filling a simple color table
  60. - Complete control with ability to use skinning to decorate widgets
  61. - Bendable UI library with widget ranging from/to
  62. - Basic widgets like buttons, checkboxes, slider, ...
  63. - Advanced widget like abstract comboboxes, contextual menus,...
  64. - Compile time configuration to only compile what you need
  65. - Subset which can be used if you do not want to link or use the standard library
  66. - Can be easily modified to only update on user input instead of frame updates
  67. ## Usage
  68. This library is self contained in one single header file and can be used either
  69. in header only mode or in implementation mode. The header only mode is used
  70. by default when included and allows including this header in other headers
  71. and does not contain the actual implementation. <br /><br />
  72. The implementation mode requires to define the preprocessor macro
  73. NK_IMPLEMENTATION in *one* .c/.cpp file before #includeing this file, e.g.:
  74. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~C
  75. #define NK_IMPLEMENTATION
  76. #include "nuklear.h"
  77. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  78. Also optionally define the symbols listed in the section "OPTIONAL DEFINES"
  79. below in header and implementation mode if you want to use additional functionality
  80. or need more control over the library.
  81. !!! WARNING
  82. 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.
  83. ### Flags
  84. Flag | Description
  85. --------------------------------|------------------------------------------
  86. NK_PRIVATE | If defined declares all functions as static, so they can only be accessed inside the file that contains the implementation
  87. 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.
  88. 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.
  89. NK_INCLUDE_STANDARD_IO | If defined it will include header `<stdio.h>` and provide additional functions depending on file loading.
  90. NK_INCLUDE_STANDARD_VARARGS | If defined it will include header <stdio.h> and provide additional functions depending on file loading.
  91. 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,...
  92. 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.
  93. 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
  94. 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.
  95. 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.
  96. 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.
  97. !!! WARNING
  98. The following flags will pull in the standard C library:
  99. - NK_INCLUDE_DEFAULT_ALLOCATOR
  100. - NK_INCLUDE_STANDARD_IO
  101. - NK_INCLUDE_STANDARD_VARARGS
  102. !!! WARNING
  103. The following flags if defined need to be defined for both header and implementation:
  104. - NK_INCLUDE_FIXED_TYPES
  105. - NK_INCLUDE_DEFAULT_ALLOCATOR
  106. - NK_INCLUDE_STANDARD_VARARGS
  107. - NK_INCLUDE_VERTEX_BUFFER_OUTPUT
  108. - NK_INCLUDE_FONT_BAKING
  109. - NK_INCLUDE_DEFAULT_FONT
  110. - NK_INCLUDE_STANDARD_VARARGS
  111. - NK_INCLUDE_COMMAND_USERDATA
  112. ### Constants
  113. Define | Description
  114. --------------------------------|---------------------------------------
  115. 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.
  116. NK_MAX_NUMBER_BUFFER | Maximum buffer size for the conversion buffer between float and string Under normal circumstances this should be more than sufficient.
  117. 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.
  118. !!! WARNING
  119. The following constants if defined need to be defined for both header and implementation:
  120. - NK_MAX_NUMBER_BUFFER
  121. - NK_BUFFER_DEFAULT_INITIAL_SIZE
  122. - NK_INPUT_MAX
  123. ### Dependencies
  124. Function | Description
  125. ------------|---------------------------------------------------------------
  126. NK_ASSERT | If you don't define this, nuklear will use <assert.h> with assert().
  127. NK_MEMSET | You can define this to 'memset' or your own memset implementation replacement. If not nuklear will use its own version.
  128. NK_MEMCPY | You can define this to 'memcpy' or your own memcpy implementation replacement. If not nuklear will use its own version.
  129. NK_SQRT | You can define this to 'sqrt' or your own sqrt implementation replacement. If not nuklear will use its own slow and not highly accurate version.
  130. NK_SIN | You can define this to 'sinf' or your own sine implementation replacement. If not nuklear will use its own approximation implementation.
  131. NK_COS | You can define this to 'cosf' or your own cosine implementation replacement. If not nuklear will use its own approximation implementation.
  132. 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!).
  133. 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!).
  134. 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.
  135. !!! WARNING
  136. The following dependencies will pull in the standard C library if not redefined:
  137. - NK_ASSERT
  138. !!! WARNING
  139. The following dependencies if defined need to be defined for both header and implementation:
  140. - NK_ASSERT
  141. !!! WARNING
  142. The following dependencies if defined need to be defined only for the implementation part:
  143. - NK_MEMSET
  144. - NK_MEMCPY
  145. - NK_SQRT
  146. - NK_SIN
  147. - NK_COS
  148. - NK_STRTOD
  149. - NK_DTOA
  150. - NK_VSNPRINTF
  151. ## Example
  152. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  153. // init gui state
  154. enum {EASY, HARD};
  155. static int op = EASY;
  156. static float value = 0.6f;
  157. static int i = 20;
  158. struct nk_context ctx;
  159. nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font);
  160. if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
  161. NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
  162. // fixed widget pixel width
  163. nk_layout_row_static(&ctx, 30, 80, 1);
  164. if (nk_button_label(&ctx, "button")) {
  165. // event handling
  166. }
  167. // fixed widget window ratio width
  168. nk_layout_row_dynamic(&ctx, 30, 2);
  169. if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY;
  170. if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD;
  171. // custom widget pixel width
  172. nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
  173. {
  174. nk_layout_row_push(&ctx, 50);
  175. nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
  176. nk_layout_row_push(&ctx, 110);
  177. nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
  178. }
  179. nk_layout_row_end(&ctx);
  180. }
  181. nk_end(&ctx);
  182. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  183. ![](https://cloud.githubusercontent.com/assets/8057201/10187981/584ecd68-675c-11e5-897c-822ef534a876.png)
  184. ## API
  185. ### Context
  186. Contexts are the main entry point and the majestro of nuklear and contain all required state.
  187. They are used for window, memory, input, style, stack, commands and time management and need
  188. to be passed into all nuklear GUI specific functions.
  189. #### Usage
  190. To use a context it first has to be initialized which can be achieved by calling
  191. one of either `nk_init_default`, `nk_init_fixed`, `nk_init`, `nk_init_custom`.
  192. Each takes in a font handle and a specific way of handling memory. Memory control
  193. hereby ranges from standard library to just specifying a fixed sized block of memory
  194. which nuklear has to manage itself from.
  195. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  196. struct nk_context ctx;
  197. nk_init_xxx(&ctx, ...);
  198. while (1) {
  199. // [...]
  200. nk_clear(&ctx);
  201. }
  202. nk_free(&ctx);
  203. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  204. #### Reference
  205. Function | Description
  206. --------------------|-------------------------------------------------------
  207. __nk_init_default__ | Initializes context with standard library memory allocation (malloc,free)
  208. __nk_init_fixed__ | Initializes context from single fixed size memory block
  209. __nk_init__ | Initializes context with memory allocator callbacks for alloc and free
  210. __nk_init_custom__ | Initializes context from two buffers. One for draw commands the other for window/panel/table allocations
  211. __nk_clear__ | Called at the end of the frame to reset and prepare the context for the next frame
  212. __nk_free__ | Shutdown and free all memory allocated inside the context
  213. __nk_set_user_data__| Utility function to pass user data to draw command
  214. #### nk_init_default
  215. Initializes a `nk_context` struct with a default standard library allocator.
  216. Should be used if you don't want to be bothered with memory management in nuklear.
  217. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  218. int nk_init_default(struct nk_context *ctx, const struct nk_user_font *font);
  219. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  220. Parameter | Description
  221. ------------|---------------------------------------------------------------
  222. __ctx__ | Must point to an either stack or heap allocated `nk_context` struct
  223. __font__ | Must point to a previously initialized font handle for more info look at font documentation
  224. Returns either `false(0)` on failure or `true(1)` on success.
  225. #### nk_init_fixed
  226. Initializes a `nk_context` struct from single fixed size memory block
  227. Should be used if you want complete control over nuklear's memory management.
  228. Especially recommended for system with little memory or systems with virtual memory.
  229. For the later case you can just allocate for example 16MB of virtual memory
  230. and only the required amount of memory will actually be committed.
  231. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  232. int nk_init_fixed(struct nk_context *ctx, void *memory, nk_size size, const struct nk_user_font *font);
  233. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  234. !!! Warning
  235. make sure the passed memory block is aligned correctly for `nk_draw_commands`.
  236. Parameter | Description
  237. ------------|--------------------------------------------------------------
  238. __ctx__ | Must point to an either stack or heap allocated `nk_context` struct
  239. __memory__ | Must point to a previously allocated memory block
  240. __size__ | Must contain the total size of __memory__
  241. __font__ | Must point to a previously initialized font handle for more info look at font documentation
  242. Returns either `false(0)` on failure or `true(1)` on success.
  243. #### nk_init
  244. Initializes a `nk_context` struct with memory allocation callbacks for nuklear to allocate
  245. memory from. Used internally for `nk_init_default` and provides a kitchen sink allocation
  246. interface to nuklear. Can be useful for cases like monitoring memory consumption.
  247. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  248. int nk_init(struct nk_context *ctx, struct nk_allocator *alloc, const struct nk_user_font *font);
  249. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  250. Parameter | Description
  251. ------------|---------------------------------------------------------------
  252. __ctx__ | Must point to an either stack or heap allocated `nk_context` struct
  253. __alloc__ | Must point to a previously allocated memory allocator
  254. __font__ | Must point to a previously initialized font handle for more info look at font documentation
  255. Returns either `false(0)` on failure or `true(1)` on success.
  256. #### nk_init_custom
  257. Initializes a `nk_context` struct from two different either fixed or growing
  258. buffers. The first buffer is for allocating draw commands while the second buffer is
  259. used for allocating windows, panels and state tables.
  260. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  261. int nk_init_custom(struct nk_context *ctx, struct nk_buffer *cmds, struct nk_buffer *pool, const struct nk_user_font *font);
  262. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  263. Parameter | Description
  264. ------------|---------------------------------------------------------------
  265. __ctx__ | Must point to an either stack or heap allocated `nk_context` struct
  266. __cmds__ | Must point to a previously initialized memory buffer either fixed or dynamic to store draw commands into
  267. __pool__ | Must point to a previously initialized memory buffer either fixed or dynamic to store windows, panels and tables
  268. __font__ | Must point to a previously initialized font handle for more info look at font documentation
  269. Returns either `false(0)` on failure or `true(1)` on success.
  270. #### nk_clear
  271. Resets the context state at the end of the frame. This includes mostly
  272. garbage collector tasks like removing windows or table not called and therefore
  273. used anymore.
  274. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  275. void nk_clear(struct nk_context *ctx);
  276. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  277. Parameter | Description
  278. ------------|-----------------------------------------------------------
  279. __ctx__ | Must point to a previously initialized `nk_context` struct
  280. #### nk_free
  281. Frees all memory allocated by nuklear. Not needed if context was
  282. initialized with `nk_init_fixed`.
  283. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  284. void nk_free(struct nk_context *ctx);
  285. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  286. Parameter | Description
  287. ------------|-----------------------------------------------------------
  288. __ctx__ | Must point to a previously initialized `nk_context` struct
  289. #### nk_set_user_data
  290. Sets the currently passed userdata passed down into each draw command.
  291. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  292. void nk_set_user_data(struct nk_context *ctx, nk_handle data);
  293. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  294. Parameter | Description
  295. ------------|--------------------------------------------------------------
  296. __ctx__ | Must point to a previously initialized `nk_context` struct
  297. __data__ | Handle with either pointer or index to be passed into every draw commands
  298. ### Input
  299. The input API is responsible for holding the current input state composed of
  300. mouse, key and text input states.
  301. It is worth noting that no direct os or window handling is done in nuklear.
  302. Instead all input state has to be provided by platform specific code. This in one hand
  303. expects more work from the user and complicates usage but on the other hand
  304. provides simple abstraction over a big number of platforms, libraries and other
  305. already provided functionality.
  306. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  307. nk_input_begin(&ctx);
  308. while (GetEvent(&evt)) {
  309. if (evt.type == MOUSE_MOVE)
  310. nk_input_motion(&ctx, evt.motion.x, evt.motion.y);
  311. else if (evt.type == [...]) {
  312. // [...]
  313. }
  314. } nk_input_end(&ctx);
  315. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  316. #### Usage
  317. Input state needs to be provided to nuklear by first calling `nk_input_begin`
  318. which resets internal state like delta mouse position and button transistions.
  319. After `nk_input_begin` all current input state needs to be provided. This includes
  320. mouse motion, button and key pressed and released, text input and scrolling.
  321. Both event- or state-based input handling are supported by this API
  322. and should work without problems. Finally after all input state has been
  323. mirrored `nk_input_end` needs to be called to finish input process.
  324. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  325. struct nk_context ctx;
  326. nk_init_xxx(&ctx, ...);
  327. while (1) {
  328. Event evt;
  329. nk_input_begin(&ctx);
  330. while (GetEvent(&evt)) {
  331. if (evt.type == MOUSE_MOVE)
  332. nk_input_motion(&ctx, evt.motion.x, evt.motion.y);
  333. else if (evt.type == [...]) {
  334. // [...]
  335. }
  336. }
  337. nk_input_end(&ctx);
  338. // [...]
  339. nk_clear(&ctx);
  340. } nk_free(&ctx);
  341. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  342. #### Reference
  343. Function | Description
  344. --------------------|-------------------------------------------------------
  345. __nk_input_begin__ | Begins the input mirroring process. Needs to be called before all other `nk_input_xxx` calls
  346. __nk_input_motion__ | Mirrors mouse cursor position
  347. __nk_input_key__ | Mirrors key state with either pressed or released
  348. __nk_input_button__ | Mirrors mouse button state with either pressed or released
  349. __nk_input_scroll__ | Mirrors mouse scroll values
  350. __nk_input_char__ | Adds a single ASCII text character into an internal text buffer
  351. __nk_input_glyph__ | Adds a single multi-byte UTF-8 character into an internal text buffer
  352. __nk_input_unicode__| Adds a single unicode rune into an internal text buffer
  353. __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
  354. #### nk_input_begin
  355. Begins the input mirroring process by resetting text, scroll
  356. mouse previous mouse position and movement as well as key state transitions,
  357. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  358. void nk_input_begin(struct nk_context*);
  359. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  360. Parameter | Description
  361. ------------|-----------------------------------------------------------
  362. __ctx__ | Must point to a previously initialized `nk_context` struct
  363. #### nk_input_motion
  364. Mirrors current mouse position to nuklear
  365. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  366. void nk_input_motion(struct nk_context *ctx, int x, int y);
  367. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  368. Parameter | Description
  369. ------------|-----------------------------------------------------------
  370. __ctx__ | Must point to a previously initialized `nk_context` struct
  371. __x__ | Must hold an integer describing the current mouse cursor x-position
  372. __y__ | Must hold an integer describing the current mouse cursor y-position
  373. #### nk_input_key
  374. Mirrors state of a specific key to nuklear
  375. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  376. void nk_input_key(struct nk_context*, enum nk_keys key, int down);
  377. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  378. Parameter | Description
  379. ------------|-----------------------------------------------------------
  380. __ctx__ | Must point to a previously initialized `nk_context` struct
  381. __key__ | Must be any value specified in enum `nk_keys` that needs to be mirrored
  382. __down__ | Must be 0 for key is up and 1 for key is down
  383. #### nk_input_button
  384. Mirrors the state of a specific mouse button to nuklear
  385. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  386. void nk_input_button(struct nk_context *ctx, enum nk_buttons btn, int x, int y, int down);
  387. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  388. Parameter | Description
  389. ------------|-----------------------------------------------------------
  390. __ctx__ | Must point to a previously initialized `nk_context` struct
  391. __btn__ | Must be any value specified in enum `nk_buttons` that needs to be mirrored
  392. __x__ | Must contain an integer describing mouse cursor x-position on click up/down
  393. __y__ | Must contain an integer describing mouse cursor y-position on click up/down
  394. __down__ | Must be 0 for key is up and 1 for key is down
  395. #### nk_input_scroll
  396. Copies the last mouse scroll value to nuklear. Is generally
  397. a scroll value. So does not have to come from mouse and could also originate
  398. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  399. void nk_input_scroll(struct nk_context *ctx, struct nk_vec2 val);
  400. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  401. Parameter | Description
  402. ------------|-----------------------------------------------------------
  403. __ctx__ | Must point to a previously initialized `nk_context` struct
  404. __val__ | vector with both X- as well as Y-scroll value
  405. #### nk_input_char
  406. Copies a single ASCII character into an internal text buffer
  407. This is basically a helper function to quickly push ASCII characters into
  408. nuklear.
  409. !!! Note
  410. Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`.
  411. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  412. void nk_input_char(struct nk_context *ctx, char c);
  413. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  414. Parameter | Description
  415. ------------|-----------------------------------------------------------
  416. __ctx__ | Must point to a previously initialized `nk_context` struct
  417. __c__ | Must be a single ASCII character preferable one that can be printed
  418. #### nk_input_glyph
  419. Converts an encoded unicode rune into UTF-8 and copies the result into an
  420. internal text buffer.
  421. !!! Note
  422. Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`.
  423. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  424. void nk_input_glyph(struct nk_context *ctx, const nk_glyph g);
  425. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  426. Parameter | Description
  427. ------------|-----------------------------------------------------------
  428. __ctx__ | Must point to a previously initialized `nk_context` struct
  429. __g__ | UTF-32 unicode codepoint
  430. #### nk_input_unicode
  431. Converts a unicode rune into UTF-8 and copies the result
  432. into an internal text buffer.
  433. !!! Note
  434. Stores up to NK_INPUT_MAX bytes between `nk_input_begin` and `nk_input_end`.
  435. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  436. void nk_input_unicode(struct nk_context*, nk_rune rune);
  437. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  438. Parameter | Description
  439. ------------|-----------------------------------------------------------
  440. __ctx__ | Must point to a previously initialized `nk_context` struct
  441. __rune__ | UTF-32 unicode codepoint
  442. #### nk_input_end
  443. End the input mirroring process by resetting mouse grabbing
  444. state to ensure the mouse cursor is not grabbed indefinitely.///
  445. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  446. void nk_input_end(struct nk_context *ctx);
  447. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  448. Parameter | Description
  449. ------------|-----------------------------------------------------------
  450. __ctx__ | Must point to a previously initialized `nk_context` struct
  451. ### Drawing
  452. This library was designed to be render backend agnostic so it does
  453. not draw anything to screen directly. Instead all drawn shapes, widgets
  454. are made of, are buffered into memory and make up a command queue.
  455. Each frame therefore fills the command buffer with draw commands
  456. that then need to be executed by the user and his own render backend.
  457. After that the command buffer needs to be cleared and a new frame can be
  458. started. It is probably important to note that the command buffer is the main
  459. drawing API and the optional vertex buffer API only takes this format and
  460. converts it into a hardware accessible format.
  461. #### Usage
  462. To draw all draw commands accumulated over a frame you need your own render
  463. backend able to draw a number of 2D primitives. This includes at least
  464. filled and stroked rectangles, circles, text, lines, triangles and scissors.
  465. As soon as this criterion is met you can iterate over each draw command
  466. and execute each draw command in a interpreter like fashion:
  467. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  468. const struct nk_command *cmd = 0;
  469. nk_foreach(cmd, &ctx) {
  470. switch (cmd->type) {
  471. case NK_COMMAND_LINE:
  472. your_draw_line_function(...)
  473. break;
  474. case NK_COMMAND_RECT
  475. your_draw_rect_function(...)
  476. break;
  477. case //...:
  478. //[...]
  479. }
  480. }
  481. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  482. In program flow context draw commands need to be executed after input has been
  483. gathered and the complete UI with windows and their contained widgets have
  484. been executed and before calling `nk_clear` which frees all previously
  485. allocated draw commands.
  486. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  487. struct nk_context ctx;
  488. nk_init_xxx(&ctx, ...);
  489. while (1) {
  490. Event evt;
  491. nk_input_begin(&ctx);
  492. while (GetEvent(&evt)) {
  493. if (evt.type == MOUSE_MOVE)
  494. nk_input_motion(&ctx, evt.motion.x, evt.motion.y);
  495. else if (evt.type == [...]) {
  496. [...]
  497. }
  498. }
  499. nk_input_end(&ctx);
  500. //
  501. // [...]
  502. //
  503. const struct nk_command *cmd = 0;
  504. nk_foreach(cmd, &ctx) {
  505. switch (cmd->type) {
  506. case NK_COMMAND_LINE:
  507. your_draw_line_function(...)
  508. break;
  509. case NK_COMMAND_RECT
  510. your_draw_rect_function(...)
  511. break;
  512. case ...:
  513. // [...]
  514. }
  515. nk_clear(&ctx);
  516. }
  517. nk_free(&ctx);
  518. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  519. You probably noticed that you have to draw all of the UI each frame which is
  520. quite wasteful. While the actual UI updating loop is quite fast rendering
  521. without actually needing it is not. So there are multiple things you could do.
  522. First is only update on input. This of course is only an option if your
  523. application only depends on the UI and does not require any outside calculations.
  524. If you actually only update on input make sure to update the UI two times each
  525. frame and call `nk_clear` directly after the first pass and only draw in
  526. the second pass. In addition it is recommended to also add additional timers
  527. to make sure the UI is not drawn more than a fixed number of frames per second.
  528. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  529. struct nk_context ctx;
  530. nk_init_xxx(&ctx, ...);
  531. while (1) {
  532. // [...wait for input ]
  533. // [...do two UI passes ...]
  534. do_ui(...)
  535. nk_clear(&ctx);
  536. do_ui(...)
  537. //
  538. // draw
  539. const struct nk_command *cmd = 0;
  540. nk_foreach(cmd, &ctx) {
  541. switch (cmd->type) {
  542. case NK_COMMAND_LINE:
  543. your_draw_line_function(...)
  544. break;
  545. case NK_COMMAND_RECT
  546. your_draw_rect_function(...)
  547. break;
  548. case ...:
  549. //[...]
  550. }
  551. nk_clear(&ctx);
  552. }
  553. nk_free(&ctx);
  554. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  555. The second probably more applicable trick is to only draw if anything changed.
  556. It is not really useful for applications with continuous draw loop but
  557. quite useful for desktop applications. To actually get nuklear to only
  558. draw on changes you first have to define `NK_ZERO_COMMAND_MEMORY` and
  559. allocate a memory buffer that will store each unique drawing output.
  560. After each frame you compare the draw command memory inside the library
  561. with your allocated buffer by memcmp. If memcmp detects differences
  562. you have to copy the command buffer into the allocated buffer
  563. and then draw like usual (this example uses fixed memory but you could
  564. use dynamically allocated memory).
  565. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  566. //[... other defines ...]
  567. #define NK_ZERO_COMMAND_MEMORY
  568. #include "nuklear.h"
  569. //
  570. // setup context
  571. struct nk_context ctx;
  572. void *last = calloc(1,64*1024);
  573. void *buf = calloc(1,64*1024);
  574. nk_init_fixed(&ctx, buf, 64*1024);
  575. //
  576. // loop
  577. while (1) {
  578. // [...input...]
  579. // [...ui...]
  580. void *cmds = nk_buffer_memory(&ctx.memory);
  581. if (memcmp(cmds, last, ctx.memory.allocated)) {
  582. memcpy(last,cmds,ctx.memory.allocated);
  583. const struct nk_command *cmd = 0;
  584. nk_foreach(cmd, &ctx) {
  585. switch (cmd->type) {
  586. case NK_COMMAND_LINE:
  587. your_draw_line_function(...)
  588. break;
  589. case NK_COMMAND_RECT
  590. your_draw_rect_function(...)
  591. break;
  592. case ...:
  593. // [...]
  594. }
  595. }
  596. }
  597. nk_clear(&ctx);
  598. }
  599. nk_free(&ctx);
  600. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  601. Finally while using draw commands makes sense for higher abstracted platforms like
  602. X11 and Win32 or drawing libraries it is often desirable to use graphics
  603. hardware directly. Therefore it is possible to just define
  604. `NK_INCLUDE_VERTEX_BUFFER_OUTPUT` which includes optional vertex output.
  605. To access the vertex output you first have to convert all draw commands into
  606. vertexes by calling `nk_convert` which takes in your preferred vertex format.
  607. After successfully converting all draw commands just iterate over and execute all
  608. vertex draw commands:
  609. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  610. // fill configuration
  611. struct nk_convert_config cfg = {};
  612. static const struct nk_draw_vertex_layout_element vertex_layout[] = {
  613. {NK_VERTEX_POSITION, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, pos)},
  614. {NK_VERTEX_TEXCOORD, NK_FORMAT_FLOAT, NK_OFFSETOF(struct your_vertex, uv)},
  615. {NK_VERTEX_COLOR, NK_FORMAT_R8G8B8A8, NK_OFFSETOF(struct your_vertex, col)},
  616. {NK_VERTEX_LAYOUT_END}
  617. };
  618. cfg.shape_AA = NK_ANTI_ALIASING_ON;
  619. cfg.line_AA = NK_ANTI_ALIASING_ON;
  620. cfg.vertex_layout = vertex_layout;
  621. cfg.vertex_size = sizeof(struct your_vertex);
  622. cfg.vertex_alignment = NK_ALIGNOF(struct your_vertex);
  623. cfg.circle_segment_count = 22;
  624. cfg.curve_segment_count = 22;
  625. cfg.arc_segment_count = 22;
  626. cfg.global_alpha = 1.0f;
  627. cfg.null = dev->null;
  628. //
  629. // setup buffers and convert
  630. struct nk_buffer cmds, verts, idx;
  631. nk_buffer_init_default(&cmds);
  632. nk_buffer_init_default(&verts);
  633. nk_buffer_init_default(&idx);
  634. nk_convert(&ctx, &cmds, &verts, &idx, &cfg);
  635. //
  636. // draw
  637. nk_draw_foreach(cmd, &ctx, &cmds) {
  638. if (!cmd->elem_count) continue;
  639. //[...]
  640. }
  641. nk_buffer_free(&cms);
  642. nk_buffer_free(&verts);
  643. nk_buffer_free(&idx);
  644. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  645. #### Reference
  646. Function | Description
  647. --------------------|-------------------------------------------------------
  648. __nk__begin__ | Returns the first draw command in the context draw command list to be drawn
  649. __nk__next__ | Increments the draw command iterator to the next command inside the context draw command list
  650. __nk_foreach__ | Iterates over each draw command inside the context draw command list
  651. __nk_convert__ | Converts from the abstract draw commands list into a hardware accessible vertex format
  652. __nk_draw_begin__ | Returns the first vertex command in the context vertex draw list to be executed
  653. __nk__draw_next__ | Increments the vertex command iterator to the next command inside the context vertex command list
  654. __nk__draw_end__ | Returns the end of the vertex draw list
  655. __nk_draw_foreach__ | Iterates over each vertex draw command inside the vertex draw list
  656. #### nk__begin
  657. Returns a draw command list iterator to iterate all draw
  658. commands accumulated over one frame.
  659. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  660. const struct nk_command* nk__begin(struct nk_context*);
  661. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  662. Parameter | Description
  663. ------------|-----------------------------------------------------------
  664. __ctx__ | must point to an previously initialized `nk_context` struct at the end of a frame
  665. Returns draw command pointer pointing to the first command inside the draw command list
  666. #### nk__next
  667. Returns a draw command list iterator to iterate all draw
  668. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  669. const struct nk_command* nk__next(struct nk_context*, const struct nk_command*);
  670. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  671. Parameter | Description
  672. ------------|-----------------------------------------------------------
  673. __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame
  674. __cmd__ | Must point to an previously a draw command either returned by `nk__begin` or `nk__next`
  675. Returns draw command pointer pointing to the next command inside the draw command list
  676. #### nk_foreach
  677. Iterates over each draw command inside the context draw command list
  678. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  679. #define nk_foreach(c, ctx)
  680. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  681. Parameter | Description
  682. ------------|-----------------------------------------------------------
  683. __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame
  684. __cmd__ | Command pointer initialized to NULL
  685. Returns draw command pointer pointing to the next command inside the draw command list
  686. #### nk_convert
  687. Converts all internal draw commands into vertex draw commands and fills
  688. three buffers with vertexes, vertex draw commands and vertex indices. The vertex format
  689. as well as some other configuration values have to be configured by filling out a
  690. `nk_convert_config` struct.
  691. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  692. nk_flags nk_convert(struct nk_context *ctx, struct nk_buffer *cmds,
  693. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  694. Parameter | Description
  695. ------------|-----------------------------------------------------------
  696. __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame
  697. __cmds__ | Must point to a previously initialized buffer to hold converted vertex draw commands
  698. __vertices__| Must point to a previously initialized buffer to hold all produced vertices
  699. __elements__| Must point to a previously initialized buffer to hold all produced vertex indices
  700. __config__ | Must point to a filled out `nk_config` struct to configure the conversion process
  701. Returns one of enum nk_convert_result error codes
  702. Parameter | Description
  703. --------------------------------|-----------------------------------------------------------
  704. NK_CONVERT_SUCCESS | Signals a successful draw command to vertex buffer conversion
  705. NK_CONVERT_INVALID_PARAM | An invalid argument was passed in the function call
  706. NK_CONVERT_COMMAND_BUFFER_FULL | The provided buffer for storing draw commands is full or failed to allocate more memory
  707. NK_CONVERT_VERTEX_BUFFER_FULL | The provided buffer for storing vertices is full or failed to allocate more memory
  708. NK_CONVERT_ELEMENT_BUFFER_FULL | The provided buffer for storing indicies is full or failed to allocate more memory
  709. #### nk__draw_begin
  710. Returns a draw vertex command buffer iterator to iterate each the vertex draw command buffer
  711. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  712. const struct nk_draw_command* nk__draw_begin(const struct nk_context*, const struct nk_buffer*);
  713. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  714. Parameter | Description
  715. ------------|-----------------------------------------------------------
  716. __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame
  717. __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer
  718. Returns vertex draw command pointer pointing to the first command inside the vertex draw command buffer
  719. #### nk__draw_end
  720. Returns the vertex draw command at the end of the vertex draw command buffer
  721. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  722. const struct nk_draw_command* nk__draw_end(const struct nk_context *ctx, const struct nk_buffer *buf);
  723. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  724. Parameter | Description
  725. ------------|-----------------------------------------------------------
  726. __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame
  727. __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer
  728. Returns vertex draw command pointer pointing to the end of the last vertex draw command inside the vertex draw command buffer
  729. #### nk__draw_next
  730. Increments the vertex draw command buffer iterator
  731. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  732. const struct nk_draw_command* nk__draw_next(const struct nk_draw_command*, const struct nk_buffer*, const struct nk_context*);
  733. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  734. Parameter | Description
  735. ------------|-----------------------------------------------------------
  736. __cmd__ | Must point to an previously either by `nk__draw_begin` or `nk__draw_next` returned vertex draw command
  737. __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer
  738. __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame
  739. Returns vertex draw command pointer pointing to the end of the last vertex draw command inside the vertex draw command buffer
  740. #### nk_draw_foreach
  741. Iterates over each vertex draw command inside a vertex draw command buffer
  742. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  743. #define nk_draw_foreach(cmd,ctx, b)
  744. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  745. Parameter | Description
  746. ------------|-----------------------------------------------------------
  747. __cmd__ | `nk_draw_command`iterator set to NULL
  748. __buf__ | Must point to an previously by `nk_convert` filled out vertex draw command buffer
  749. __ctx__ | Must point to an previously initialized `nk_context` struct at the end of a frame
  750. ### Window
  751. Windows are the main persistent state used inside nuklear and are life time
  752. controlled by simply "retouching" (i.e. calling) each window each frame.
  753. All widgets inside nuklear can only be added inside function pair `nk_begin_xxx`
  754. and `nk_end`. Calling any widgets outside these two functions will result in an
  755. assert in debug or no state change in release mode.<br /><br />
  756. Each window holds frame persistent state like position, size, flags, state tables,
  757. and some garbage collected internal persistent widget state. Each window
  758. is linked into a window stack list which determines the drawing and overlapping
  759. order. The topmost window thereby is the currently active window.<br /><br />
  760. To change window position inside the stack occurs either automatically by
  761. user input by being clicked on or programmatically by calling `nk_window_focus`.
  762. Windows by default are visible unless explicitly being defined with flag
  763. `NK_WINDOW_HIDDEN`, the user clicked the close button on windows with flag
  764. `NK_WINDOW_CLOSABLE` or if a window was explicitly hidden by calling
  765. `nk_window_show`. To explicitly close and destroy a window call `nk_window_close`.<br /><br />
  766. #### Usage
  767. To create and keep a window you have to call one of the two `nk_begin_xxx`
  768. functions to start window declarations and `nk_end` at the end. Furthermore it
  769. is recommended to check the return value of `nk_begin_xxx` and only process
  770. widgets inside the window if the value is not 0. Either way you have to call
  771. `nk_end` at the end of window declarations. Furthermore, do not attempt to
  772. nest `nk_begin_xxx` calls which will hopefully result in an assert or if not
  773. in a segmentation fault.
  774. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  775. if (nk_begin_xxx(...) {
  776. // [... widgets ...]
  777. }
  778. nk_end(ctx);
  779. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  780. In the grand concept window and widget declarations need to occur after input
  781. handling and before drawing to screen. Not doing so can result in higher
  782. latency or at worst invalid behavior. Furthermore make sure that `nk_clear`
  783. is called at the end of the frame. While nuklear's default platform backends
  784. already call `nk_clear` for you if you write your own backend not calling
  785. `nk_clear` can cause asserts or even worse undefined behavior.
  786. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  787. struct nk_context ctx;
  788. nk_init_xxx(&ctx, ...);
  789. while (1) {
  790. Event evt;
  791. nk_input_begin(&ctx);
  792. while (GetEvent(&evt)) {
  793. if (evt.type == MOUSE_MOVE)
  794. nk_input_motion(&ctx, evt.motion.x, evt.motion.y);
  795. else if (evt.type == [...]) {
  796. nk_input_xxx(...);
  797. }
  798. }
  799. nk_input_end(&ctx);
  800. if (nk_begin_xxx(...) {
  801. //[...]
  802. }
  803. nk_end(ctx);
  804. const struct nk_command *cmd = 0;
  805. nk_foreach(cmd, &ctx) {
  806. case NK_COMMAND_LINE:
  807. your_draw_line_function(...)
  808. break;
  809. case NK_COMMAND_RECT
  810. your_draw_rect_function(...)
  811. break;
  812. case //...:
  813. //[...]
  814. }
  815. nk_clear(&ctx);
  816. }
  817. nk_free(&ctx);
  818. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  819. #### Reference
  820. Function | Description
  821. ------------------------------------|----------------------------------------
  822. nk_begin | Starts a new window; needs to be called every frame for every window (unless hidden) or otherwise the window gets removed
  823. nk_begin_titled | Extended window start with separated title and identifier to allow multiple windows with same name but not title
  824. nk_end | Needs to be called at the end of the window building process to process scaling, scrollbars and general cleanup
  825. nk_window_find | Finds and returns the window with give name
  826. nk_window_get_bounds | Returns a rectangle with screen position and size of the currently processed window.
  827. nk_window_get_position | Returns the position of the currently processed window
  828. nk_window_get_size | Returns the size with width and height of the currently processed window
  829. nk_window_get_width | Returns the width of the currently processed window
  830. nk_window_get_height | Returns the height of the currently processed window
  831. nk_window_get_panel | Returns the underlying panel which contains all processing state of the current window
  832. nk_window_get_content_region | Returns the position and size of the currently visible and non-clipped space inside the currently processed window
  833. nk_window_get_content_region_min | Returns the upper rectangle position of the currently visible and non-clipped space inside the currently processed window
  834. nk_window_get_content_region_max | Returns the upper rectangle position of the currently visible and non-clipped space inside the currently processed window
  835. nk_window_get_content_region_size | Returns the size of the currently visible and non-clipped space inside the currently processed window
  836. nk_window_get_canvas | Returns the draw command buffer. Can be used to draw custom widgets
  837. nk_window_has_focus | Returns if the currently processed window is currently active
  838. nk_window_is_collapsed | Returns if the window with given name is currently minimized/collapsed
  839. nk_window_is_closed | Returns if the currently processed window was closed
  840. nk_window_is_hidden | Returns if the currently processed window was hidden
  841. nk_window_is_active | Same as nk_window_has_focus for some reason
  842. nk_window_is_hovered | Returns if the currently processed window is currently being hovered by mouse
  843. nk_window_is_any_hovered | Return if any window currently hovered
  844. nk_item_is_any_active | Returns if any window or widgets is currently hovered or active
  845. nk_window_set_bounds | Updates position and size of the currently processed window
  846. nk_window_set_position | Updates position of the currently process window
  847. nk_window_set_size | Updates the size of the currently processed window
  848. nk_window_set_focus | Set the currently processed window as active window
  849. nk_window_close | Closes the window with given window name which deletes the window at the end of the frame
  850. nk_window_collapse | Collapses the window with given window name
  851. nk_window_collapse_if | Collapses the window with given window name if the given condition was met
  852. nk_window_show | Hides a visible or reshows a hidden window
  853. nk_window_show_if | Hides/shows a window depending on condition
  854. #### nk_panel_flags
  855. Flag | Description
  856. ----------------------------|----------------------------------------
  857. NK_WINDOW_BORDER | Draws a border around the window to visually separate window from the background
  858. NK_WINDOW_MOVABLE | The movable flag indicates that a window can be moved by user input or by dragging the window header
  859. 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
  860. NK_WINDOW_CLOSABLE | Adds a closable icon into the header
  861. NK_WINDOW_MINIMIZABLE | Adds a minimize icon into the header
  862. NK_WINDOW_NO_SCROLLBAR | Removes the scrollbar from the window
  863. NK_WINDOW_TITLE | Forces a header at the top at the window showing the title
  864. 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
  865. NK_WINDOW_BACKGROUND | Always keep window in the background
  866. NK_WINDOW_SCALE_LEFT | Puts window scaler in the left-ottom corner instead right-bottom
  867. NK_WINDOW_NO_INPUT | Prevents window of scaling, moving or getting focus
  868. #### nk_collapse_states
  869. State | Description
  870. ----------------|-----------------------------------------------------------
  871. __NK_MINIMIZED__| UI section is collased and not visibile until maximized
  872. __NK_MAXIMIZED__| UI section is extended and visibile until minimized
  873. <br /><br />
  874. #### nk_begin
  875. Starts a new window; needs to be called every frame for every
  876. window (unless hidden) or otherwise the window gets removed
  877. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  878. int nk_begin(struct nk_context *ctx, const char *title, struct nk_rect bounds, nk_flags flags);
  879. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  880. Parameter | Description
  881. ------------|-----------------------------------------------------------
  882. __ctx__ | Must point to an previously initialized `nk_context` struct
  883. __title__ | Window title and identifier. Needs to be persistent over frames to identify the window
  884. __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
  885. __flags__ | Window flags defined in the nk_panel_flags section with a number of different window behaviors
  886. Returns `true(1)` if the window can be filled up with widgets from this point
  887. until `nk_end` or `false(0)` otherwise for example if minimized
  888. #### nk_begin_titled
  889. Extended window start with separated title and identifier to allow multiple
  890. windows with same name but not title
  891. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  892. int nk_begin_titled(struct nk_context *ctx, const char *name, const char *title, struct nk_rect bounds, nk_flags flags);
  893. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  894. Parameter | Description
  895. ------------|-----------------------------------------------------------
  896. __ctx__ | Must point to an previously initialized `nk_context` struct
  897. __name__ | Window identifier. Needs to be persistent over frames to identify the window
  898. __title__ | Window title displayed inside header if flag `NK_WINDOW_TITLE` or either `NK_WINDOW_CLOSABLE` or `NK_WINDOW_MINIMIZED` was set
  899. __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
  900. __flags__ | Window flags defined in the nk_panel_flags section with a number of different window behaviors
  901. Returns `true(1)` if the window can be filled up with widgets from this point
  902. until `nk_end` or `false(0)` otherwise for example if minimized
  903. #### nk_end
  904. Needs to be called at the end of the window building process to process scaling, scrollbars and general cleanup.
  905. All widget calls after this functions will result in asserts or no state changes
  906. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  907. void nk_end(struct nk_context *ctx);
  908. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  909. Parameter | Description
  910. ------------|-----------------------------------------------------------
  911. __ctx__ | Must point to an previously initialized `nk_context` struct
  912. #### nk_window_find
  913. Finds and returns a window from passed name
  914. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  915. void nk_end(struct nk_context *ctx);
  916. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  917. Parameter | Description
  918. ------------|-----------------------------------------------------------
  919. __ctx__ | Must point to an previously initialized `nk_context` struct
  920. __name__ | Window identifier
  921. Returns a `nk_window` struct pointing to the identified window or NULL if
  922. no window with given name was found
  923. #### nk_window_get_bounds
  924. Returns a rectangle with screen position and size of the currently processed window
  925. !!! WARNING
  926. Only call this function between calls `nk_begin_xxx` and `nk_end`
  927. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  928. struct nk_rect nk_window_get_bounds(const struct nk_context *ctx);
  929. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  930. Parameter | Description
  931. ------------|-----------------------------------------------------------
  932. __ctx__ | Must point to an previously initialized `nk_context` struct
  933. Returns a `nk_rect` struct with window upper left window position and size
  934. #### nk_window_get_bounds
  935. Returns the position of the currently processed window.
  936. !!! WARNING
  937. Only call this function between calls `nk_begin_xxx` and `nk_end`
  938. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  939. struct nk_vec2 nk_window_get_position(const struct nk_context *ctx);
  940. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  941. Parameter | Description
  942. ------------|-----------------------------------------------------------
  943. __ctx__ | Must point to an previously initialized `nk_context` struct
  944. Returns a `nk_vec2` struct with window upper left position
  945. #### nk_window_get_size
  946. Returns the size with width and height of the currently processed window.
  947. !!! WARNING
  948. Only call this function between calls `nk_begin_xxx` and `nk_end`
  949. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  950. struct nk_vec2 nk_window_get_size(const struct nk_context *ctx);
  951. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  952. Parameter | Description
  953. ------------|-----------------------------------------------------------
  954. __ctx__ | Must point to an previously initialized `nk_context` struct
  955. Returns a `nk_vec2` struct with window width and height
  956. #### nk_window_get_width
  957. Returns the width of the currently processed window.
  958. !!! WARNING
  959. Only call this function between calls `nk_begin_xxx` and `nk_end`
  960. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  961. float nk_window_get_width(const struct nk_context *ctx);
  962. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  963. Parameter | Description
  964. ------------|-----------------------------------------------------------
  965. __ctx__ | Must point to an previously initialized `nk_context` struct
  966. Returns the current window width
  967. #### nk_window_get_width
  968. Returns the height of the currently processed window.
  969. !!! WARNING
  970. Only call this function between calls `nk_begin_xxx` and `nk_end`
  971. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  972. float nk_window_get_width(const struct nk_context *ctx);
  973. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  974. Parameter | Description
  975. ------------|-----------------------------------------------------------
  976. __ctx__ | Must point to an previously initialized `nk_context` struct
  977. Returns the current window width
  978. #### nk_window_get_panel
  979. Returns the underlying panel which contains all processing state of the current window.
  980. !!! WARNING
  981. Only call this function between calls `nk_begin_xxx` and `nk_end`
  982. !!! WARNING
  983. Do not keep the returned panel pointer around it is only valid until `nk_end`
  984. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  985. struct nk_panel* nk_window_get_panel(struct nk_context *ctx);
  986. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  987. Parameter | Description
  988. ------------|-----------------------------------------------------------
  989. __ctx__ | Must point to an previously initialized `nk_context` struct
  990. Returns a pointer to window internal `nk_panel` state.
  991. #### nk_window_get_content_region
  992. Returns the position and size of the currently visible and non-clipped space
  993. inside the currently processed window.
  994. !!! WARNING
  995. Only call this function between calls `nk_begin_xxx` and `nk_end`
  996. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  997. struct nk_rect nk_window_get_content_region(struct nk_context *ctx);
  998. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  999. Parameter | Description
  1000. ------------|-----------------------------------------------------------
  1001. __ctx__ | Must point to an previously initialized `nk_context` struct
  1002. Returns `nk_rect` struct with screen position and size (no scrollbar offset)
  1003. of the visible space inside the current window
  1004. #### nk_window_get_content_region_min
  1005. Returns the upper left position of the currently visible and non-clipped
  1006. space inside the currently processed window.
  1007. !!! WARNING
  1008. Only call this function between calls `nk_begin_xxx` and `nk_end`
  1009. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1010. struct nk_vec2 nk_window_get_content_region_min(struct nk_context *ctx);
  1011. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1012. Parameter | Description
  1013. ------------|-----------------------------------------------------------
  1014. __ctx__ | Must point to an previously initialized `nk_context` struct
  1015. returns `nk_vec2` struct with upper left screen position (no scrollbar offset)
  1016. of the visible space inside the current window
  1017. #### nk_window_get_content_region_max
  1018. Returns the lower right screen position of the currently visible and
  1019. non-clipped space inside the currently processed window.
  1020. !!! WARNING
  1021. Only call this function between calls `nk_begin_xxx` and `nk_end`
  1022. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1023. struct nk_vec2 nk_window_get_content_region_max(struct nk_context *ctx);
  1024. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1025. Parameter | Description
  1026. ------------|-----------------------------------------------------------
  1027. __ctx__ | Must point to an previously initialized `nk_context` struct
  1028. Returns `nk_vec2` struct with lower right screen position (no scrollbar offset)
  1029. of the visible space inside the current window
  1030. #### nk_window_get_content_region_size
  1031. Returns the size of the currently visible and non-clipped space inside the
  1032. currently processed window
  1033. !!! WARNING
  1034. Only call this function between calls `nk_begin_xxx` and `nk_end`
  1035. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1036. struct nk_vec2 nk_window_get_content_region_size(struct nk_context *ctx);
  1037. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1038. Parameter | Description
  1039. ------------|-----------------------------------------------------------
  1040. __ctx__ | Must point to an previously initialized `nk_context` struct
  1041. Returns `nk_vec2` struct with size the visible space inside the current window
  1042. #### nk_window_get_canvas
  1043. Returns the draw command buffer. Can be used to draw custom widgets
  1044. !!! WARNING
  1045. Only call this function between calls `nk_begin_xxx` and `nk_end`
  1046. !!! WARNING
  1047. Do not keep the returned command buffer pointer around it is only valid until `nk_end`
  1048. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1049. struct nk_command_buffer* nk_window_get_canvas(struct nk_context *ctx);
  1050. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1051. Parameter | Description
  1052. ------------|-----------------------------------------------------------
  1053. __ctx__ | Must point to an previously initialized `nk_context` struct
  1054. Returns a pointer to window internal `nk_command_buffer` struct used as
  1055. drawing canvas. Can be used to do custom drawing.
  1056. #### nk_window_has_focus
  1057. Returns if the currently processed window is currently active
  1058. !!! WARNING
  1059. Only call this function between calls `nk_begin_xxx` and `nk_end`
  1060. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1061. int nk_window_has_focus(const struct nk_context *ctx);
  1062. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1063. Parameter | Description
  1064. ------------|-----------------------------------------------------------
  1065. __ctx__ | Must point to an previously initialized `nk_context` struct
  1066. Returns `false(0)` if current window is not active or `true(1)` if it is
  1067. #### nk_window_is_hovered
  1068. Return if the current window is being hovered
  1069. !!! WARNING
  1070. Only call this function between calls `nk_begin_xxx` and `nk_end`
  1071. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1072. int nk_window_is_hovered(struct nk_context *ctx);
  1073. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1074. Parameter | Description
  1075. ------------|-----------------------------------------------------------
  1076. __ctx__ | Must point to an previously initialized `nk_context` struct
  1077. Returns `true(1)` if current window is hovered or `false(0)` otherwise
  1078. #### nk_window_is_collapsed
  1079. Returns if the window with given name is currently minimized/collapsed
  1080. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1081. int nk_window_is_collapsed(struct nk_context *ctx, const char *name);
  1082. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1083. Parameter | Description
  1084. ------------|-----------------------------------------------------------
  1085. __ctx__ | Must point to an previously initialized `nk_context` struct
  1086. __name__ | Identifier of window you want to check if it is collapsed
  1087. Returns `true(1)` if current window is minimized and `false(0)` if window not
  1088. found or is not minimized
  1089. #### nk_window_is_closed
  1090. Returns if the window with given name was closed by calling `nk_close`
  1091. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1092. int nk_window_is_closed(struct nk_context *ctx, const char *name);
  1093. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1094. Parameter | Description
  1095. ------------|-----------------------------------------------------------
  1096. __ctx__ | Must point to an previously initialized `nk_context` struct
  1097. __name__ | Identifier of window you want to check if it is closed
  1098. Returns `true(1)` if current window was closed or `false(0)` window not found or not closed
  1099. #### nk_window_is_hidden
  1100. Returns if the window with given name is hidden
  1101. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1102. int nk_window_is_hidden(struct nk_context *ctx, const char *name);
  1103. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1104. Parameter | Description
  1105. ------------|-----------------------------------------------------------
  1106. __ctx__ | Must point to an previously initialized `nk_context` struct
  1107. __name__ | Identifier of window you want to check if it is hidden
  1108. Returns `true(1)` if current window is hidden or `false(0)` window not found or visible
  1109. #### nk_window_is_active
  1110. Same as nk_window_has_focus for some reason
  1111. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1112. int nk_window_is_active(struct nk_context *ctx, const char *name);
  1113. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1114. Parameter | Description
  1115. ------------|-----------------------------------------------------------
  1116. __ctx__ | Must point to an previously initialized `nk_context` struct
  1117. __name__ | Identifier of window you want to check if it is active
  1118. Returns `true(1)` if current window is active or `false(0)` window not found or not active
  1119. #### nk_window_is_any_hovered
  1120. Returns if the any window is being hovered
  1121. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1122. int nk_window_is_any_hovered(struct nk_context*);
  1123. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1124. Parameter | Description
  1125. ------------|-----------------------------------------------------------
  1126. __ctx__ | Must point to an previously initialized `nk_context` struct
  1127. Returns `true(1)` if any window is hovered or `false(0)` otherwise
  1128. #### nk_item_is_any_active
  1129. Returns if the any window is being hovered or any widget is currently active.
  1130. Can be used to decide if input should be processed by UI or your specific input handling.
  1131. Example could be UI and 3D camera to move inside a 3D space.
  1132. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1133. int nk_item_is_any_active(struct nk_context*);
  1134. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1135. Parameter | Description
  1136. ------------|-----------------------------------------------------------
  1137. __ctx__ | Must point to an previously initialized `nk_context` struct
  1138. Returns `true(1)` if any window is hovered or any item is active or `false(0)` otherwise
  1139. #### nk_window_set_bounds
  1140. Updates position and size of window with passed in name
  1141. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1142. void nk_window_set_bounds(struct nk_context*, const char *name, struct nk_rect bounds);
  1143. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1144. Parameter | Description
  1145. ------------|-----------------------------------------------------------
  1146. __ctx__ | Must point to an previously initialized `nk_context` struct
  1147. __name__ | Identifier of the window to modify both position and size
  1148. __bounds__ | Must point to a `nk_rect` struct with the new position and size
  1149. #### nk_window_set_position
  1150. Updates position of window with passed name
  1151. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1152. void nk_window_set_position(struct nk_context*, const char *name, struct nk_vec2 pos);
  1153. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1154. Parameter | Description
  1155. ------------|-----------------------------------------------------------
  1156. __ctx__ | Must point to an previously initialized `nk_context` struct
  1157. __name__ | Identifier of the window to modify both position
  1158. __pos__ | Must point to a `nk_vec2` struct with the new position
  1159. #### nk_window_set_size
  1160. Updates size of window with passed in name
  1161. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1162. void nk_window_set_size(struct nk_context*, const char *name, struct nk_vec2);
  1163. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1164. Parameter | Description
  1165. ------------|-----------------------------------------------------------
  1166. __ctx__ | Must point to an previously initialized `nk_context` struct
  1167. __name__ | Identifier of the window to modify both window size
  1168. __size__ | Must point to a `nk_vec2` struct with new window size
  1169. #### nk_window_set_focus
  1170. Sets the window with given name as active
  1171. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1172. void nk_window_set_focus(struct nk_context*, const char *name);
  1173. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1174. Parameter | Description
  1175. ------------|-----------------------------------------------------------
  1176. __ctx__ | Must point to an previously initialized `nk_context` struct
  1177. __name__ | Identifier of the window to set focus on
  1178. #### nk_window_close
  1179. Closes a window and marks it for being freed at the end of the frame
  1180. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1181. void nk_window_close(struct nk_context *ctx, const char *name);
  1182. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1183. Parameter | Description
  1184. ------------|-----------------------------------------------------------
  1185. __ctx__ | Must point to an previously initialized `nk_context` struct
  1186. __name__ | Identifier of the window to close
  1187. #### nk_window_collapse
  1188. Updates collapse state of a window with given name
  1189. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1190. void nk_window_collapse(struct nk_context*, const char *name, enum nk_collapse_states state);
  1191. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1192. Parameter | Description
  1193. ------------|-----------------------------------------------------------
  1194. __ctx__ | Must point to an previously initialized `nk_context` struct
  1195. __name__ | Identifier of the window to close
  1196. __state__ | value out of nk_collapse_states section
  1197. #### nk_window_collapse_if
  1198. Updates collapse state of a window with given name if given condition is met
  1199. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1200. void nk_window_collapse_if(struct nk_context*, const char *name, enum nk_collapse_states, int cond);
  1201. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1202. Parameter | Description
  1203. ------------|-----------------------------------------------------------
  1204. __ctx__ | Must point to an previously initialized `nk_context` struct
  1205. __name__ | Identifier of the window to either collapse or maximize
  1206. __state__ | value out of nk_collapse_states section the window should be put into
  1207. __cond__ | condition that has to be met to actually commit the collapse state change
  1208. #### nk_window_show
  1209. updates visibility state of a window with given name
  1210. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1211. void nk_window_show(struct nk_context*, const char *name, enum nk_show_states);
  1212. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1213. Parameter | Description
  1214. ------------|-----------------------------------------------------------
  1215. __ctx__ | Must point to an previously initialized `nk_context` struct
  1216. __name__ | Identifier of the window to either collapse or maximize
  1217. __state__ | state with either visible or hidden to modify the window with
  1218. #### nk_window_show_if
  1219. Updates visibility state of a window with given name if a given condition is met
  1220. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1221. void nk_window_show_if(struct nk_context*, const char *name, enum nk_show_states, int cond);
  1222. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1223. Parameter | Description
  1224. ------------|-----------------------------------------------------------
  1225. __ctx__ | Must point to an previously initialized `nk_context` struct
  1226. __name__ | Identifier of the window to either hide or show
  1227. __state__ | state with either visible or hidden to modify the window with
  1228. __cond__ | condition that has to be met to actually commit the visbility state change
  1229. ### Layouting
  1230. Layouting in general describes placing widget inside a window with position and size.
  1231. While in this particular implementation there are five different APIs for layouting
  1232. each with different trade offs between control and ease of use. <br /><br />
  1233. All layouting methods in this library are based around the concept of a row.
  1234. A row has a height the window content grows by and a number of columns and each
  1235. layouting method specifies how each widget is placed inside the row.
  1236. After a row has been allocated by calling a layouting functions and then
  1237. filled with widgets will advance an internal pointer over the allocated row. <br /><br />
  1238. To actually define a layout you just call the appropriate layouting function
  1239. and each subsequent widget call will place the widget as specified. Important
  1240. here is that if you define more widgets then columns defined inside the layout
  1241. functions it will allocate the next row without you having to make another layouting <br /><br />
  1242. call.
  1243. Biggest limitation with using all these APIs outside the `nk_layout_space_xxx` API
  1244. is that you have to define the row height for each. However the row height
  1245. often depends on the height of the font. <br /><br />
  1246. To fix that internally nuklear uses a minimum row height that is set to the
  1247. height plus padding of currently active font and overwrites the row height
  1248. value if zero. <br /><br />
  1249. If you manually want to change the minimum row height then
  1250. use nk_layout_set_min_row_height, and use nk_layout_reset_min_row_height to
  1251. reset it back to be derived from font height. <br /><br />
  1252. Also if you change the font in nuklear it will automatically change the minimum
  1253. row height for you and. This means if you change the font but still want
  1254. a minimum row height smaller than the font you have to repush your value. <br /><br />
  1255. For actually more advanced UI I would even recommend using the `nk_layout_space_xxx`
  1256. layouting method in combination with a cassowary constraint solver (there are
  1257. some versions on github with permissive license model) to take over all control over widget
  1258. layouting yourself. However for quick and dirty layouting using all the other layouting
  1259. functions should be fine.
  1260. #### Usage
  1261. 1. __nk_layout_row_dynamic__<br /><br />
  1262. The easiest layouting function is `nk_layout_row_dynamic`. It provides each
  1263. widgets with same horizontal space inside the row and dynamically grows
  1264. if the owning window grows in width. So the number of columns dictates
  1265. the size of each widget dynamically by formula:
  1266. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1267. widget_width = (window_width - padding - spacing) * (1/colum_count)
  1268. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1269. Just like all other layouting APIs if you define more widget than columns this
  1270. library will allocate a new row and keep all layouting parameters previously
  1271. defined.
  1272. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1273. if (nk_begin_xxx(...) {
  1274. // first row with height: 30 composed of two widgets
  1275. nk_layout_row_dynamic(&ctx, 30, 2);
  1276. nk_widget(...);
  1277. nk_widget(...);
  1278. //
  1279. // second row with same parameter as defined above
  1280. nk_widget(...);
  1281. nk_widget(...);
  1282. //
  1283. // third row uses 0 for height which will use auto layouting
  1284. nk_layout_row_dynamic(&ctx, 0, 2);
  1285. nk_widget(...);
  1286. nk_widget(...);
  1287. }
  1288. nk_end(...);
  1289. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1290. 2. __nk_layout_row_static__<br /><br />
  1291. Another easy layouting function is `nk_layout_row_static`. It provides each
  1292. widget with same horizontal pixel width inside the row and does not grow
  1293. if the owning window scales smaller or bigger.
  1294. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1295. if (nk_begin_xxx(...) {
  1296. // first row with height: 30 composed of two widgets with width: 80
  1297. nk_layout_row_static(&ctx, 30, 80, 2);
  1298. nk_widget(...);
  1299. nk_widget(...);
  1300. //
  1301. // second row with same parameter as defined above
  1302. nk_widget(...);
  1303. nk_widget(...);
  1304. //
  1305. // third row uses 0 for height which will use auto layouting
  1306. nk_layout_row_static(&ctx, 0, 80, 2);
  1307. nk_widget(...);
  1308. nk_widget(...);
  1309. }
  1310. nk_end(...);
  1311. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1312. 3. __nk_layout_row_xxx__<br /><br />
  1313. A little bit more advanced layouting API are functions `nk_layout_row_begin`,
  1314. `nk_layout_row_push` and `nk_layout_row_end`. They allow to directly
  1315. specify each column pixel or window ratio in a row. It supports either
  1316. directly setting per column pixel width or widget window ratio but not
  1317. both. Furthermore it is a immediate mode API so each value is directly
  1318. pushed before calling a widget. Therefore the layout is not automatically
  1319. repeating like the last two layouting functions.
  1320. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1321. if (nk_begin_xxx(...) {
  1322. // first row with height: 25 composed of two widgets with width 60 and 40
  1323. nk_layout_row_begin(ctx, NK_STATIC, 25, 2);
  1324. nk_layout_row_push(ctx, 60);
  1325. nk_widget(...);
  1326. nk_layout_row_push(ctx, 40);
  1327. nk_widget(...);
  1328. nk_layout_row_end(ctx);
  1329. //
  1330. // second row with height: 25 composed of two widgets with window ratio 0.25 and 0.75
  1331. nk_layout_row_begin(ctx, NK_DYNAMIC, 25, 2);
  1332. nk_layout_row_push(ctx, 0.25f);
  1333. nk_widget(...);
  1334. nk_layout_row_push(ctx, 0.75f);
  1335. nk_widget(...);
  1336. nk_layout_row_end(ctx);
  1337. //
  1338. // third row with auto generated height: composed of two widgets with window ratio 0.25 and 0.75
  1339. nk_layout_row_begin(ctx, NK_DYNAMIC, 0, 2);
  1340. nk_layout_row_push(ctx, 0.25f);
  1341. nk_widget(...);
  1342. nk_layout_row_push(ctx, 0.75f);
  1343. nk_widget(...);
  1344. nk_layout_row_end(ctx);
  1345. }
  1346. nk_end(...);
  1347. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1348. 4. __nk_layout_row__<br /><br />
  1349. The array counterpart to API nk_layout_row_xxx is the single nk_layout_row
  1350. functions. Instead of pushing either pixel or window ratio for every widget
  1351. it allows to define it by array. The trade of for less control is that
  1352. `nk_layout_row` is automatically repeating. Otherwise the behavior is the
  1353. same.
  1354. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1355. if (nk_begin_xxx(...) {
  1356. // two rows with height: 30 composed of two widgets with width 60 and 40
  1357. const float size[] = {60,40};
  1358. nk_layout_row(ctx, NK_STATIC, 30, 2, ratio);
  1359. nk_widget(...);
  1360. nk_widget(...);
  1361. nk_widget(...);
  1362. nk_widget(...);
  1363. //
  1364. // two rows with height: 30 composed of two widgets with window ratio 0.25 and 0.75
  1365. const float ratio[] = {0.25, 0.75};
  1366. nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratio);
  1367. nk_widget(...);
  1368. nk_widget(...);
  1369. nk_widget(...);
  1370. nk_widget(...);
  1371. //
  1372. // two rows with auto generated height composed of two widgets with window ratio 0.25 and 0.75
  1373. const float ratio[] = {0.25, 0.75};
  1374. nk_layout_row(ctx, NK_DYNAMIC, 30, 2, ratio);
  1375. nk_widget(...);
  1376. nk_widget(...);
  1377. nk_widget(...);
  1378. nk_widget(...);
  1379. }
  1380. nk_end(...);
  1381. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1382. 5. __nk_layout_row_template_xxx__<br /><br />
  1383. The most complex and second most flexible API is a simplified flexbox version without
  1384. line wrapping and weights for dynamic widgets. It is an immediate mode API but
  1385. unlike `nk_layout_row_xxx` it has auto repeat behavior and needs to be called
  1386. before calling the templated widgets.
  1387. The row template layout has three different per widget size specifier. The first
  1388. one is the `nk_layout_row_template_push_static` with fixed widget pixel width.
  1389. They do not grow if the row grows and will always stay the same.
  1390. The second size specifier is `nk_layout_row_template_push_variable`
  1391. which defines a minimum widget size but it also can grow if more space is available
  1392. not taken by other widgets.
  1393. Finally there are dynamic widgets with `nk_layout_row_template_push_dynamic`
  1394. which are completely flexible and unlike variable widgets can even shrink
  1395. to zero if not enough space is provided.
  1396. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1397. if (nk_begin_xxx(...) {
  1398. // two rows with height: 30 composed of three widgets
  1399. nk_layout_row_template_begin(ctx, 30);
  1400. nk_layout_row_template_push_dynamic(ctx);
  1401. nk_layout_row_template_push_variable(ctx, 80);
  1402. nk_layout_row_template_push_static(ctx, 80);
  1403. nk_layout_row_template_end(ctx);
  1404. //
  1405. // first row
  1406. nk_widget(...); // dynamic widget can go to zero if not enough space
  1407. nk_widget(...); // variable widget with min 80 pixel but can grow bigger if enough space
  1408. nk_widget(...); // static widget with fixed 80 pixel width
  1409. //
  1410. // second row same layout
  1411. nk_widget(...);
  1412. nk_widget(...);
  1413. nk_widget(...);
  1414. }
  1415. nk_end(...);
  1416. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1417. 6. __nk_layout_space_xxx__<br /><br />
  1418. Finally the most flexible API directly allows you to place widgets inside the
  1419. window. The space layout API is an immediate mode API which does not support
  1420. row auto repeat and directly sets position and size of a widget. Position
  1421. and size hereby can be either specified as ratio of allocated space or
  1422. allocated space local position and pixel size. Since this API is quite
  1423. powerful there are a number of utility functions to get the available space
  1424. and convert between local allocated space and screen space.
  1425. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1426. if (nk_begin_xxx(...) {
  1427. // static row with height: 500 (you can set column count to INT_MAX if you don't want to be bothered)
  1428. nk_layout_space_begin(ctx, NK_STATIC, 500, INT_MAX);
  1429. nk_layout_space_push(ctx, nk_rect(0,0,150,200));
  1430. nk_widget(...);
  1431. nk_layout_space_push(ctx, nk_rect(200,200,100,200));
  1432. nk_widget(...);
  1433. nk_layout_space_end(ctx);
  1434. //
  1435. // dynamic row with height: 500 (you can set column count to INT_MAX if you don't want to be bothered)
  1436. nk_layout_space_begin(ctx, NK_DYNAMIC, 500, INT_MAX);
  1437. nk_layout_space_push(ctx, nk_rect(0.5,0.5,0.1,0.1));
  1438. nk_widget(...);
  1439. nk_layout_space_push(ctx, nk_rect(0.7,0.6,0.1,0.1));
  1440. nk_widget(...);
  1441. }
  1442. nk_end(...);
  1443. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1444. #### Reference
  1445. Function | Description
  1446. ----------------------------------------|------------------------------------
  1447. nk_layout_set_min_row_height | Set the currently used minimum row height to a specified value
  1448. nk_layout_reset_min_row_height | Resets the currently used minimum row height to font height
  1449. nk_layout_widget_bounds | Calculates current width a static layout row can fit inside a window
  1450. nk_layout_ratio_from_pixel | Utility functions to calculate window ratio from pixel size
  1451. nk_layout_row_dynamic | Current layout is divided into n same sized growing columns
  1452. nk_layout_row_static | Current layout is divided into n same fixed sized columns
  1453. nk_layout_row_begin | Starts a new row with given height and number of columns
  1454. nk_layout_row_push | Pushes another column with given size or window ratio
  1455. nk_layout_row_end | Finished previously started row
  1456. nk_layout_row | Specifies row columns in array as either window ratio or size
  1457. nk_layout_row_template_begin | Begins the row template declaration
  1458. nk_layout_row_template_push_dynamic | Adds a dynamic column that dynamically grows and can go to zero if not enough space
  1459. nk_layout_row_template_push_variable | Adds a variable column that dynamically grows but does not shrink below specified pixel width
  1460. nk_layout_row_template_push_static | Adds a static column that does not grow and will always have the same size
  1461. nk_layout_row_template_end | Marks the end of the row template
  1462. nk_layout_space_begin | Begins a new layouting space that allows to specify each widgets position and size
  1463. nk_layout_space_push | Pushes position and size of the next widget in own coordinate space either as pixel or ratio
  1464. nk_layout_space_end | Marks the end of the layouting space
  1465. nk_layout_space_bounds | Callable after nk_layout_space_begin and returns total space allocated
  1466. nk_layout_space_to_screen | Converts vector from nk_layout_space coordinate space into screen space
  1467. nk_layout_space_to_local | Converts vector from screen space into nk_layout_space coordinates
  1468. nk_layout_space_rect_to_screen | Converts rectangle from nk_layout_space coordinate space into screen space
  1469. nk_layout_space_rect_to_local | Converts rectangle from screen space into nk_layout_space coordinates
  1470. #### nk_layout_set_min_row_height
  1471. Sets the currently used minimum row height.
  1472. !!! WARNING
  1473. The passed height needs to include both your preferred row height
  1474. as well as padding. No internal padding is added.
  1475. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1476. void nk_layout_set_min_row_height(struct nk_context*, float height);
  1477. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1478. Parameter | Description
  1479. ------------|-----------------------------------------------------------
  1480. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1481. __height__ | New minimum row height to be used for auto generating the row height
  1482. #### nk_layout_reset_min_row_height
  1483. Reset the currently used minimum row height back to `font_height + text_padding + padding`
  1484. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1485. void nk_layout_reset_min_row_height(struct nk_context*);
  1486. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1487. Parameter | Description
  1488. ------------|-----------------------------------------------------------
  1489. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1490. #### nk_layout_widget_bounds
  1491. Returns the width of the next row allocate by one of the layouting functions
  1492. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1493. struct nk_rect nk_layout_widget_bounds(struct nk_context*);
  1494. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1495. Parameter | Description
  1496. ------------|-----------------------------------------------------------
  1497. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1498. Return `nk_rect` with both position and size of the next row
  1499. #### nk_layout_ratio_from_pixel
  1500. Utility functions to calculate window ratio from pixel size
  1501. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1502. float nk_layout_ratio_from_pixel(struct nk_context*, float pixel_width);
  1503. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1504. Parameter | Description
  1505. ------------|-----------------------------------------------------------
  1506. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1507. __pixel__ | Pixel_width to convert to window ratio
  1508. Returns `nk_rect` with both position and size of the next row
  1509. #### nk_layout_row_dynamic
  1510. Sets current row layout to share horizontal space
  1511. between @cols number of widgets evenly. Once called all subsequent widget
  1512. calls greater than @cols will allocate a new row with same layout.
  1513. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1514. void nk_layout_row_dynamic(struct nk_context *ctx, float height, int cols);
  1515. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1516. Parameter | Description
  1517. ------------|-----------------------------------------------------------
  1518. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1519. __height__ | Holds height of each widget in row or zero for auto layouting
  1520. __columns__ | Number of widget inside row
  1521. #### nk_layout_row_dynamic
  1522. Sets current row layout to fill @cols number of widgets
  1523. in row with same @item_width horizontal size. Once called all subsequent widget
  1524. calls greater than @cols will allocate a new row with same layout.
  1525. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1526. void nk_layout_row_static(struct nk_context *ctx, float height, int item_width, int cols);
  1527. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1528. Parameter | Description
  1529. ------------|-----------------------------------------------------------
  1530. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1531. __height__ | Holds height of each widget in row or zero for auto layouting
  1532. __width__ | Holds pixel width of each widget in the row
  1533. __columns__ | Number of widget inside row
  1534. #### nk_layout_row_begin
  1535. Starts a new dynamic or fixed row with given height and columns.
  1536. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1537. void nk_layout_row_begin(struct nk_context *ctx, enum nk_layout_format fmt, float row_height, int cols);
  1538. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1539. Parameter | Description
  1540. ------------|-----------------------------------------------------------
  1541. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1542. __fmt__ | either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns
  1543. __height__ | holds height of each widget in row or zero for auto layouting
  1544. __columns__ | Number of widget inside row
  1545. #### nk_layout_row_push
  1546. Specifies either window ratio or width of a single column
  1547. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1548. void nk_layout_row_push(struct nk_context*, float value);
  1549. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1550. Parameter | Description
  1551. ------------|-----------------------------------------------------------
  1552. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1553. __value__ | either a window ratio or fixed width depending on @fmt in previous `nk_layout_row_begin` call
  1554. #### nk_layout_row_end
  1555. Finished previously started row
  1556. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1557. void nk_layout_row_end(struct nk_context*);
  1558. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1559. Parameter | Description
  1560. ------------|-----------------------------------------------------------
  1561. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1562. #### nk_layout_row
  1563. Specifies row columns in array as either window ratio or size
  1564. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1565. void nk_layout_row(struct nk_context*, enum nk_layout_format, float height, int cols, const float *ratio);
  1566. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1567. Parameter | Description
  1568. ------------|-----------------------------------------------------------
  1569. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1570. __fmt__ | Either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns
  1571. __height__ | Holds height of each widget in row or zero for auto layouting
  1572. __columns__ | Number of widget inside row
  1573. #### nk_layout_row_template_begin
  1574. Begins the row template declaration
  1575. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1576. void nk_layout_row_template_begin(struct nk_context*, float row_height);
  1577. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1578. Parameter | Description
  1579. ------------|-----------------------------------------------------------
  1580. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1581. __height__ | Holds height of each widget in row or zero for auto layouting
  1582. #### nk_layout_row_template_push_dynamic
  1583. Adds a dynamic column that dynamically grows and can go to zero if not enough space
  1584. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1585. void nk_layout_row_template_push_dynamic(struct nk_context*);
  1586. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1587. Parameter | Description
  1588. ------------|-----------------------------------------------------------
  1589. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1590. __height__ | Holds height of each widget in row or zero for auto layouting
  1591. #### nk_layout_row_template_push_variable
  1592. Adds a variable column that dynamically grows but does not shrink below specified pixel width
  1593. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1594. void nk_layout_row_template_push_variable(struct nk_context*, float min_width);
  1595. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1596. Parameter | Description
  1597. ------------|-----------------------------------------------------------
  1598. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1599. __width__ | Holds the minimum pixel width the next column must always be
  1600. #### nk_layout_row_template_push_static
  1601. Adds a static column that does not grow and will always have the same size
  1602. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1603. void nk_layout_row_template_push_static(struct nk_context*, float width);
  1604. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1605. Parameter | Description
  1606. ------------|-----------------------------------------------------------
  1607. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1608. __width__ | Holds the absolute pixel width value the next column must be
  1609. #### nk_layout_row_template_end
  1610. Marks the end of the row template
  1611. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1612. void nk_layout_row_template_end(struct nk_context*);
  1613. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1614. Parameter | Description
  1615. ------------|-----------------------------------------------------------
  1616. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1617. #### nk_layout_space_begin
  1618. Begins a new layouting space that allows to specify each widgets position and size.
  1619. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1620. void nk_layout_space_begin(struct nk_context*, enum nk_layout_format, float height, int widget_count);
  1621. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1622. Parameter | Description
  1623. ------------|-----------------------------------------------------------
  1624. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_begin_xxx`
  1625. __fmt__ | Either `NK_DYNAMIC` for window ratio or `NK_STATIC` for fixed size columns
  1626. __height__ | Holds height of each widget in row or zero for auto layouting
  1627. __columns__ | Number of widgets inside row
  1628. #### nk_layout_space_push
  1629. Pushes position and size of the next widget in own coordinate space either as pixel or ratio
  1630. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1631. void nk_layout_space_push(struct nk_context *ctx, struct nk_rect bounds);
  1632. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1633. Parameter | Description
  1634. ------------|-----------------------------------------------------------
  1635. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
  1636. __bounds__ | Position and size in laoyut space local coordinates
  1637. #### nk_layout_space_end
  1638. Marks the end of the layout space
  1639. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1640. void nk_layout_space_end(struct nk_context*);
  1641. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1642. Parameter | Description
  1643. ------------|-----------------------------------------------------------
  1644. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
  1645. #### nk_layout_space_bounds
  1646. Utility function to calculate total space allocated for `nk_layout_space`
  1647. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1648. struct nk_rect nk_layout_space_bounds(struct nk_context*);
  1649. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1650. Parameter | Description
  1651. ------------|-----------------------------------------------------------
  1652. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
  1653. Returns `nk_rect` holding the total space allocated
  1654. #### nk_layout_space_to_screen
  1655. Converts vector from nk_layout_space coordinate space into screen space
  1656. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1657. struct nk_vec2 nk_layout_space_to_screen(struct nk_context*, struct nk_vec2);
  1658. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1659. Parameter | Description
  1660. ------------|-----------------------------------------------------------
  1661. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
  1662. __vec__ | Position to convert from layout space into screen coordinate space
  1663. Returns transformed `nk_vec2` in screen space coordinates
  1664. #### nk_layout_space_to_screen
  1665. Converts vector from layout space into screen space
  1666. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1667. struct nk_vec2 nk_layout_space_to_local(struct nk_context*, struct nk_vec2);
  1668. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1669. Parameter | Description
  1670. ------------|-----------------------------------------------------------
  1671. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
  1672. __vec__ | Position to convert from screen space into layout coordinate space
  1673. Returns transformed `nk_vec2` in layout space coordinates
  1674. #### nk_layout_space_rect_to_screen
  1675. Converts rectangle from screen space into layout space
  1676. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1677. struct nk_rect nk_layout_space_rect_to_screen(struct nk_context*, struct nk_rect);
  1678. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1679. Parameter | Description
  1680. ------------|-----------------------------------------------------------
  1681. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
  1682. __bounds__ | Rectangle to convert from layout space into screen space
  1683. Returns transformed `nk_rect` in screen space coordinates
  1684. #### nk_layout_space_rect_to_local
  1685. Converts rectangle from layout space into screen space
  1686. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1687. struct nk_rect nk_layout_space_rect_to_local(struct nk_context*, struct nk_rect);
  1688. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1689. Parameter | Description
  1690. ------------|-----------------------------------------------------------
  1691. __ctx__ | Must point to an previously initialized `nk_context` struct after call `nk_layout_space_begin`
  1692. __bounds__ | Rectangle to convert from layout space into screen space
  1693. Returns transformed `nk_rect` in layout space coordinates
  1694. ### Groups
  1695. Groups are basically windows inside windows. They allow to subdivide space
  1696. in a window to layout widgets as a group. Almost all more complex widget
  1697. layouting requirements can be solved using groups and basic layouting
  1698. fuctionality. Groups just like windows are identified by an unique name and
  1699. internally keep track of scrollbar offsets by default. However additional
  1700. versions are provided to directly manage the scrollbar.
  1701. #### Usage
  1702. To create a group you have to call one of the three `nk_group_begin_xxx`
  1703. functions to start group declarations and `nk_group_end` at the end. Furthermore it
  1704. is required to check the return value of `nk_group_begin_xxx` and only process
  1705. widgets inside the window if the value is not 0.
  1706. Nesting groups is possible and even encouraged since many layouting schemes
  1707. can only be achieved by nesting. Groups, unlike windows, need `nk_group_end`
  1708. to be only called if the corosponding `nk_group_begin_xxx` call does not return 0:
  1709. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1710. if (nk_group_begin_xxx(ctx, ...) {
  1711. // [... widgets ...]
  1712. nk_group_end(ctx);
  1713. }
  1714. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1715. In the grand concept groups can be called after starting a window
  1716. with `nk_begin_xxx` and before calling `nk_end`:
  1717. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1718. struct nk_context ctx;
  1719. nk_init_xxx(&ctx, ...);
  1720. while (1) {
  1721. // Input
  1722. Event evt;
  1723. nk_input_begin(&ctx);
  1724. while (GetEvent(&evt)) {
  1725. if (evt.type == MOUSE_MOVE)
  1726. nk_input_motion(&ctx, evt.motion.x, evt.motion.y);
  1727. else if (evt.type == [...]) {
  1728. nk_input_xxx(...);
  1729. }
  1730. }
  1731. nk_input_end(&ctx);
  1732. //
  1733. // Window
  1734. if (nk_begin_xxx(...) {
  1735. // [...widgets...]
  1736. nk_layout_row_dynamic(...);
  1737. if (nk_group_begin_xxx(ctx, ...) {
  1738. //[... widgets ...]
  1739. nk_group_end(ctx);
  1740. }
  1741. }
  1742. nk_end(ctx);
  1743. //
  1744. // Draw
  1745. const struct nk_command *cmd = 0;
  1746. nk_foreach(cmd, &ctx) {
  1747. switch (cmd->type) {
  1748. case NK_COMMAND_LINE:
  1749. your_draw_line_function(...)
  1750. break;
  1751. case NK_COMMAND_RECT
  1752. your_draw_rect_function(...)
  1753. break;
  1754. case ...:
  1755. // [...]
  1756. }
  1757. }
  1758. nk_free(&ctx);
  1759. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1760. #### Reference
  1761. Function | Description
  1762. --------------------------------|-------------------------------------------
  1763. nk_group_begin | Start a new group with internal scrollbar handling
  1764. nk_group_begin_titled | Start a new group with separeted name and title and internal scrollbar handling
  1765. nk_group_end | Ends a group. Should only be called if nk_group_begin returned non-zero
  1766. nk_group_scrolled_offset_begin | Start a new group with manual separated handling of scrollbar x- and y-offset
  1767. nk_group_scrolled_begin | Start a new group with manual scrollbar handling
  1768. nk_group_scrolled_end | Ends a group with manual scrollbar handling. Should only be called if nk_group_begin returned non-zero
  1769. #### nk_group_begin
  1770. Starts a new widget group. Requires a previous layouting function to specify a pos/size.
  1771. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1772. int nk_group_begin(struct nk_context*, const char *title, nk_flags);
  1773. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1774. Parameter | Description
  1775. ------------|-----------------------------------------------------------
  1776. __ctx__ | Must point to an previously initialized `nk_context` struct
  1777. __title__ | Must be an unique identifier for this group that is also used for the group header
  1778. __flags__ | Window flags defined in the nk_panel_flags section with a number of different group behaviors
  1779. Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
  1780. #### nk_group_begin_titled
  1781. Starts a new widget group. Requires a previous layouting function to specify a pos/size.
  1782. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1783. int nk_group_begin_titled(struct nk_context*, const char *name, const char *title, nk_flags);
  1784. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1785. Parameter | Description
  1786. ------------|-----------------------------------------------------------
  1787. __ctx__ | Must point to an previously initialized `nk_context` struct
  1788. __id__ | Must be an unique identifier for this group
  1789. __title__ | Group header title
  1790. __flags__ | Window flags defined in the nk_panel_flags section with a number of different group behaviors
  1791. Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
  1792. #### nk_group_end
  1793. Ends a widget group
  1794. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1795. void nk_group_end(struct nk_context*);
  1796. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1797. Parameter | Description
  1798. ------------|-----------------------------------------------------------
  1799. __ctx__ | Must point to an previously initialized `nk_context` struct
  1800. #### nk_group_scrolled_offset_begin
  1801. starts a new widget group. requires a previous layouting function to specify
  1802. a size. Does not keep track of scrollbar.
  1803. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1804. int nk_group_scrolled_offset_begin(struct nk_context*, nk_uint *x_offset, nk_uint *y_offset, const char *title, nk_flags flags);
  1805. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1806. Parameter | Description
  1807. ------------|-----------------------------------------------------------
  1808. __ctx__ | Must point to an previously initialized `nk_context` struct
  1809. __x_offset__| Scrollbar x-offset to offset all widgets inside the group horizontally.
  1810. __y_offset__| Scrollbar y-offset to offset all widgets inside the group vertically
  1811. __title__ | Window unique group title used to both identify and display in the group header
  1812. __flags__ | Window flags from the nk_panel_flags section
  1813. Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
  1814. #### nk_group_scrolled_begin
  1815. Starts a new widget group. requires a previous
  1816. layouting function to specify a size. Does not keep track of scrollbar.
  1817. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1818. int nk_group_scrolled_begin(struct nk_context*, struct nk_scroll *off, const char *title, nk_flags);
  1819. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1820. Parameter | Description
  1821. ------------|-----------------------------------------------------------
  1822. __ctx__ | Must point to an previously initialized `nk_context` struct
  1823. __off__ | Both x- and y- scroll offset. Allows for manual scrollbar control
  1824. __title__ | Window unique group title used to both identify and display in the group header
  1825. __flags__ | Window flags from nk_panel_flags section
  1826. Returns `true(1)` if visible and fillable with widgets or `false(0)` otherwise
  1827. #### nk_group_scrolled_end
  1828. Ends a widget group after calling nk_group_scrolled_offset_begin or nk_group_scrolled_begin.
  1829. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1830. void nk_group_scrolled_end(struct nk_context*);
  1831. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1832. Parameter | Description
  1833. ------------|-----------------------------------------------------------
  1834. __ctx__ | Must point to an previously initialized `nk_context` struct
  1835. ### Tree
  1836. Trees represent two different concept. First the concept of a collapsable
  1837. UI section that can be either in a hidden or visibile state. They allow the UI
  1838. user to selectively minimize the current set of visible UI to comprehend.
  1839. The second concept are tree widgets for visual UI representation of trees.<br /><br />
  1840. Trees thereby can be nested for tree representations and multiple nested
  1841. collapsable UI sections. All trees are started by calling of the
  1842. `nk_tree_xxx_push_tree` functions and ended by calling one of the
  1843. `nk_tree_xxx_pop_xxx()` functions. Each starting functions takes a title label
  1844. and optionally an image to be displayed and the initial collapse state from
  1845. the nk_collapse_states section.<br /><br />
  1846. The runtime state of the tree is either stored outside the library by the caller
  1847. or inside which requires a unique ID. The unique ID can either be generated
  1848. automatically from `__FILE__` and `__LINE__` with function `nk_tree_push`,
  1849. by `__FILE__` and a user provided ID generated for example by loop index with
  1850. function `nk_tree_push_id` or completely provided from outside by user with
  1851. function `nk_tree_push_hashed`.
  1852. #### Usage
  1853. To create a tree you have to call one of the seven `nk_tree_xxx_push_xxx`
  1854. functions to start a collapsable UI section and `nk_tree_xxx_pop` to mark the
  1855. end.
  1856. Each starting function will either return `false(0)` if the tree is collapsed
  1857. or hidden and therefore does not need to be filled with content or `true(1)`
  1858. if visible and required to be filled.
  1859. !!! Note
  1860. The tree header does not require and layouting function and instead
  1861. calculates a auto height based on the currently used font size
  1862. The tree ending functions only need to be called if the tree content is
  1863. actually visible. So make sure the tree push function is guarded by `if`
  1864. and the pop call is only taken if the tree is visible.
  1865. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1866. if (nk_tree_push(ctx, NK_TREE_TAB, "Tree", NK_MINIMIZED)) {
  1867. nk_layout_row_dynamic(...);
  1868. nk_widget(...);
  1869. nk_tree_pop(ctx);
  1870. }
  1871. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1872. #### Reference
  1873. Function | Description
  1874. ----------------------------|-------------------------------------------
  1875. nk_tree_push | Start a collapsable UI section with internal state management
  1876. nk_tree_push_id | Start a collapsable UI section with internal state management callable in a look
  1877. nk_tree_push_hashed | Start a collapsable UI section with internal state management with full control over internal unique ID use to store state
  1878. nk_tree_image_push | Start a collapsable UI section with image and label header
  1879. nk_tree_image_push_id | Start a collapsable UI section with image and label header and internal state management callable in a look
  1880. nk_tree_image_push_hashed | Start a collapsable UI section with image and label header and internal state management with full control over internal unique ID use to store state
  1881. nk_tree_pop | Ends a collapsable UI section
  1882. nk_tree_state_push | Start a collapsable UI section with external state management
  1883. nk_tree_state_image_push | Start a collapsable UI section with image and label header and external state management
  1884. nk_tree_state_pop | Ends a collapsabale UI section
  1885. #### nk_tree_type
  1886. Flag | Description
  1887. ----------------|----------------------------------------
  1888. NK_TREE_NODE | Highlighted tree header to mark a collapsable UI section
  1889. NK_TREE_TAB | Non-highighted tree header closer to tree representations
  1890. #### nk_tree_push
  1891. Starts a collapsable UI section with internal state management
  1892. !!! WARNING
  1893. To keep track of the runtime tree collapsable state this function uses
  1894. defines `__FILE__` and `__LINE__` to generate a unique ID. If you want
  1895. to call this function in a loop please use `nk_tree_push_id` or
  1896. `nk_tree_push_hashed` instead.
  1897. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1898. #define nk_tree_push(ctx, type, title, state)
  1899. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1900. Parameter | Description
  1901. ------------|-----------------------------------------------------------
  1902. __ctx__ | Must point to an previously initialized `nk_context` struct
  1903. __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
  1904. __title__ | Label printed in the tree header
  1905. __state__ | Initial tree state value out of nk_collapse_states
  1906. #### nk_tree_push_id
  1907. Starts a collapsable UI section with internal state management callable in a look
  1908. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1909. #define nk_tree_push_id(ctx, type, title, state, id)
  1910. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1911. Parameter | Description
  1912. ------------|-----------------------------------------------------------
  1913. __ctx__ | Must point to an previously initialized `nk_context` struct
  1914. __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
  1915. __title__ | Label printed in the tree header
  1916. __state__ | Initial tree state value out of nk_collapse_states
  1917. __id__ | Loop counter index if this function is called in a loop
  1918. #### nk_tree_push_hashed
  1919. Start a collapsable UI section with internal state management with full
  1920. control over internal unique ID used to store state
  1921. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1922. int 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);
  1923. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1924. Parameter | Description
  1925. ------------|-----------------------------------------------------------
  1926. __ctx__ | Must point to an previously initialized `nk_context` struct
  1927. __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
  1928. __title__ | Label printed in the tree header
  1929. __state__ | Initial tree state value out of nk_collapse_states
  1930. __hash__ | Memory block or string to generate the ID from
  1931. __len__ | Size of passed memory block or string in __hash__
  1932. __seed__ | Seeding value if this function is called in a loop or default to `0`
  1933. #### nk_tree_image_push
  1934. Start a collapsable UI section with image and label header
  1935. !!! WARNING
  1936. To keep track of the runtime tree collapsable state this function uses
  1937. defines `__FILE__` and `__LINE__` to generate a unique ID. If you want
  1938. to call this function in a loop please use `nk_tree_image_push_id` or
  1939. `nk_tree_image_push_hashed` instead.
  1940. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1941. #define nk_tree_image_push(ctx, type, img, title, state)
  1942. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1943. Parameter | Description
  1944. ------------|-----------------------------------------------------------
  1945. __ctx__ | Must point to an previously initialized `nk_context` struct
  1946. __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
  1947. __img__ | Image to display inside the header on the left of the label
  1948. __title__ | Label printed in the tree header
  1949. __state__ | Initial tree state value out of nk_collapse_states
  1950. #### nk_tree_image_push_id
  1951. Start a collapsable UI section with image and label header and internal state
  1952. management callable in a look
  1953. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1954. #define nk_tree_image_push_id(ctx, type, img, title, state, id)
  1955. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1956. Parameter | Description
  1957. ------------|-----------------------------------------------------------
  1958. __ctx__ | Must point to an previously initialized `nk_context` struct
  1959. __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
  1960. __img__ | Image to display inside the header on the left of the label
  1961. __title__ | Label printed in the tree header
  1962. __state__ | Initial tree state value out of nk_collapse_states
  1963. __id__ | Loop counter index if this function is called in a loop
  1964. #### nk_tree_image_push_hashed
  1965. Start a collapsable UI section with internal state management with full
  1966. control over internal unique ID used to store state
  1967. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1968. int 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);
  1969. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1970. Parameter | Description
  1971. ------------|-----------------------------------------------------------
  1972. __ctx__ | Must point to an previously initialized `nk_context` struct
  1973. __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
  1974. __img__ | Image to display inside the header on the left of the label
  1975. __title__ | Label printed in the tree header
  1976. __state__ | Initial tree state value out of nk_collapse_states
  1977. __hash__ | Memory block or string to generate the ID from
  1978. __len__ | Size of passed memory block or string in __hash__
  1979. __seed__ | Seeding value if this function is called in a loop or default to `0`
  1980. #### nk_tree_pop
  1981. Ends a collapsabale UI section
  1982. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1983. void nk_tree_pop(struct nk_context*);
  1984. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1985. Parameter | Description
  1986. ------------|-----------------------------------------------------------
  1987. __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx`
  1988. #### nk_tree_state_push
  1989. Start a collapsable UI section with external state management
  1990. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  1991. int nk_tree_state_push(struct nk_context*, enum nk_tree_type, const char *title, enum nk_collapse_states *state);
  1992. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1993. Parameter | Description
  1994. ------------|-----------------------------------------------------------
  1995. __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx`
  1996. __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
  1997. __title__ | Label printed in the tree header
  1998. __state__ | Persistent state to update
  1999. #### nk_tree_state_image_push
  2000. Start a collapsable UI section with image and label header and external state management
  2001. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  2002. int nk_tree_state_image_push(struct nk_context*, enum nk_tree_type, struct nk_image, const char *title, enum nk_collapse_states *state);
  2003. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2004. Parameter | Description
  2005. ------------|-----------------------------------------------------------
  2006. __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx`
  2007. __img__ | Image to display inside the header on the left of the label
  2008. __type__ | Value from the nk_tree_type section to visually mark a tree node header as either a collapseable UI section or tree node
  2009. __title__ | Label printed in the tree header
  2010. __state__ | Persistent state to update
  2011. #### nk_tree_state_pop
  2012. Ends a collapsabale UI section
  2013. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~c
  2014. void nk_tree_state_pop(struct nk_context*);
  2015. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2016. Parameter | Description
  2017. ------------|-----------------------------------------------------------
  2018. __ctx__ | Must point to an previously initialized `nk_context` struct after calling `nk_tree_xxx_push_xxx`
  2019. scores --------- */
  2020. -XXX.XXX- X...X - X...X -X....X - X....X"
  2021. X...XXXXXXXXXXXXX...X - "
  2022. Offset --*/
  2023. ## License
  2024. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~none
  2025. ------------------------------------------------------------------------------
  2026. This software is available under 2 licenses -- choose whichever you prefer.
  2027. ------------------------------------------------------------------------------
  2028. ALTERNATIVE A - MIT License
  2029. Copyright (c) 2016-2018 Micha Mettke
  2030. Permission is hereby granted, free of charge, to any person obtaining a copy of
  2031. this software and associated documentation files (the "Software"), to deal in
  2032. the Software without restriction, including without limitation the rights to
  2033. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  2034. of the Software, and to permit persons to whom the Software is furnished to do
  2035. so, subject to the following conditions:
  2036. The above copyright notice and this permission notice shall be included in all
  2037. copies or substantial portions of the Software.
  2038. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  2039. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2040. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  2041. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  2042. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  2043. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  2044. SOFTWARE.
  2045. ------------------------------------------------------------------------------
  2046. ALTERNATIVE B - Public Domain (www.unlicense.org)
  2047. This is free and unencumbered software released into the public domain.
  2048. Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
  2049. software, either in source code form or as a compiled binary, for any purpose,
  2050. commercial or non-commercial, and by any means.
  2051. In jurisdictions that recognize copyright laws, the author or authors of this
  2052. software dedicate any and all copyright interest in the software to the public
  2053. domain. We make this dedication for the benefit of the public at large and to
  2054. the detriment of our heirs and successors. We intend this dedication to be an
  2055. overt act of relinquishment in perpetuity of all present and future rights to
  2056. this software under copyright law.
  2057. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  2058. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  2059. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  2060. AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  2061. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  2062. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  2063. ------------------------------------------------------------------------------
  2064. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2065. ## Changelog
  2066. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~none
  2067. [date][x.yy.zz]-[description]
  2068. -[date]: date on which the change has been pushed
  2069. -[x.yy.zz]: Numerical version string representation. Each version number on the right
  2070. resets back to zero if version on the left is incremented.
  2071. - [x]: Major version with API and library breaking
  2072. - [yy]: Minor version with non-breaking API and library changes
  2073. - [zz]: Bug fix version with no direct changes to API
  2074. - 2017/01/12 (3.00.2) - Added `nk_group_begin_titled` for separed group identifier and title
  2075. - 2017/01/07 (3.00.1) - Started to change documentation style
  2076. - 2017/01/05 (3.00.0) - BREAKING CHANGE: The previous color picker API was broken
  2077. because of conversions between float and byte color representation.
  2078. Color pickers now use floating point values to represent
  2079. HSV values. To get back the old behavior I added some additional
  2080. color conversion functions to cast between nk_color and
  2081. nk_colorf.
  2082. - 2017/12/23 (2.00.7) - Fixed small warning
  2083. - 2017/12/23 (2.00.7) - Fixed nk_edit_buffer behavior if activated to allow input
  2084. - 2017/12/23 (2.00.7) - Fixed modifyable progressbar dragging visuals and input behavior
  2085. - 2017/12/04 (2.00.6) - Added formated string tooltip widget
  2086. - 2017/11/18 (2.00.5) - Fixed window becoming hidden with flag NK_WINDOW_NO_INPUT
  2087. - 2017/11/15 (2.00.4) - Fixed font merging
  2088. - 2017/11/07 (2.00.3) - Fixed window size and position modifier functions
  2089. - 2017/09/14 (2.00.2) - Fixed nk_edit_buffer and nk_edit_focus behavior
  2090. - 2017/09/14 (2.00.1) - Fixed window closing behavior
  2091. - 2017/09/14 (2.00.0) - BREAKING CHANGE: Modifing window position and size funtions now
  2092. require the name of the window and must happen outside the window
  2093. building process (between function call nk_begin and nk_end).
  2094. - 2017/09/11 (1.40.9) - Fixed window background flag if background window is declared last
  2095. - 2017/08/27 (1.40.8) - Fixed `nk_item_is_any_active` for hidden windows
  2096. - 2017/08/27 (1.40.7) - Fixed window background flag
  2097. - 2017/07/07 (1.40.6) - Fixed missing clipping rect check for hovering/clicked
  2098. query for widgets
  2099. - 2017/07/07 (1.40.5) - Fixed drawing bug for vertex output for lines and stroked
  2100. and filled rectangles
  2101. - 2017/07/07 (1.40.4) - Fixed bug in nk_convert trying to add windows that are in
  2102. process of being destroyed.
  2103. - 2017/07/07 (1.40.3) - Fixed table internal bug caused by storing table size in
  2104. window instead of directly in table.
  2105. - 2017/06/30 (1.40.2) - Removed unneeded semicolon in C++ NK_ALIGNOF macro
  2106. - 2017/06/30 (1.40.1) - Fixed drawing lines smaller or equal zero
  2107. - 2017/06/08 (1.40.0) - Removed the breaking part of last commit. Auto layout now only
  2108. comes in effect if you pass in zero was row height argument
  2109. - 2017/06/08 (1.40.0) - BREAKING CHANGE: while not directly API breaking it will change
  2110. how layouting works. From now there will be an internal minimum
  2111. row height derived from font height. If you need a row smaller than
  2112. that you can directly set it by `nk_layout_set_min_row_height` and
  2113. reset the value back by calling `nk_layout_reset_min_row_height.
  2114. - 2017/06/08 (1.39.1) - Fixed property text edit handling bug caused by past `nk_widget` fix
  2115. - 2017/06/08 (1.39.0) - Added function to retrieve window space without calling a nk_layout_xxx function
  2116. - 2017/06/06 (1.38.5) - Fixed `nk_convert` return flag for command buffer
  2117. - 2017/05/23 (1.38.4) - Fixed activation behavior for widgets partially clipped
  2118. - 2017/05/10 (1.38.3) - Fixed wrong min window size mouse scaling over boundries
  2119. - 2017/05/09 (1.38.2) - Fixed vertical scrollbar drawing with not enough space
  2120. - 2017/05/09 (1.38.1) - Fixed scaler dragging behavior if window size hits minimum size
  2121. - 2017/05/06 (1.38.0) - Added platform double-click support
  2122. - 2017/04/20 (1.37.1) - Fixed key repeat found inside glfw demo backends
  2123. - 2017/04/20 (1.37.0) - Extended properties with selection and clipbard support
  2124. - 2017/04/20 (1.36.2) - Fixed #405 overlapping rows with zero padding and spacing
  2125. - 2017/04/09 (1.36.1) - Fixed #403 with another widget float error
  2126. - 2017/04/09 (1.36.0) - Added window `NK_WINDOW_NO_INPUT` and `NK_WINDOW_NOT_INTERACTIVE` flags
  2127. - 2017/04/09 (1.35.3) - Fixed buffer heap corruption
  2128. - 2017/03/25 (1.35.2) - Fixed popup overlapping for `NK_WINDOW_BACKGROUND` windows
  2129. - 2017/03/25 (1.35.1) - Fixed windows closing behavior
  2130. - 2017/03/18 (1.35.0) - Added horizontal scroll requested in #377
  2131. - 2017/03/18 (1.34.3) - Fixed long window header titles
  2132. - 2017/03/04 (1.34.2) - Fixed text edit filtering
  2133. - 2017/03/04 (1.34.1) - Fixed group closable flag
  2134. - 2017/02/25 (1.34.0) - Added custom draw command for better language binding support
  2135. - 2017/01/24 (1.33.0) - Added programatic way of remove edit focus
  2136. - 2017/01/24 (1.32.3) - Fixed wrong define for basic type definitions for windows
  2137. - 2017/01/21 (1.32.2) - Fixed input capture from hidden or closed windows
  2138. - 2017/01/21 (1.32.1) - Fixed slider behavior and drawing
  2139. - 2017/01/13 (1.32.0) - Added flag to put scaler into the bottom left corner
  2140. - 2017/01/13 (1.31.0) - Added additional row layouting method to combine both
  2141. dynamic and static widgets.
  2142. - 2016/12/31 (1.30.0) - Extended scrollbar offset from 16-bit to 32-bit
  2143. - 2016/12/31 (1.29.2)- Fixed closing window bug of minimized windows
  2144. - 2016/12/03 (1.29.1)- Fixed wrapped text with no seperator and C89 error
  2145. - 2016/12/03 (1.29.0) - Changed text wrapping to process words not characters
  2146. - 2016/11/22 (1.28.6)- Fixed window minimized closing bug
  2147. - 2016/11/19 (1.28.5)- Fixed abstract combo box closing behavior
  2148. - 2016/11/19 (1.28.4)- Fixed tooltip flickering
  2149. - 2016/11/19 (1.28.3)- Fixed memory leak caused by popup repeated closing
  2150. - 2016/11/18 (1.28.2)- Fixed memory leak caused by popup panel allocation
  2151. - 2016/11/10 (1.28.1)- Fixed some warnings and C++ error
  2152. - 2016/11/10 (1.28.0)- Added additional `nk_button` versions which allows to directly
  2153. pass in a style struct to change buttons visual.
  2154. - 2016/11/10 (1.27.0)- Added additional 'nk_tree' versions to support external state
  2155. storage. Just like last the `nk_group` commit the main
  2156. advantage is that you optionally can minimize nuklears runtime
  2157. memory consumption or handle hash collisions.
  2158. - 2016/11/09 (1.26.0)- Added additional `nk_group` version to support external scrollbar
  2159. offset storage. Main advantage is that you can externalize
  2160. the memory management for the offset. It could also be helpful
  2161. if you have a hash collision in `nk_group_begin` but really
  2162. want the name. In addition I added `nk_list_view` which allows
  2163. to draw big lists inside a group without actually having to
  2164. commit the whole list to nuklear (issue #269).
  2165. - 2016/10/30 (1.25.1)- Fixed clipping rectangle bug inside `nk_draw_list`
  2166. - 2016/10/29 (1.25.0)- Pulled `nk_panel` memory management into nuklear and out of
  2167. the hands of the user. From now on users don't have to care
  2168. about panels unless they care about some information. If you
  2169. still need the panel just call `nk_window_get_panel`.
  2170. - 2016/10/21 (1.24.0)- Changed widget border drawing to stroked rectangle from filled
  2171. rectangle for less overdraw and widget background transparency.
  2172. - 2016/10/18 (1.23.0)- Added `nk_edit_focus` for manually edit widget focus control
  2173. - 2016/09/29 (1.22.7)- Fixed deduction of basic type in non `<stdint.h>` compilation
  2174. - 2016/09/29 (1.22.6)- Fixed edit widget UTF-8 text cursor drawing bug
  2175. - 2016/09/28 (1.22.5)- Fixed edit widget UTF-8 text appending/inserting/removing
  2176. - 2016/09/28 (1.22.4)- Fixed drawing bug inside edit widgets which offset all text
  2177. text in every edit widget if one of them is scrolled.
  2178. - 2016/09/28 (1.22.3)- Fixed small bug in edit widgets if not active. The wrong
  2179. text length is passed. It should have been in bytes but
  2180. was passed as glyphes.
  2181. - 2016/09/20 (1.22.2)- Fixed color button size calculation
  2182. - 2016/09/20 (1.22.1)- Fixed some `nk_vsnprintf` behavior bugs and removed
  2183. `<stdio.h>` again from `NK_INCLUDE_STANDARD_VARARGS`.
  2184. - 2016/09/18 (1.22.0)- C89 does not support vsnprintf only C99 and newer as well
  2185. as C++11 and newer. In addition to use vsnprintf you have
  2186. to include <stdio.h>. So just defining `NK_INCLUDE_STD_VAR_ARGS`
  2187. is not enough. That behavior is now fixed. By default if
  2188. both varargs as well as stdio is selected I try to use
  2189. vsnprintf if not possible I will revert to vsprintf. If
  2190. varargs but not stdio was defined I will use my own function.
  2191. - 2016/09/15 (1.21.2)- Fixed panel `close` behavior for deeper panel levels
  2192. - 2016/09/15 (1.21.1)- Fixed C++ errors and wrong argument to `nk_panel_get_xxxx`
  2193. - 2016/09/13 (1.21.0) - !BREAKING! Fixed nonblocking popup behavior in menu, combo,
  2194. and contextual which prevented closing in y-direction if
  2195. popup did not reach max height.
  2196. In addition the height parameter was changed into vec2
  2197. for width and height to have more control over the popup size.
  2198. - 2016/09/13 (1.20.3) - Cleaned up and extended type selection
  2199. - 2016/09/13 (1.20.2)- Fixed slider behavior hopefully for the last time. This time
  2200. all calculation are correct so no more hackery.
  2201. - 2016/09/13 (1.20.1)- Internal change to divide window/panel flags into panel flags and types.
  2202. Suprisinly spend years in C and still happened to confuse types
  2203. with flags. Probably something to take note.
  2204. - 2016/09/08 (1.20.0)- Added additional helper function to make it easier to just
  2205. take the produced buffers from `nk_convert` and unplug the
  2206. iteration process from `nk_context`. So now you can
  2207. just use the vertex,element and command buffer + two pointer
  2208. inside the command buffer retrieved by calls `nk__draw_begin`
  2209. and `nk__draw_end` and macro `nk_draw_foreach_bounded`.
  2210. - 2016/09/08 (1.19.0)- Added additional asserts to make sure every `nk_xxx_begin` call
  2211. for windows, popups, combobox, menu and contextual is guarded by
  2212. `if` condition and does not produce false drawing output.
  2213. - 2016/09/08 (1.18.0)- Changed confusing name for `NK_SYMBOL_RECT_FILLED`, `NK_SYMBOL_RECT`
  2214. to hopefully easier to understand `NK_SYMBOL_RECT_FILLED` and
  2215. `NK_SYMBOL_RECT_OUTLINE`.
  2216. - 2016/09/08 (1.17.0)- Changed confusing name for `NK_SYMBOL_CIRLCE_FILLED`, `NK_SYMBOL_CIRCLE`
  2217. to hopefully easier to understand `NK_SYMBOL_CIRCLE_FILLED` and
  2218. `NK_SYMBOL_CIRCLE_OUTLINE`.
  2219. - 2016/09/08 (1.16.0)- Added additional checks to select correct types if `NK_INCLUDE_FIXED_TYPES`
  2220. is not defined by supporting the biggest compiler GCC, clang and MSVC.
  2221. - 2016/09/07 (1.15.3)- Fixed `NK_INCLUDE_COMMAND_USERDATA` define to not cause an error
  2222. - 2016/09/04 (1.15.2)- Fixed wrong combobox height calculation
  2223. - 2016/09/03 (1.15.1)- Fixed gaps inside combo boxes in OpenGL
  2224. - 2016/09/02 (1.15.0) - Changed nuklear to not have any default vertex layout and
  2225. instead made it user provided. The range of types to convert
  2226. to is quite limited at the moment, but I would be more than
  2227. happy to accept PRs to add additional.
  2228. - 2016/08/30 (1.14.2) - Removed unused variables
  2229. - 2016/08/30 (1.14.1) - Fixed C++ build errors
  2230. - 2016/08/30 (1.14.0) - Removed mouse dragging from SDL demo since it does not work correctly
  2231. - 2016/08/30 (1.13.4) - Tweaked some default styling variables
  2232. - 2016/08/30 (1.13.3) - Hopefully fixed drawing bug in slider, in general I would
  2233. refrain from using slider with a big number of steps.
  2234. - 2016/08/30 (1.13.2) - Fixed close and minimize button which would fire even if the
  2235. window was in Read Only Mode.
  2236. - 2016/08/30 (1.13.1) - Fixed popup panel padding handling which was previously just
  2237. a hack for combo box and menu.
  2238. - 2016/08/30 (1.13.0) - Removed `NK_WINDOW_DYNAMIC` flag from public API since
  2239. it is bugged and causes issues in window selection.
  2240. - 2016/08/30 (1.12.0) - Removed scaler size. The size of the scaler is now
  2241. determined by the scrollbar size
  2242. - 2016/08/30 (1.11.2) - Fixed some drawing bugs caused by changes from 1.11
  2243. - 2016/08/30 (1.11.1) - Fixed overlapping minimized window selection
  2244. - 2016/08/30 (1.11.0) - Removed some internal complexity and overly complex code
  2245. handling panel padding and panel border.
  2246. - 2016/08/29 (1.10.0) - Added additional height parameter to `nk_combobox_xxx`
  2247. - 2016/08/29 (1.10.0) - Fixed drawing bug in dynamic popups
  2248. - 2016/08/29 (1.10.0) - Added experimental mouse scrolling to popups, menus and comboboxes
  2249. - 2016/08/26 (1.10.0) - Added window name string prepresentation to account for
  2250. hash collisions. Currently limited to NK_WINDOW_MAX_NAME
  2251. which in term can be redefined if not big enough.
  2252. - 2016/08/26 (1.10.0) - Added stacks for temporary style/UI changes in code
  2253. - 2016/08/25 (1.10.0) - Changed `nk_input_is_key_pressed` and 'nk_input_is_key_released'
  2254. to account for key press and release happening in one frame.
  2255. - 2016/08/25 (1.10.0) - Added additional nk_edit flag to directly jump to the end on activate
  2256. - 2016/08/17 (1.09.6)- Removed invalid check for value zero in nk_propertyx
  2257. - 2016/08/16 (1.09.5)- Fixed ROM mode for deeper levels of popup windows parents.
  2258. - 2016/08/15 (1.09.4)- Editbox are now still active if enter was pressed with flag
  2259. `NK_EDIT_SIG_ENTER`. Main reasoning is to be able to keep
  2260. typing after commiting.
  2261. - 2016/08/15 (1.09.4)- Removed redundant code
  2262. - 2016/08/15 (1.09.4)- Fixed negative numbers in `nk_strtoi` and remove unused variable
  2263. - 2016/08/15 (1.09.3)- Fixed `NK_WINDOW_BACKGROUND` flag behavior to select a background
  2264. window only as selected by hovering and not by clicking.
  2265. - 2016/08/14 (1.09.2)- Fixed a bug in font atlas which caused wrong loading
  2266. of glyphes for font with multiple ranges.
  2267. - 2016/08/12 (1.09.1)- Added additional function to check if window is currently
  2268. hidden and therefore not visible.
  2269. - 2016/08/12 (1.09.1)- nk_window_is_closed now queries the correct flag `NK_WINDOW_CLOSED`
  2270. instead of the old flag `NK_WINDOW_HIDDEN`
  2271. - 2016/08/09 (1.09.0) - Added additional double version to nk_property and changed
  2272. the underlying implementation to not cast to float and instead
  2273. work directly on the given values.
  2274. - 2016/08/09 (1.08.0) - Added additional define to overwrite library internal
  2275. floating pointer number to string conversion for additional
  2276. precision.
  2277. - 2016/08/09 (1.08.0) - Added additional define to overwrite library internal
  2278. string to floating point number conversion for additional
  2279. precision.
  2280. - 2016/08/08 (1.07.2)- Fixed compiling error without define NK_INCLUDE_FIXED_TYPE
  2281. - 2016/08/08 (1.07.1)- Fixed possible floating point error inside `nk_widget` leading
  2282. to wrong wiget width calculation which results in widgets falsly
  2283. becomming tagged as not inside window and cannot be accessed.
  2284. - 2016/08/08 (1.07.0) - Nuklear now differentiates between hiding a window (NK_WINDOW_HIDDEN) and
  2285. closing a window (NK_WINDOW_CLOSED). A window can be hidden/shown
  2286. by using `nk_window_show` and closed by either clicking the close
  2287. icon in a window or by calling `nk_window_close`. Only closed
  2288. windows get removed at the end of the frame while hidden windows
  2289. remain.
  2290. - 2016/08/08 (1.06.0) - Added `nk_edit_string_zero_terminated` as a second option to
  2291. `nk_edit_string` which takes, edits and outputs a '\0' terminated string.
  2292. - 2016/08/08 (1.05.4)- Fixed scrollbar auto hiding behavior
  2293. - 2016/08/08 (1.05.3)- Fixed wrong panel padding selection in `nk_layout_widget_space`
  2294. - 2016/08/07 (1.05.2)- Fixed old bug in dynamic immediate mode layout API, calculating
  2295. wrong item spacing and panel width.
  2296. define NK_INCLUDE_STANDARD_VARARGS to allow more fine
  2297. grained controlled over library includes.
  2298. - 2016/08/06 (1.04.5)- Changed memset calls to NK_MEMSET
  2299. - 2016/08/04 (1.04.4)- Fixed fast window scaling behavior
  2300. - 2016/08/04 (1.04.3)- Fixed window scaling, movement bug which appears if you
  2301. move/scale a window and another window is behind it.
  2302. If you are fast enough then the window behind gets activated
  2303. and the operation is blocked. I now require activating
  2304. by hovering only if mouse is not pressed.
  2305. - 2016/08/04 (1.04.2)- Fixed changing fonts
  2306. - 2016/08/03 (1.04.1)- Fixed `NK_WINDOW_BACKGROUND` behavior
  2307. - 2016/08/03 (1.04.0) - Added color parameter to `nk_draw_image`
  2308. - 2016/08/03 (1.04.0) - Added additional window padding style attributes for
  2309. sub windows (combo, menu, ...)
  2310. - 2016/08/03 (1.04.0) - Added functions to show/hide software cursor
  2311. - 2016/08/03 (1.04.0) - Added `NK_WINDOW_BACKGROUND` flag to force a window
  2312. to be always in the background of the screen
  2313. - 2016/08/03 (1.03.2)- Removed invalid assert macro for NK_RGB color picker
  2314. - 2016/08/01 (1.03.1)- Added helper macros into header include guard
  2315. - 2016/07/29 (1.03.0) - Moved the window/table pool into the header part to
  2316. simplify memory management by removing the need to
  2317. allocate the pool.
  2318. - 2016/07/29 (1.02.0) - Added auto scrollbar hiding window flag which if enabled
  2319. will hide the window scrollbar after NK_SCROLLBAR_HIDING_TIMEOUT
  2320. seconds without window interaction. To make it work
  2321. you have to also set a delta time inside the `nk_context`.
  2322. - 2016/07/25 (1.01.1) - Fixed small panel and panel border drawing bugs
  2323. - 2016/07/15 (1.01.0) - Added software cursor to `nk_style` and `nk_context`
  2324. - 2016/07/15 (1.01.0) - Added const correctness to `nk_buffer_push' data argument
  2325. - 2016/07/15 (1.01.0) - Removed internal font baking API and simplified
  2326. font atlas memory management by converting pointer
  2327. arrays for fonts and font configurations to lists.
  2328. - 2016/07/15 (1.00.0) - Changed button API to use context dependend button
  2329. behavior instead of passing it for every function call.
  2330. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2331. ## Gallery
  2332. ![Figure [blue]: Feature overview with blue color styling](https://cloud.githubusercontent.com/assets/8057201/13538240/acd96876-e249-11e5-9547-5ac0b19667a0.png)
  2333. ![Figure [red]: Feature overview with red color styling](https://cloud.githubusercontent.com/assets/8057201/13538243/b04acd4c-e249-11e5-8fd2-ad7744a5b446.png)
  2334. ![Figure [widgets]: Widget overview](https://cloud.githubusercontent.com/assets/8057201/11282359/3325e3c6-8eff-11e5-86cb-cf02b0596087.png)
  2335. ![Figure [blackwhite]: Black and white](https://cloud.githubusercontent.com/assets/8057201/11033668/59ab5d04-86e5-11e5-8091-c56f16411565.png)
  2336. ![Figure [filexp]: File explorer](https://cloud.githubusercontent.com/assets/8057201/10718115/02a9ba08-7b6b-11e5-950f-adacdd637739.png)
  2337. ![Figure [opengl]: OpenGL Editor](https://cloud.githubusercontent.com/assets/8057201/12779619/2a20d72c-ca69-11e5-95fe-4edecf820d5c.png)
  2338. ![Figure [nodedit]: Node Editor](https://cloud.githubusercontent.com/assets/8057201/9976995/e81ac04a-5ef7-11e5-872b-acd54fbeee03.gif)
  2339. ![Figure [skinning]: Using skinning in Nuklear](https://cloud.githubusercontent.com/assets/8057201/15991632/76494854-30b8-11e6-9555-a69840d0d50b.png)
  2340. ![Figure [bf]: Heavy modified version](https://cloud.githubusercontent.com/assets/8057201/14902576/339926a8-0d9c-11e6-9fee-a8b73af04473.png)
  2341. ## Credits
  2342. Developed by Micha Mettke and every direct or indirect github contributor. <br /><br />
  2343. 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 />
  2344. Uses [stddoc.c](https://github.com/r-lyeh/stddoc.c) from [email protected] for documentation generation <br /><br />
  2345. Embeds ProggyClean.ttf font by Tristan Grimmer (MIT license). <br />
  2346. Big thank you to Omar Cornut (ocornut@github) for his [imgui library](https://github.com/ocornut/imgui) and
  2347. giving me the inspiration for this library, Casey Muratori for handmade hero
  2348. and his original immediate mode graphical user interface idea and Sean
  2349. Barret for his amazing single header libraries which restored my faith
  2350. in libraries and brought me to create some of my own.
  2351. <script>markdeepOptions={tocStyle:'medium'};</script>
  2352. <!-- Markdeep: --><script src='https://casual-effects.com/markdeep/latest/markdeep.min.js?'></script>