Зеркало. Это набор инструментов графического интерфейса пользователя с минимальным состоянием и немедленным режимом работы, написанный на ANSI C
Go to file
Alexander W. Schultz b6a7791d13 disables intrinsics on SDL demos
SDL library has an issue where it expects intrinsics headers to be
provided, but intrinsics are not exactly part of a standard, so there is
no guarantee that they will be available. As such, the library allows
you to turn them off. I am disabling them to allow for better
portability and ease of compilation.
2024-10-20 23:17:02 -04:00
.github/workflows Update rawfb demos to use similar code (#629) 2024-04-06 01:27:07 -04:00
demo disables intrinsics on SDL demos 2024-10-20 23:17:02 -04:00
doc Fix typos. 2023-12-20 00:41:52 -05:00
example Fix strncpy() call to use nuklear API (#595) 2024-04-04 13:13:08 -04:00
extra_font Release Version 1.0 2016-04-14 16:26:15 +02:00
src Fix incompatible pointer types warning 2024-09-30 13:33:55 -04:00
.editorconfig utils: Apply indent_size 2 to all JSON and YAML files 2022-12-17 14:10:43 -05:00
.gitattributes Fixes newline issue on windows with the paq script 2020-06-05 10:42:36 +01:00
.gitignore doc: Add clean up, and git ignore the binary 2023-07-09 22:18:20 -04:00
clib.json Made the PR not break current API 2023-11-28 09:52:30 +01:00
LICENSE Move copyright info to its own file (#667) 2024-08-26 11:29:47 -04:00
nuklear.h Rebuild nuklear.h 2024-09-30 13:41:55 -04:00
Readme.md Move copyright info to its own file (#667) 2024-08-26 11:29:47 -04:00

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 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 layered library that tries to abstract over a number of platform and render backends, it focuses only 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 control of memory usage if needed / 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 defining the preprocessor macro NK_IMPLEMENTATION in one .c/.cpp file before #includeing 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.

screenshot screen screen2 node skinning gamepad

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);

example

Bindings

There are a number of nuklear bindings for different languages created by other authors. I cannot attest for their quality since I am not necessarily proficient in any of these languages. Furthermore there are no guarantee that all bindings will always be kept up to date:

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 single-header file packer.

License

Nuklear is avaliable under either the MIT License or public domain. See LICENSE for more info.

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.
  • Check no other parts of nuklear.h are related to the PR and thus nothing is missing.
  • 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.
  • Ensure that the contributor has bumped the appropriate version in clib.json and added their changes to the 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.