2017-02-24 19:18:27 +01:00
# Nuklear
2019-12-20 09:29:07 +11:00
[](https://github.com/Immediate-Mode-UI/Nuklear/actions)
2019-12-04 17:08:37 +01:00
2019-10-25 10:15:13 -06:00
This is a minimal-state, immediate-mode graphical user interface toolkit
2016-04-11 01:34:59 +02:00
written in ANSI C and licensed under public domain. It was designed as a simple
embeddable user interface for application and does not have any dependencies,
2019-10-25 10:15:13 -06:00
a default render backend or OS window/input handling but instead provides a
highly modular, library-based approach, with simple input state for input and
draw commands describing primitive shapes as output. So instead of providing a
2015-09-17 17:31:43 +02:00
layered library that tries to abstract over a number of platform and
2019-10-25 10:15:13 -06:00
render backends, it focuses only on the actual UI.
2015-03-11 14:00:59 +01:00
2015-03-14 17:05:30 +01:00
## Features
2017-02-24 19:18:27 +01:00
2019-10-25 10:15:13 -06:00
- Immediate-mode graphical user interface toolkit
- Single-header library
2015-03-14 17:05:30 +01:00
- Written in C89 (ANSI C)
2017-08-19 18:45:46 -04:00
- Small codebase (~18kLOC)
2016-01-26 14:52:00 +01:00
- Focus on portability, efficiency and simplicity
2016-04-11 01:34:59 +02:00
- No dependencies (not even the standard library if not wanted)
2016-03-26 16:05:19 +01:00
- Fully skinnable and customizable
2019-10-25 10:15:13 -06:00
- Low memory footprint with total control of memory usage if needed / wanted
2015-04-30 16:12:21 +02:00
- UTF-8 support
2016-04-11 01:34:59 +02:00
- No global or hidden state
2016-04-19 15:23:33 +07:00
- Customizable library modules (you can compile and use only what you need)
2016-04-11 01:34:59 +02:00
- Optional font baker and vertex buffer output
2020-04-30 12:41:07 +02:00
- [Documentation ](https://Immediate-Mode-UI.github.io/Nuklear/doc/nuklear.html )
2015-11-19 21:02:36 +01:00
## Building
2017-02-24 19:18:27 +01:00
2019-10-25 10:15:13 -06:00
This library is self-contained in one single header file and can be used either
in header-only mode or in implementation mode. The header-only mode is used
2016-04-11 01:34:59 +02:00
by default when included and allows including this header in other headers
and does not contain the actual implementation.
2019-10-25 10:15:13 -06:00
The implementation mode requires defining the preprocessor macro
2016-05-02 08:44:22 -04:00
`NK_IMPLEMENTATION` in *one* .c/.cpp file before `#include` ing this file, e.g.:
2016-04-11 01:34:59 +02:00
```c
2016-05-02 08:44:22 -04:00
#define NK_IMPLEMENTATION
#include "nuklear.h"
2016-04-11 01:34:59 +02:00
```
2016-09-04 20:46:23 +02:00
IMPORTANT: Every time you include "nuklear.h" you have to define the same optional flags.
2019-10-25 10:15:13 -06:00
This is very important; not doing it either leads to compiler errors, or even worse, stack corruptions.
2015-09-17 17:31:43 +02:00
2015-05-09 15:22:23 +02:00
## Gallery
2017-02-24 19:18:27 +01:00
2015-12-12 11:53:15 +01:00

2016-03-04 20:46:45 +01:00


2015-09-19 17:59:10 +02:00

2016-06-12 16:14:24 +02:00

2016-04-28 23:54:13 +02:00

2015-05-09 15:22:23 +02:00
2015-04-25 16:44:43 +02:00
## Example
2017-02-24 19:18:27 +01:00
2015-04-25 16:44:43 +02:00
```c
2015-12-30 16:31:08 +01:00
/* init gui state */
2016-04-11 01:34:59 +02:00
struct nk_context ctx;
nk_init_fixed(& ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font);
2015-12-30 16:31:08 +01:00
2015-08-05 12:48:01 +02:00
enum {EASY, HARD};
2017-03-17 20:24:28 +01:00
static int op = EASY;
static float value = 0.6f;
static int i = 20;
2015-12-30 16:31:08 +01:00
2016-10-29 23:23:46 +02:00
if (nk_begin(& ctx, "Show", nk_rect(50, 50, 220, 220),
2016-09-18 02:31:45 +02:00
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
2016-01-04 21:34:48 +01:00
/* fixed widget pixel width */
2016-04-11 01:34:59 +02:00
nk_layout_row_static(& ctx, 30, 80, 1);
2016-09-18 02:31:45 +02:00
if (nk_button_label(& ctx, "button")) {
2016-01-04 21:34:48 +01:00
/* event handling */
2015-12-30 16:31:08 +01:00
}
2015-06-28 10:09:53 +02:00
2016-01-04 21:34:48 +01:00
/* fixed widget window ratio width */
2016-04-11 01:34:59 +02:00
nk_layout_row_dynamic(& ctx, 30, 2);
2016-09-18 02:31:45 +02:00
if (nk_option_label(& ctx, "easy", op == EASY)) op = EASY;
if (nk_option_label(& ctx, "hard", op == HARD)) op = HARD;
2016-01-04 21:34:48 +01:00
/* custom widget pixel width */
2016-04-11 01:34:59 +02:00
nk_layout_row_begin(& ctx, NK_STATIC, 30, 2);
2016-01-04 21:34:48 +01:00
{
2016-04-11 01:34:59 +02:00
nk_layout_row_push(& ctx, 50);
nk_label(& ctx, "Volume:", NK_TEXT_LEFT);
nk_layout_row_push(& ctx, 110);
nk_slider_float(& ctx, 0, & value, 1.0f, 0.1f);
2015-04-25 16:44:43 +02:00
}
2016-04-11 01:34:59 +02:00
nk_layout_row_end(&ctx);
2015-04-25 16:44:43 +02:00
}
2016-09-18 02:31:45 +02:00
nk_end(&ctx);
2015-04-25 16:44:43 +02:00
```
2015-09-30 10:23:45 +02:00

2015-04-25 16:44:43 +02:00
2017-02-24 19:18:27 +01:00
## Bindings
2021-11-30 21:45:48 -05:00
There are a number of nuklear bindings for different languages created by other authors.
2019-10-25 10:15:13 -06:00
I cannot attest for their quality since I am not necessarily proficient in any of these
2017-02-24 19:18:27 +01:00
languages. Furthermore there are no guarantee that all bindings will always be kept up to date:
2016-05-17 18:37:13 +02:00
2017-02-24 19:18:27 +01:00
- [Java ](https://github.com/glegris/nuklear4j ) by Guillaume Legris
2019-06-06 22:06:01 +00:00
- [D ](https://github.com/Timu5/bindbc-nuklear ) by Mateusz Muszyński
2017-02-24 19:18:27 +01:00
- [Golang ](https://github.com/golang-ui/nuklear ) by golang-ui@github .com
- [Rust ](https://github.com/snuk182/nuklear-rust ) by snuk182@github .com
2018-01-09 05:52:18 +01:00
- [Chicken ](https://github.com/wasamasa/nuklear ) by wasamasa@github .com
2017-02-24 19:18:27 +01:00
- [Nim ](https://github.com/zacharycarter/nuklear-nim ) by zacharycarter@github .com
2018-04-12 13:48:53 -03:00
- Lua
- [LÖVE-Nuklear ](https://github.com/keharriso/love-nuklear ) by Kevin Harrison
- [MoonNuklear ](https://github.com/stetre/moonnuklear ) by Stefano Trettel
2018-03-24 17:20:26 +00:00
- Python
- [pyNuklear ](https://github.com/billsix/pyNuklear ) by William Emerison Six (ctypes-based wrapper)
- [pynk ](https://github.com/nathanrw/nuklear-cffi ) by nathanrw@github .com (cffi binding)
2018-01-09 05:55:25 +01:00
- [CSharp/.NET ](https://github.com/cartman300/NuklearDotNet ) by cartman300@github .com
2020-02-23 00:32:08 +01:00
- [V ](https://github.com/nsauzede/vnk ) by Nicolas Sauzede
2017-02-24 19:18:27 +01:00
## Credits
2016-04-11 01:34:59 +02:00
Developed by Micha Mettke and every direct or indirect contributor to the GitHub.
2018-02-11 13:28:19 +02:00
Embeds `stb_texedit` , `stb_truetype` and `stb_rectpack` by Sean Barrett (public domain)
2016-05-02 08:44:22 -04:00
Embeds `ProggyClean.ttf` font by Tristan Grimmer (MIT license).
2016-04-11 01:34:59 +02:00
2016-04-28 23:54:13 +02:00
Big thank you to Omar Cornut (ocornut@github ) for his [imgui ](https://github.com/ocornut/imgui ) library and
2016-04-11 01:34:59 +02:00
giving me the inspiration for this library, Casey Muratori for handmade hero
2019-10-25 10:15:13 -06:00
and his original immediate-mode graphical user interface idea and Sean
Barrett for his amazing single-header [libraries ](https://github.com/nothings/stb ) which restored my faith
2019-12-04 16:41:37 +01:00
in libraries and brought me to create some of my own. Finally Apoorva Joshi for his single-header [file packer ](http://apoorvaj.io/single-header-packer.html ).
2016-04-11 01:34:59 +02:00
2017-02-24 19:18:27 +01:00
## License
2024-08-26 15:29:47 +00:00
Nuklear is avaliable under either the MIT License or public domain.
See [LICENSE ](LICENSE ) for more info.
2020-03-08 20:19:30 +01:00
## Reviewers guide
When reviewing pull request there are common things a reviewer should keep
in mind.
Reviewing changes to `src/*` and `nuklear.h` :
* Ensure C89 compatibility.
* The code should work for several backends to an acceptable degree.
2020-03-31 14:52:08 +02:00
* Check no other parts of `nuklear.h` are related to the PR and thus nothing is missing.
2020-03-08 20:19:30 +01:00
* Recommend simple optimizations.
* Pass small structs by value instead of by pointer.
* Use local buffers over heap allocation when possible.
* Check that the coding style is consistent with code around it.
* Variable/function name casing.
* Indentation.
* Curly bracket (`{}` ) placement.
2021-11-30 21:45:48 -05:00
* Ensure that the contributor has bumped the appropriate version in
2021-12-15 10:36:03 +11:00
[clib.json ](https://github.com/Immediate-Mode-UI/Nuklear/blob/master/clib.json )
2020-03-08 20:19:30 +01:00
and added their changes to the
[CHANGELOG ](https://github.com/Immediate-Mode-UI/Nuklear/blob/master/src/CHANGELOG ).
* Have at least one other person review the changes before merging.
Reviewing changes to `demo/*` , `example/*` and other files in the repo:
* Focus on getting working code merged.
* We want to make it easy for people to get started with Nuklear, and any
`demo` and `example` improvements helps in this regard.
* Use of newer C features, or even other languages is not discouraged.
* If another language is used, ensure that the build process is easy to figure out.
* Messy or less efficient code can be merged so long as these outliers are pointed out
and easy to find.
* Version shouldn't be bumped for these changes.
* Changes that improves code to be more inline with `nuklear.h` are ofc always welcome.