2eb72b26e4
The software rasterizer is to be used with raw framebuffer devices, where no GPU or X11 is available. The demo emulates a raw framebuffer on X11 using XShmImage / XImage. Features implemented: * Drawing primitives * Drawing polygons (using Darel Rex Finley algorithm) * Drawing arcs and circles (using Bresenham's elipses algorithm) * Drawing images using nearest filtering * Bounds check on every operation * Fastpath for lines * Font rendering using nearest filtering * Window resize * Thread safe implementation by using a context * Fixed lower and upper scissors on fast-path * Adapted coding style to nuklear's style * Implemented text scissors Color formats: Define one of them at compile time. * RAWFB_RGBX_8888 (32bpp) * RAWFB_XRGB_8888 (32bpp) Tested: The library has been tested on Lenovo Thinkpad T500 and is able to render more than 30fps on a single core with no further optimizations and VSNYC enabled. TODO: * Improve font rendering by using filters. * Account font foreground color. Usage: The raw framebuffer library needs a "texture" that holds the prerendered font data. The texture is used at runtime to blit the letters onto screen. You have to provide the framebuffer address, dimension and pitch. Signed-off-by: Patrick Rudolph <siro@das-labor.org> |
||
---|---|---|
demo | ||
example | ||
extra_font | ||
.gitattributes | ||
.gitignore | ||
.travis.yml | ||
CHANGELOG.md | ||
nuklear.h | ||
package.json | ||
Readme.md |
Nuklear
This is a minimal state immediate mode graphical user interface toolkit 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, 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 commands describing primitive shapes as output. So instead of providing a layered library that tries to abstract over a number of platform and render backends it only focuses on the actual UI.
Features
- Immediate mode graphical user interface toolkit
- Single header library
- Written in C89 (ANSI C)
- Small codebase (~17kLOC)
- Focus on portability, efficiency and simplicity
- No dependencies (not even the standard library if not wanted)
- Fully skinnable and customizable
- Low memory footprint with total memory control if needed or wanted
- UTF-8 support
- No global or hidden state
- Customizable library modules (you can compile and use only what you need)
- Optional font baker and vertex buffer output
Building
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
NK_IMPLEMENTATION
in one .c/.cpp file before #include
ing this file, e.g.:
#define NK_IMPLEMENTATION
#include "nuklear.h"
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.
Gallery
Example
/* init gui state */
struct nk_context ctx;
nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font);
enum {EASY, HARD};
static int op = EASY;
static float value = 0.6f;
static int i = 20;
if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
/* fixed widget pixel width */
nk_layout_row_static(&ctx, 30, 80, 1);
if (nk_button_label(&ctx, "button")) {
/* event handling */
}
/* fixed widget window ratio width */
nk_layout_row_dynamic(&ctx, 30, 2);
if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY;
if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD;
/* custom widget pixel width */
nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
{
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);
}
nk_layout_row_end(&ctx);
}
nk_end(&ctx);
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:
- Java by Guillaume Legris
- Golang by golang-ui@github.com
- Rust by snuk182@github.com
- Chicken by wasamasa@github.comx
- Nim by zacharycarter@github.com
Credits
Developed by Micha Mettke and every direct or indirect contributor to the GitHub.
Embeds stb_texedit
, stb_truetype
and stb_rectpack
by Sean Barret (public domain)
Embeds ProggyClean.ttf
font by Tristan Grimmer (MIT license).
Big thank you to Omar Cornut (ocornut@github) for his imgui library and giving me the inspiration for this library, Casey Muratori for handmade hero and his original immediate mode graphical user interface idea and Sean Barret for his amazing single header libraries which restored my faith in libraries and brought me to create some of my own.
License
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.