Top Related Projects
Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
A single-header ANSI C immediate mode cross-platform GUI library
A simple and easy-to-use immediate-mode gui library
A tiny immediate-mode UI library
Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.
Quick Overview
Nuklear is a single-header ANSI C immediate mode GUI library. It's designed to be easily embedded into applications, providing a simple and lightweight solution for creating graphical user interfaces. Nuklear is highly portable and can be integrated into various graphics APIs and platforms.
Pros
- Lightweight and minimal: Single-header library with no dependencies
- Highly portable: Can be integrated with multiple graphics APIs and platforms
- Customizable: Allows for easy styling and theming of UI elements
- Easy to use: Immediate mode GUI paradigm simplifies UI creation and management
Cons
- Limited built-in widgets: May require additional implementation for complex UI elements
- Performance overhead: Immediate mode GUIs can be less efficient for large, complex interfaces
- Learning curve: Immediate mode GUI concept may be unfamiliar to developers used to retained mode systems
- Limited documentation: Relies heavily on examples for learning and implementation
Code Examples
- Creating a simple window:
if (nk_begin(ctx, "Demo", nk_rect(50, 50, 200, 200),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
nk_layout_row_dynamic(ctx, 30, 1);
nk_label(ctx, "Hello, Nuklear!", NK_TEXT_LEFT);
}
nk_end(ctx);
- Adding a button and handling clicks:
if (nk_button_label(ctx, "Click me!"))
{
printf("Button clicked!\n");
}
- Creating a simple form with input:
static char name[32] = "John Doe";
static int age = 30;
nk_layout_row_dynamic(ctx, 30, 2);
nk_label(ctx, "Name:", NK_TEXT_LEFT);
nk_edit_string(ctx, NK_EDIT_SIMPLE, name, &len, 32, nk_filter_default);
nk_label(ctx, "Age:", NK_TEXT_LEFT);
nk_property_int(ctx, "Age", 0, &age, 120, 1, 1);
Getting Started
- Download the
nuklear.h
header file from the repository. - Include the header in your project:
#define NK_IMPLEMENTATION #include "nuklear.h"
- Initialize Nuklear context:
struct nk_context ctx; nk_init_default(&ctx, 0);
- In your main loop, begin a new frame and create UI elements:
nk_input_begin(&ctx); // Handle input events here nk_input_end(&ctx); if (nk_begin(&ctx, "Window", nk_rect(50, 50, 200, 200), 0)) { // Add UI elements here } nk_end(&ctx);
- Render the Nuklear UI using your preferred graphics API.
Competitor Comparisons
Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
Pros of ImGui
- More feature-rich and actively maintained
- Extensive documentation and examples
- Wider community support and adoption
Cons of ImGui
- Larger codebase and potentially higher memory footprint
- Steeper learning curve for beginners
Code Comparison
ImGui:
ImGui::Begin("My Window");
ImGui::Text("Hello, world!");
if (ImGui::Button("Click me!"))
doSomething();
ImGui::End();
Nuklear:
if (nk_begin(ctx, "My Window", nk_rect(50, 50, 200, 200), 0)) {
nk_layout_row_dynamic(ctx, 30, 1);
nk_label(ctx, "Hello, world!", NK_TEXT_LEFT);
if (nk_button_label(ctx, "Click me!"))
doSomething();
}
nk_end(ctx);
Both libraries offer immediate mode GUI functionality, but ImGui provides a more C++-oriented API with RAII-style scoping, while Nuklear uses a C-style API with explicit context handling. ImGui's syntax is generally more concise and intuitive for C++ developers, whereas Nuklear's approach may be more familiar to C programmers.
A single-header ANSI C immediate mode cross-platform GUI library
Pros of Nuklear (Immediate-Mode-UI)
- More active development and maintenance
- Expanded feature set and improvements
- Larger community and contributor base
Cons of Nuklear (Immediate-Mode-UI)
- Potentially less stable due to frequent updates
- May have a steeper learning curve for newcomers
Code Comparison
Nuklear (vurtun):
struct nk_context ctx;
nk_init_default(&ctx, 0);
if (nk_begin(&ctx, "Demo", nk_rect(50, 50, 200, 200), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
nk_layout_row_static(&ctx, 30, 80, 1);
if (nk_button_label(&ctx, "Button"))
fprintf(stdout, "Button pressed!\n");
}
nk_end(&ctx);
Nuklear (Immediate-Mode-UI):
struct nk_context ctx;
nk_init_default(&ctx, 0);
if (nk_begin(&ctx, "Demo", nk_rect(50, 50, 200, 200), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
nk_layout_row_static(&ctx, 30, 80, 1);
if (nk_button_label(&ctx, "Button"))
printf("Button pressed!\n");
}
nk_end(&ctx);
The code comparison shows minimal differences, as both repositories maintain similar API structures. The main distinction lies in the project's development trajectory and community engagement rather than significant code changes.
A simple and easy-to-use immediate-mode gui library
Pros of raygui
- Designed specifically for use with the raylib game programming library
- Simpler API with fewer functions, making it easier to learn and use
- Includes a built-in style editor for customizing the GUI appearance
Cons of raygui
- Less feature-rich compared to Nuklear, with fewer widget types available
- Limited to C programming language, while Nuklear supports multiple languages
- Lacks some advanced features like layout systems and docking
Code Comparison
raygui:
GuiButton((Rectangle){ 25, 25, 125, 30 }, "Button");
GuiSlider((Rectangle){ 25, 65, 125, 30 }, "Slider", &value, 0, 100);
GuiCheckBox((Rectangle){ 25, 105, 125, 30 }, "CheckBox", &checked);
Nuklear:
if (nk_button_label(ctx, "Button")) {
// Button clicked
}
nk_slider_float(ctx, 0, &value, 100, 1.0f);
nk_checkbox_label(ctx, "CheckBox", &checked);
Both libraries offer straightforward ways to create common GUI elements, but Nuklear's API is more verbose and flexible, while raygui's is simpler and more concise.
A tiny immediate-mode UI library
Pros of microui
- Extremely lightweight and simple (under 1,000 lines of code)
- Easy to integrate with minimal dependencies
- Designed for immediate mode GUI, making it suitable for games and real-time applications
Cons of microui
- Limited set of UI elements compared to Nuklear
- Less customization options and theming capabilities
- Fewer advanced features like layout systems or complex widgets
Code Comparison
microui:
mu_begin(ctx);
if (mu_button(ctx, "Hello")) {
printf("Button pressed\n");
}
mu_end(ctx);
Nuklear:
if (nk_begin(ctx, "Window", nk_rect(50, 50, 200, 200),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_SCALABLE|
NK_WINDOW_MINIMIZABLE|NK_WINDOW_TITLE))
{
nk_layout_row_static(ctx, 30, 80, 1);
if (nk_button_label(ctx, "Hello")) {
printf("Button pressed\n");
}
}
nk_end(ctx);
The code comparison shows that microui has a more streamlined API with fewer options, while Nuklear offers more detailed control over window properties and layout.
Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.
Pros of libui
- Native look and feel on each platform (Windows, macOS, Linux)
- Simpler API for basic UI elements
- Better support for complex layouts and controls
Cons of libui
- Less customizable than Nuklear
- Larger binary size due to native dependencies
- More limited in terms of custom rendering and effects
Code Comparison
Nuklear (simple button):
if (nk_button_label(ctx, "Click me")) {
printf("Button clicked!\n");
}
libui (simple button):
uiButton *button = uiNewButton("Click me");
uiButtonOnClicked(button, onButtonClicked, NULL);
Summary
Nuklear is a lightweight, single-header immediate mode GUI library, while libui focuses on providing native-looking UIs across platforms. Nuklear offers more flexibility and customization but requires more manual work for complex layouts. libui provides a higher-level API with better support for native controls and layouts but sacrifices some customization options.
Both libraries have their strengths, and the choice between them depends on the specific requirements of your project, such as the desired look and feel, performance constraints, and the level of customization needed.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Nuklear
ALL DEVELOPMENT MOVED ELSEWHERE
Dear visitor,
this repository, issue tracker, etc. is abandoned in favor of https://github.com/Immediate-Mode-UI/Nuklear . Any activity in this issue tracker, any pull requests, etc. will be ignored.
Looking forward to hearing from you in https://github.com/Immediate-Mode-UI/Nuklear
Nuklear community
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 render backend 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 (~18kLOC)
- 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
- Documentation
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
- D by Mateusz MuszyÅski
- Golang by golang-ui@github.com
- Rust by snuk182@github.com
- Chicken by wasamasa@github.com
- Nim by zacharycarter@github.com
- Lua
- LÃVE-Nuklear by Kevin Harrison
- MoonNuklear by Stefano Trettel
- Python
- pyNuklear by William Emerison Six (ctypes-based wrapper)
- pynk by nathanrw@github.com (cffi binding)
- CSharp/.NET by cartman300@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 Barrett (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 Barrett for his amazing single header libraries which restored my faith in libraries and brought me to create some of my own. Finally Apoorva Joshi for his singe-header file packer.
License
------------------------------------------------------------------------------
This software is available under 2 licenses -- choose whichever you prefer.
------------------------------------------------------------------------------
ALTERNATIVE A - MIT License
Copyright (c) 2017 Micha Mettke
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
------------------------------------------------------------------------------
ALTERNATIVE B - Public Domain (www.unlicense.org)
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
software, either in source code form or as a compiled binary, for any purpose,
commercial or non-commercial, and by any means.
In jurisdictions that recognize copyright laws, the author or authors of this
software dedicate any and all copyright interest in the software to the public
domain. We make this dedication for the benefit of the public at large and to
the detriment of our heirs and successors. We intend this dedication to be an
overt act of relinquishment in perpetuity of all present and future rights to
this software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-----------------------------------------------------------------------------
Top Related Projects
Dear ImGui: Bloat-free Graphical User interface for C++ with minimal dependencies
A single-header ANSI C immediate mode cross-platform GUI library
A simple and easy-to-use immediate-mode gui library
A tiny immediate-mode UI library
Simple and portable (but not inflexible) GUI library in C that uses the native GUI technologies of each platform it supports.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot