2017-02-24 21:18:27 +03:00
|
|
|
# Nuklear
|
|
|
|
|
2016-05-02 15:44:22 +03:00
|
|
|
[![Build Status](https://travis-ci.org/vurtun/nuklear.svg)](https://travis-ci.org/vurtun/nuklear)
|
|
|
|
|
2015-11-19 23:02:36 +03:00
|
|
|
This is a minimal state immediate mode graphical user interface toolkit
|
2016-04-11 02:34:59 +03: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,
|
2015-12-11 02:04:17 +03:00
|
|
|
a default renderbackend or OS window and input handling but instead provides a very modular
|
|
|
|
library approach by using simple input state for input and draw
|
2015-09-17 18:31:43 +03:00
|
|
|
commands describing primitive shapes as output. So instead of providing a
|
|
|
|
layered library that tries to abstract over a number of platform and
|
2015-11-19 23:02:36 +03:00
|
|
|
render backends it only focuses on the actual UI.
|
2015-03-11 16:00:59 +03:00
|
|
|
|
2015-03-14 19:05:30 +03:00
|
|
|
## Features
|
2017-02-24 21:18:27 +03:00
|
|
|
|
2015-04-16 17:20:00 +03:00
|
|
|
- Immediate mode graphical user interface toolkit
|
2016-04-11 02:34:59 +03:00
|
|
|
- Single header library
|
2015-03-14 19:05:30 +03:00
|
|
|
- Written in C89 (ANSI C)
|
2017-01-12 01:24:41 +03:00
|
|
|
- Small codebase (~17kLOC)
|
2016-01-26 16:52:00 +03:00
|
|
|
- Focus on portability, efficiency and simplicity
|
2016-04-11 02:34:59 +03:00
|
|
|
- No dependencies (not even the standard library if not wanted)
|
2016-03-26 18:05:19 +03:00
|
|
|
- Fully skinnable and customizable
|
2016-04-11 02:34:59 +03:00
|
|
|
- Low memory footprint with total memory control if needed or wanted
|
2015-04-30 17:12:21 +03:00
|
|
|
- UTF-8 support
|
2016-04-11 02:34:59 +03:00
|
|
|
- No global or hidden state
|
2016-04-19 11:23:33 +03:00
|
|
|
- Customizable library modules (you can compile and use only what you need)
|
2016-04-11 02:34:59 +03:00
|
|
|
- Optional font baker and vertex buffer output
|
2015-11-19 23:02:36 +03:00
|
|
|
|
|
|
|
## Building
|
2017-02-24 21:18:27 +03:00
|
|
|
|
2016-04-11 02:34:59 +03: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
|
|
|
|
by default when included and allows including this header in other headers
|
|
|
|
and does not contain the actual implementation.
|
|
|
|
|
|
|
|
The implementation mode requires to define the preprocessor macro
|
2016-05-02 15:44:22 +03:00
|
|
|
`NK_IMPLEMENTATION` in *one* .c/.cpp file before `#include`ing this file, e.g.:
|
2016-04-11 02:34:59 +03:00
|
|
|
```c
|
2016-05-02 15:44:22 +03:00
|
|
|
#define NK_IMPLEMENTATION
|
|
|
|
#include "nuklear.h"
|
2016-04-11 02:34:59 +03:00
|
|
|
```
|
2016-09-04 21:46:23 +03:00
|
|
|
IMPORTANT: Every time you include "nuklear.h" you have to define the same optional flags.
|
|
|
|
This is very important not doing it either leads to compiler errors or even worse stack corruptions.
|
2015-09-17 18:31:43 +03:00
|
|
|
|
2015-05-09 16:22:23 +03:00
|
|
|
## Gallery
|
2017-02-24 21:18:27 +03:00
|
|
|
|
2015-12-12 13:53:15 +03:00
|
|
|
![screenshot](https://cloud.githubusercontent.com/assets/8057201/11761525/ae06f0ca-a0c6-11e5-819d-5610b25f6ef4.gif)
|
2016-03-04 22:46:45 +03:00
|
|
|
![screen](https://cloud.githubusercontent.com/assets/8057201/13538240/acd96876-e249-11e5-9547-5ac0b19667a0.png)
|
|
|
|
![screen2](https://cloud.githubusercontent.com/assets/8057201/13538243/b04acd4c-e249-11e5-8fd2-ad7744a5b446.png)
|
2015-09-19 18:59:10 +03:00
|
|
|
![node](https://cloud.githubusercontent.com/assets/8057201/9976995/e81ac04a-5ef7-11e5-872b-acd54fbeee03.gif)
|
2016-06-12 17:14:24 +03:00
|
|
|
![skinning](https://cloud.githubusercontent.com/assets/8057201/15991632/76494854-30b8-11e6-9555-a69840d0d50b.png)
|
2016-04-29 00:54:13 +03:00
|
|
|
![gamepad](https://cloud.githubusercontent.com/assets/8057201/14902576/339926a8-0d9c-11e6-9fee-a8b73af04473.png)
|
2015-05-09 16:22:23 +03:00
|
|
|
|
2015-04-25 17:44:43 +03:00
|
|
|
## Example
|
2017-02-24 21:18:27 +03:00
|
|
|
|
2015-04-25 17:44:43 +03:00
|
|
|
```c
|
2015-12-30 18:31:08 +03:00
|
|
|
/* init gui state */
|
2016-04-11 02:34:59 +03:00
|
|
|
struct nk_context ctx;
|
|
|
|
nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font);
|
2015-12-30 18:31:08 +03:00
|
|
|
|
2015-08-05 13:48:01 +03:00
|
|
|
enum {EASY, HARD};
|
2017-03-17 22:24:28 +03:00
|
|
|
static int op = EASY;
|
|
|
|
static float value = 0.6f;
|
|
|
|
static int i = 20;
|
2015-12-30 18:31:08 +03:00
|
|
|
|
2016-10-30 00:23:46 +03:00
|
|
|
if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
|
2016-09-18 03:31:45 +03:00
|
|
|
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
|
2016-01-04 23:34:48 +03:00
|
|
|
/* fixed widget pixel width */
|
2016-04-11 02:34:59 +03:00
|
|
|
nk_layout_row_static(&ctx, 30, 80, 1);
|
2016-09-18 03:31:45 +03:00
|
|
|
if (nk_button_label(&ctx, "button")) {
|
2016-01-04 23:34:48 +03:00
|
|
|
/* event handling */
|
2015-12-30 18:31:08 +03:00
|
|
|
}
|
2015-06-28 11:09:53 +03:00
|
|
|
|
2016-01-04 23:34:48 +03:00
|
|
|
/* fixed widget window ratio width */
|
2016-04-11 02:34:59 +03:00
|
|
|
nk_layout_row_dynamic(&ctx, 30, 2);
|
2016-09-18 03:31:45 +03:00
|
|
|
if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY;
|
|
|
|
if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD;
|
2016-01-04 23:34:48 +03:00
|
|
|
|
|
|
|
/* custom widget pixel width */
|
2016-04-11 02:34:59 +03:00
|
|
|
nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
|
2016-01-04 23:34:48 +03:00
|
|
|
{
|
2016-04-11 02:34:59 +03: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 17:44:43 +03:00
|
|
|
}
|
2016-04-11 02:34:59 +03:00
|
|
|
nk_layout_row_end(&ctx);
|
2015-04-25 17:44:43 +03:00
|
|
|
}
|
2016-09-18 03:31:45 +03:00
|
|
|
nk_end(&ctx);
|
2015-04-25 17:44:43 +03:00
|
|
|
```
|
2015-09-30 11:23:45 +03:00
|
|
|
![example](https://cloud.githubusercontent.com/assets/8057201/10187981/584ecd68-675c-11e5-897c-822ef534a876.png)
|
2015-04-25 17:44:43 +03:00
|
|
|
|
2017-02-24 21:18:27 +03:00
|
|
|
## Bindings
|
|
|
|
There are a number of nuklear bindings for different languges created by other authors.
|
|
|
|
I cannot atest for their quality since I am not necessarily proficient in either of these
|
|
|
|
languages. Furthermore there are no guarantee that all bindings will always be kept up to date:
|
2016-05-17 19:37:13 +03:00
|
|
|
|
2017-02-24 21:18:27 +03:00
|
|
|
- [Java](https://github.com/glegris/nuklear4j) by Guillaume Legris
|
|
|
|
- [Golang](https://github.com/golang-ui/nuklear) by golang-ui@github.com
|
|
|
|
- [Rust](https://github.com/snuk182/nuklear-rust) by snuk182@github.com
|
|
|
|
- [Chicken](https://github.com/wasamasa/nuklear) by wasamasa@github.comx
|
|
|
|
- [Nim](https://github.com/zacharycarter/nuklear-nim) by zacharycarter@github.com
|
|
|
|
|
|
|
|
## Credits
|
2016-04-11 02:34:59 +03:00
|
|
|
Developed by Micha Mettke and every direct or indirect contributor to the GitHub.
|
|
|
|
|
|
|
|
|
2016-09-15 15:39:53 +03:00
|
|
|
Embeds `stb_texedit`, `stb_truetype` and `stb_rectpack` by Sean Barret (public domain)
|
2016-05-02 15:44:22 +03:00
|
|
|
Embeds `ProggyClean.ttf` font by Tristan Grimmer (MIT license).
|
2016-04-11 02:34:59 +03:00
|
|
|
|
|
|
|
|
2016-04-29 00:54:13 +03:00
|
|
|
Big thank you to Omar Cornut (ocornut@github) for his [imgui](https://github.com/ocornut/imgui) library and
|
2016-04-11 02:34:59 +03:00
|
|
|
giving me the inspiration for this library, Casey Muratori for handmade hero
|
|
|
|
and his original immediate mode graphical user interface idea and Sean
|
2016-04-29 00:54:13 +03:00
|
|
|
Barret for his amazing single header [libraries](https://github.com/nothings/stb) which restored my faith
|
2016-04-11 02:34:59 +03:00
|
|
|
in libraries and brought me to create some of my own.
|
|
|
|
|
2017-02-24 21:18:27 +03:00
|
|
|
## License
|
|
|
|
|
2016-04-11 02:34:59 +03:00
|
|
|
This software is dual-licensed to the public domain and under the following
|
|
|
|
license: you are granted a perpetual, irrevocable license to copy, modify,
|
|
|
|
publish and distribute this file as you see fit.
|
|
|
|
|