index.html 155 KB

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