index.html 173 KB

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