Giter Club home page Giter Club logo

raylib-nuklear's Introduction

raylib-nuklear

Use the Nuklear immediate mode cross-platform GUI library in raylib.

raylib-nuklear-example Screenshot

Usage

  1. Since this is a header-only library, you must first define RAYLIB_NUKLEAR_IMPLEMENTATION in one of your .c files...
    #define RAYLIB_NUKLEAR_IMPLEMENTATION
  2. Include the raylib-nuklear.h file...
    #include "path/to/raylib-nuklear.h"
  3. Use InitNuklear(fontSize) or InitNuklearEx(font, fontSize) to create the nuklear context...
    struct nk_context *ctx = InitNuklear(10);
  4. Build your Nuklear GUI through the standard Nuklear API
  5. Update the input for the GUI using UpdateNuklear(ctx)
  6. Render the context using DrawNuklear(ctx)
  7. Destroy the nuklear context with UnloadNuklear(ctx)

Example

#define RAYLIB_NUKLEAR_IMPLEMENTATION
#include "raylib-nuklear.h"

int main() {
    InitWindow(640, 480, "raylib-nuklear example");

    // Create the Nuklear Context
    int fontSize = 10;
    struct nk_context *ctx = InitNuklear(fontSize);

    while (!WindowShouldClose()) {
        // Update the Nuklear context, along with input
        UpdateNuklear(ctx);

        // Nuklear GUI Code
        // https://github.com/Immediate-Mode-UI/Nuklear/wiki/Window
        if (nk_begin(ctx, "Nuklear", nk_rect(100, 100, 220, 220),
                NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
            if (nk_button_label(ctx, "Button")) {
                // Button was clicked!
            }
        }
        nk_end(ctx);

        // Render
        BeginDrawing();
            ClearBackground(RAYWHITE);

            // Render the Nuklear GUI
            DrawNuklear(ctx);

        EndDrawing();
    }

    // De-initialize the Nuklear GUI
    UnloadNuklear(ctx);

    CloseWindow();
    return 0;
}

API

struct nk_context* InitNuklear(int fontSize);                // Initialize the Nuklear GUI context
struct nk_context* InitNuklearEx(Font font, float fontSize); // Initialize the Nuklear GUI context, with a custom font
void UpdateNuklear(struct nk_context * ctx);                 // Update the input state and internal components for Nuklear
void DrawNuklear(struct nk_context * ctx);                   // Render the Nuklear GUI on the screen
void UnloadNuklear(struct nk_context * ctx);                 // Deinitialize the Nuklear context
struct nk_color ColorToNuklear(Color color);                 // Convert a raylib Color to a Nuklear color object
struct nk_colorf ColorToNuklearF(Color color);               // Convert a raylib Color to a Nuklear floating color
struct Color ColorFromNuklear(struct nk_color color);        // Convert a Nuklear color to a raylib Color
struct Color ColorFromNuklearF(struct nk_colorf color);      // Convert a Nuklear floating color to a raylib Color
struct Rectangle RectangleFromNuklear(struct nk_context * ctx, struct nk_rect rect); // Convert a Nuklear rectangle to a raylib Rectangle
struct nk_rect RectangleToNuklear(struct nk_context * ctx, Rectangle rect); // Convert a raylib Rectangle to a Nuklear Rectangle
struct nk_image TextureToNuklear(Texture tex);               // Convert a raylib Texture to A Nuklear image
struct Texture TextureFromNuklear(struct nk_image img);      // Convert a Nuklear image to a raylib Texture
struct nk_image LoadNuklearImage(const char* path);          // Load a Nuklear image
void UnloadNuklearImage(struct nk_image img);                // Unload a Nuklear image. And free its data
void CleanupNuklearImage(struct nk_image img);               // Frees the data stored by the Nuklear image
void SetNuklearScaling(struct nk_context * ctx, float scaling); // Scale the graphical user interface larger or smaller (1 is the default)
float GetNuklearScaling(struct nk_context * ctx);            // Retrieves the scale of the given Nuklear contextgit

See the Nuklear API documenation for more how to use Nuklear.

Comparision

There are a few other graphical user interface solutions out there for use with raylib. While every project's needs differ, this aims to compare and contrast each one. In general, however, if you're unsure which GUI to use, use raygui.

Nuklear

Nuklear is a fully fledged immediate mode GUI library, providing a full set of controls and widgets.

Pros

  • Portability, as it's written in C99
  • Automatic layouts
  • Lots of controls
  • Documentation
  • Stable API

Cons

  • Larger code size, which can result in slower compile time
  • Slightly more complex API than raygui

raygui

raygui is a companion library for raylib, and is a tiny, lightweight immediate mode GUI.

Pros

  • Targets the same platforms as raylib
  • Tiny code size
  • Minimal API
  • Easy to use
  • Matches the coding conventions of raylib

Cons

  • No automatic layouts
  • No documentation
  • Not many advanced controls

ImGui

ImGui, used in raylib with rlImGui, is a very powerful graphical user interface for C++.

Pros

  • Pretty much an industry standard
  • Lots of advanced controls
  • Automatic layouts

Cons

  • Requires C++

Development

While this project uses CMake, CMake is not required in order to use raylib-nuklear.

git submodule update --init
mkdir build
cd build
cmake ..
make
./example/raylib-nuklear-example
make test

License

raylib-nuklear is licensed under an unmodified zlib/libpng license, which is an OSI-certified, BSD-like license that allows static linking with closed source software. Check LICENSE for further details.

raylib-nuklear's People

Contributors

8-bit-dev avatar ddexxedd avatar dejaime avatar mhcerri avatar redthing1 avatar robloach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

raylib-nuklear's Issues

`nk_label_wrap` Text wraps to new line after first character

This might be related to #13, but I'm not sure.

Here's what I'm getting:
raylib-nuklear-buggy-nk_label_wrap

And here's the code that I'm using:

if (nk_begin(NuklearGUI, "BlueDragonEngine Example", nk_rect(10, 10, 500, 480),
            NK_WINDOW_BORDER | NK_WINDOW_TITLE)) {
    nk_layout_row_dynamic(NuklearGUI, 60, 1);
    nk_label_wrap(NuklearGUI, "Welcome to the BlueDragonEngine Example. The code for this should demonstrate typical usage of the engine.");
    nk_label(NuklearGUI, "This is a 2nd label.", NK_TEXT_LEFT);
}
nk_end(NuklearGUI);

I'm assuming it has something to do with measuring the size of text, but I could be wrong.

How to include with CMake?

What I've done
In my CMakeLists.txt I have

cmake_minimum_required(VERSION 3.0)
project(minecart C)
set(CMAKE_C_STANDARD 99)

# Adding Raylib
include(FetchContent)
set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
set(BUILD_GAMES    OFF CACHE BOOL "" FORCE) # don't build the supplied example games
FetchContent_Declare(raylib GIT_REPOSITORY https://github.com/raysan5/raylib.git GIT_TAG master)
FetchContent_MakeAvailable(raylib)

# Adding raylib-nuklear
include(FetchContent)
set(RAYLIB_NUKLEAR_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) # don't build the supplied examples
FetchContent_Declare(raylib-nuklear GIT_REPOSITORY https://github.com/RobLoach/raylib-nuklear.git GIT_TAG master)
FetchContent_MakeAvailable(raylib-nuklear)

# Adding our source files
file(GLOB_RECURSE PROJECT_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/sources/*.c") # Define PROJECT_SOURCES as a list of all source files
set(PROJECT_INCLUDE "${CMAKE_CURRENT_LIST_DIR}/sources/") # Define PROJECT_INCLUDE to be the path to the include directory of the project

# Declaring our executable
add_executable(${PROJECT_NAME})
target_sources(${PROJECT_NAME} PRIVATE ${PROJECT_SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE ${PROJECT_INCLUDE})
target_link_libraries(${PROJECT_NAME} PRIVATE raylib raylib-nuklear)

# Setting ASSETS_PATH
target_compile_definitions(${PROJECT_NAME} PUBLIC ASSETS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/assets/") # Set the asset path macro to the absolute path on the dev machine
#target_compile_definitions(${PROJECT_NAME} PUBLIC ASSETS_PATH="./assets") # Set the asset path macro in release mode to a relative path that assumes the assets folder is in the same directory as the game executable

And my main.c

#define RAYLIB_NUKLEAR_IMPLEMENTATION
#include "raylib-nuklear.h"
#include "raylib.h"

#define SCREEN_WIDTH (800)
#define SCREEN_HEIGHT (450)

#define WINDOW_TITLE "Window title"
#ifndef ASSETS_PATH:
    #define ASSETS_PATH "./assets"
#endif

int main(void)
{
    InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, WINDOW_TITLE);
    SetTargetFPS(60);

    Texture2D texture = LoadTexture(ASSETS_PATH"test.png"); // Check README.md for how this works

    // Create the Nuklear Context
    int fontSize = 10;
    struct nk_context *ctx = InitNuklear(fontSize);

    while (!WindowShouldClose())
    {
        // Update the Nuklear context, along with input
        UpdateNuklear(ctx);
        // Nuklear GUI Code
        // https://github.com/Immediate-Mode-UI/Nuklear/wiki/Window
        if (nk_begin(ctx, "Nuklear", nk_rect(100, 100, 220, 220),
                NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
            if (nk_button_label(ctx, "Button")) {
                // Button was clicked!
            }
        }
        nk_end(ctx);

        BeginDrawing();

        ClearBackground(RAYWHITE);

        const int texture_x = SCREEN_WIDTH / 2 - texture.width / 2;
        const int texture_y = SCREEN_HEIGHT / 2 - texture.height / 2;
        DrawTexture(texture, texture_x, texture_y, WHITE);

        const char* text = "OMG! IT WORKS!";
        const Vector2 text_size = MeasureTextEx(GetFontDefault(), text, 20, 1);
        DrawText(text, SCREEN_WIDTH / 2 - text_size.x / 2, texture_y + texture.height + text_size.y + 10, 20, BLACK);

        DrawNuklear(ctx);
        EndDrawing();
    }

    CloseWindow();

    return 0;
}

What happens
When I build I get the following error

$ make
Consolidate compiler generated dependencies of target glfw
[ 68%] Built target glfw
Consolidate compiler generated dependencies of target raylib
[ 93%] Built target raylib
Consolidate compiler generated dependencies of target minecart
[ 96%] Building C object CMakeFiles/minecart.dir/sources/main.c.obj
D:/Minecart/sources/main.c:2:10: fatal error: raylib-nuklear.h: No such file or directory
    2 | #include "raylib-nuklear.h"
      |          ^~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [CMakeFiles/minecart.dir/build.make:77: CMakeFiles/minecart.dir/sources/main.c.obj] Error 1
make[1]: *** [CMakeFiles/Makefile2:182: CMakeFiles/minecart.dir/all] Error 2
make: *** [Makefile:156: all] Error 2

But raylib on its own works fine. What do I need to do differently?

nk_edit_strings displays incorrectly

For some reason nk_edit_strings wont display correctly. The char buffer has the correct contents but when displayed characters seem to be disappearing

Sample program

#define RAYLIB_NUKLEAR_IMPLEMENTATION
#define NK_INCLUDE_FIXED_TYPES
#define NK_ASSERT(...) (void)0
#define NK_BUTTON_TRIGGER_ON_RELEASE
#include "raylib-nuklear.h"

char edit[64] = {0};
int edit_size = 0;

int main() {
	InitWindow(640, 480, "raylib-nuklear example");

	// Create the Nuklear Context
	int fontSize = 10;
	struct nk_context *ctx = InitNuklear(fontSize);

	while (!WindowShouldClose()) {
		// Update the Nuklear context, along with input
		UpdateNuklear(ctx);

		// Nuklear GUI Code
		// https://github.com/Immediate-Mode-UI/Nuklear/wiki/Window
		if (nk_begin(ctx, "Nuklear", nk_rect(100, 100, 220, 220), NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
			nk_layout_row_dynamic(ctx, 30, 1);
			if (nk_button_label(ctx, "Button")) {
				// Button was clicked!
			}
			nk_edit_string(ctx, NK_EDIT_SIMPLE, edit, &edit_size, 64, nk_filter_default);
		}
		nk_end(ctx);

		// Render
		BeginDrawing();
			ClearBackground(RAYWHITE);

			// Render the Nuklear GUI
			DrawNuklear(ctx);

		EndDrawing();
	}

	// De-initialize the Nuklear GUI
	UnloadNuklear(ctx);

	CloseWindow();
	return 0;
}

nk_edit_strings seems to be working okay on sokol
I also tried using sokol's nuklear file and the bug is still there so it seems like the issue is in raylib-nuklear

Drawing Images starts from absolute position instead of image region.

The image draw command uses an absolute source instead of the source images region.
This makes using nk_nine_slice or sub-regions difficult or not possible.

A short fix is to use the image region as the source argument to DrawTexturePro.

I am able to correctly use slices with the following diff on raylib-nuklear.c

/**
 * Convert the given raylib texture to a Nuklear image
 */
NK_API struct nk_image TextureToNuklear(Texture tex)
{
	// Declare the img to store data and allocate memory
	// For the texture
	struct nk_image img;
	struct Texture* stored_tex = (struct Texture*)MemAlloc(sizeof(Texture));

	// Copy the data from the texture given into the new texture
	stored_tex->id = tex.id;
	stored_tex->width = tex.width;
	stored_tex->height = tex.height;
	stored_tex->mipmaps = tex.mipmaps;
	stored_tex->format = tex.format;

	// Initialize the nk_image struct
	img.handle.ptr = stored_tex;
	img.w = (nk_ushort)stored_tex->width;
	img.h = (nk_ushort)stored_tex->height;
+      // set the region so we can sub-select the image later.
+      img.region[0] = (nk_ushort)0;
+      img.region[1] = (nk_ushort)0;
+      img.region[2] = img.w;
+      img.region[3] = img.h;

	return img;
}

        case NK_COMMAND_IMAGE: {
            const struct nk_command_image *i = (const struct nk_command_image *)cmd;
            Texture texture = *(Texture*)i->img.handle.ptr;
-           Rectangle source = {0, 0, (float)texture.width, (float)texture.height};
+           Rectangle source = {i->img.region[0], i->img.region[1], (float)i->img.region[2], (float)i->img.region[3]};
            Rectangle dest = {(float)i->x * scale, (float)i->y * scale, (float)i->w * scale, (float)i->h * scale};
            Vector2 origin = {0, 0};
            Color tint = ColorFromNuklear(i->col);
            DrawTexturePro(texture, source, dest, origin, 0, tint);
        } break;

If it sounds good to fix, I'll plan to throw up a PR with tests. Absolutely thrilled about this project and how easy it makes using Nuklear with Raylib.

It seems like the button will not show in default, is it normal?

Sorry to bother, I just finished following the README, I found that the button (nk_button_label(ctx, "button")) will not show in default.
0

2

when I put the "nk_layout_row_static(ctx, 50, 150, 1);" back, the button shows.
3
4

Is it normal? I checked the wiki of nuklear and it seems like the button may show without a layout.
Could it be possible to make it happen?

Sorry for my English...

Warnings

In file included from /home/rob/Documents/raylib-nuklear/include/raylib-nuklear.h:80,
                 from /home/rob/Documents/raylib-nuklear/test/raylib-nuklear-test.c:6:
/home/rob/Documents/raylib-nuklear/include/nuklear.h: In function ‘nk_pool_init_fixed’:
/home/rob/Documents/raylib-nuklear/include/nuklear.h:19025:22: warning: conversion from ‘long unsigned int’ to ‘unsigned int’ may change value [-Wconversion]
19025 |     pool->capacity = 1 + (unsigned)(size - sizeof(struct nk_page)) / sizeof(struct nk_page_element);
      |                      ^
/home/rob/Documents/raylib-nuklear/include/nuklear.h: In function ‘nk_layout_row_calculate_usable_space’:
/home/rob/Documents/raylib-nuklear/include/nuklear.h:21306:87: warning: unused parameter ‘type’ [-Wunused-parameter]
21306 | nk_layout_row_calculate_usable_space(const struct nk_style *style, enum nk_panel_type type,
      |                                                                    ~~~~~~~~~~~~~~~~~~~^~~~
/home/rob/Documents/raylib-nuklear/include/nuklear.h: In function ‘nk_layout_widget_space’:
/home/rob/Documents/raylib-nuklear/include/nuklear.h:21864:27: warning: conversion from ‘int’ to ‘float’ may change value [-Wconversion]
21864 |     #define NK_FRAC(x) (x - (int)x) /* will be used to remove fookin gaps */
      |                           ^
/home/rob/Documents/raylib-nuklear/include/nuklear.h:21871:26: note: in expansion of macro ‘NK_FRAC’
21871 |         item_width = w + NK_FRAC(item_offset);
      |                          ^~~~~~~
/home/rob/Documents/raylib-nuklear/include/nuklear.h:21864:27: warning: conversion from ‘int’ to ‘float’ may change value [-Wconversion]
21864 |     #define NK_FRAC(x) (x - (int)x) /* will be used to remove fookin gaps */
      |                           ^
/home/rob/Documents/raylib-nuklear/include/nuklear.h:21878:26: note: in expansion of macro ‘NK_FRAC’
21878 |         item_width = w + NK_FRAC(item_offset);
      |                          ^~~~~~~
/home/rob/Documents/raylib-nuklear/include/nuklear.h:21864:27: warning: conversion from ‘int’ to ‘float’ may change value [-Wconversion]
21864 |     #define NK_FRAC(x) (x - (int)x) /* will be used to remove fookin gaps */
      |                           ^
/home/rob/Documents/raylib-nuklear/include/nuklear.h:21893:62: note: in expansion of macro ‘NK_FRAC’
21893 |         bounds->w = layout->bounds.w  * layout->row.item.w + NK_FRAC(bounds->x);
      |                                                              ^~~~~~~
/home/rob/Documents/raylib-nuklear/include/nuklear.h:21864:27: warning: conversion from ‘int’ to ‘float’ may change value [-Wconversion]
21864 |     #define NK_FRAC(x) (x - (int)x) /* will be used to remove fookin gaps */
      |                           ^
/home/rob/Documents/raylib-nuklear/include/nuklear.h:21894:63: note: in expansion of macro ‘NK_FRAC’
21894 |         bounds->h = layout->row.height * layout->row.item.h + NK_FRAC(bounds->y);
      |                                                               ^~~~~~~
/home/rob/Documents/raylib-nuklear/include/nuklear.h:21864:27: warning: conversion from ‘int’ to ‘float’ may change value [-Wconversion]
21864 |     #define NK_FRAC(x) (x - (int)x) /* will be used to remove fookin gaps */
      |                           ^
/home/rob/Documents/raylib-nuklear/include/nuklear.h:21907:26: note: in expansion of macro ‘NK_FRAC’
21907 |         item_width = w + NK_FRAC(item_offset);
      |                          ^~~~~~~
/home/rob/Documents/raylib-nuklear/include/nuklear.h:21864:27: warning: conversion from ‘int’ to ‘float’ may change value [-Wconversion]
21864 |     #define NK_FRAC(x) (x - (int)x) /* will be used to remove fookin gaps */
      |                           ^
/home/rob/Documents/raylib-nuklear/include/nuklear.h:21953:26: note: in expansion of macro ‘NK_FRAC’
21953 |         item_width = w + NK_FRAC(item_offset);
      |                          ^~~~~~~
/home/rob/Documents/raylib-nuklear/include/nuklear.h: In function ‘nk_scrollbar_behavior’:
/home/rob/Documents/raylib-nuklear/include/nuklear.h:25081:26: warning: conversion to ‘int’ from ‘unsigned int’ may change the sign of the result [-Wsign-conversion]
25081 |     left_mouse_clicked = in->mouse.buttons[NK_BUTTON_LEFT].clicked;
      |                          ^~
At top level:
/home/rob/Documents/raylib-nuklear/include/nuklear.h:6129:1: warning: ‘nk_cos’ defined but not used [-Wunused-function]
 6129 | nk_cos(float x)
      | ^~~~~~
/home/rob/Documents/raylib-nuklear/include/nuklear.h:6113:1: warning: ‘nk_sin’ defined but not used [-Wunused-function]
 6113 | nk_sin(float x)
      | ^~~~~~
/home/rob/Documents/raylib-nuklear/include/nuklear.h:6099:1: warning: ‘nk_inv_sqrt’ defined but not used [-Wunused-function]
 6099 | nk_inv_sqrt(float n)
      | ^~~~~~~~~~~
[100%] Linking C executable raylib-nuklear-test
[build] ../dependencies/raylib-nuklear.h: In function ‘void DrawNuklear(nk_context*)’:
[build] ../dependencies/raylib-nuklear.h:319:55: warning: narrowing conversion of ‘(short int)l->nk_command_line::begin.nk_vec2i::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   319 |                 Vector2 startPos = (Vector2){l->begin.x, l->begin.y};
[build]       |                                              ~~~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:319:67: warning: narrowing conversion of ‘(short int)l->nk_command_line::begin.nk_vec2i::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   319 |                 Vector2 startPos = (Vector2){l->begin.x, l->begin.y};
[build]       |                                                          ~~~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:320:51: warning: narrowing conversion of ‘(short int)l->nk_command_line::end.nk_vec2i::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   320 |                 Vector2 endPos = (Vector2){l->end.x, l->end.y};
[build]       |                                            ~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:320:61: warning: narrowing conversion of ‘(short int)l->nk_command_line::end.nk_vec2i::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   320 |                 Vector2 endPos = (Vector2){l->end.x, l->end.y};
[build]       |                                                      ~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:329:52: warning: narrowing conversion of ‘(short int)q->nk_command_curve::begin.nk_vec2i::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   329 |                 Vector2 start = (Vector2){q->begin.x, q->begin.y};
[build]       |                                           ~~~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:329:64: warning: narrowing conversion of ‘(short int)q->nk_command_curve::begin.nk_vec2i::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   329 |                 Vector2 start = (Vector2){q->begin.x, q->begin.y};
[build]       |                                                       ~~~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:332:48: warning: narrowing conversion of ‘(short int)q->nk_command_curve::end.nk_vec2i::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   332 |                 Vector2 end = (Vector2){q->end.x, q->end.y};
[build]       |                                         ~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:332:58: warning: narrowing conversion of ‘(short int)q->nk_command_curve::end.nk_vec2i::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   332 |                 Vector2 end = (Vector2){q->end.x, q->end.y};
[build]       |                                                   ~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:343:49: warning: narrowing conversion of ‘(short int)r->nk_command_rect::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   343 |                 Rectangle rect = (Rectangle){r->x, r->y, r->w, r->h};
[build]       |                                              ~~~^
[build] ../dependencies/raylib-nuklear.h:343:55: warning: narrowing conversion of ‘(short int)r->nk_command_rect::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   343 |                 Rectangle rect = (Rectangle){r->x, r->y, r->w, r->h};
[build]       |                                                    ~~~^
[build] ../dependencies/raylib-nuklear.h:343:61: warning: narrowing conversion of ‘(short unsigned int)r->nk_command_rect::w’ from ‘short unsigned int’ to ‘float’ [-Wnarrowing]
[build]   343 |                 Rectangle rect = (Rectangle){r->x, r->y, r->w, r->h};
[build]       |                                                          ~~~^
[build] ../dependencies/raylib-nuklear.h:343:67: warning: narrowing conversion of ‘(short unsigned int)r->nk_command_rect::h’ from ‘short unsigned int’ to ‘float’ [-Wnarrowing]
[build]   343 |                 Rectangle rect = (Rectangle){r->x, r->y, r->w, r->h};
[build]       |                                                                ~~~^
[build] ../dependencies/raylib-nuklear.h:357:49: warning: narrowing conversion of ‘(short int)r->nk_command_rect_filled::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   357 |                 Rectangle rect = (Rectangle){r->x, r->y, r->w, r->h};
[build]       |                                              ~~~^
[build] ../dependencies/raylib-nuklear.h:357:55: warning: narrowing conversion of ‘(short int)r->nk_command_rect_filled::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   357 |                 Rectangle rect = (Rectangle){r->x, r->y, r->w, r->h};
[build]       |                                                    ~~~^
[build] ../dependencies/raylib-nuklear.h:357:61: warning: narrowing conversion of ‘(short unsigned int)r->nk_command_rect_filled::w’ from ‘short unsigned int’ to ‘float’ [-Wnarrowing]
[build]   357 |                 Rectangle rect = (Rectangle){r->x, r->y, r->w, r->h};
[build]       |                                                          ~~~^
[build] ../dependencies/raylib-nuklear.h:357:67: warning: narrowing conversion of ‘(short unsigned int)r->nk_command_rect_filled::h’ from ‘short unsigned int’ to ‘float’ [-Wnarrowing]
[build]   357 |                 Rectangle rect = (Rectangle){r->x, r->y, r->w, r->h};
[build]       |                                                                ~~~^
[build] ../dependencies/raylib-nuklear.h:370:61: warning: narrowing conversion of ‘(short int)rectangle->nk_command_rect_multi_color::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   370 |                 Rectangle position = (Rectangle){rectangle->x, rectangle->y, rectangle->w, rectangle->h};
[build]       |                                                  ~~~~~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:370:75: warning: narrowing conversion of ‘(short int)rectangle->nk_command_rect_multi_color::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   370 |                 Rectangle position = (Rectangle){rectangle->x, rectangle->y, rectangle->w, rectangle->h};
[build]       |                                                                ~~~~~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:370:89: warning: narrowing conversion of ‘(short unsigned int)rectangle->nk_command_rect_multi_color::w’ from ‘short unsigned int’ to ‘float’ [-Wnarrowing]
[build]   370 |                 Rectangle position = (Rectangle){rectangle->x, rectangle->y, rectangle->w, rectangle->h};
[build]       |                                                                              ~~~~~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:370:103: warning: narrowing conversion of ‘(short unsigned int)rectangle->nk_command_rect_multi_color::h’ from ‘short unsigned int’ to ‘float’ [-Wnarrowing]
[build]   370 |                 Rectangle position = (Rectangle){rectangle->x, rectangle->y, rectangle->w, rectangle->h};
[build]       |                                                                                            ~~~~~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:396:38: warning: narrowing conversion of ‘(short int)a->nk_command_arc::cx’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   396 |                 Vector2 center = {a->cx, a->cy};
[build]       |                                   ~~~^~
[build] ../dependencies/raylib-nuklear.h:396:45: warning: narrowing conversion of ‘(short int)a->nk_command_arc::cy’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   396 |                 Vector2 center = {a->cx, a->cy};
[build]       |                                          ~~~^~
[build] ../dependencies/raylib-nuklear.h:409:38: warning: narrowing conversion of ‘(short int)a->nk_command_arc::cx’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   409 |                 Vector2 center = {a->cx, a->cy};
[build]       |                                   ~~~^~
[build] ../dependencies/raylib-nuklear.h:409:45: warning: narrowing conversion of ‘(short int)a->nk_command_arc::cy’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   409 |                 Vector2 center = {a->cx, a->cy};
[build]       |                                          ~~~^~
[build] ../dependencies/raylib-nuklear.h:419:50: warning: narrowing conversion of ‘(short int)t->nk_command_triangle::b.nk_vec2i::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   419 |                 DrawTriangleLines((Vector2){t->b.x, t->b.y}, (Vector2){t->a.x, t->a.y}, (Vector2){t->c.x, t->c.y}, color);
[build]       |                                             ~~~~~^
[build] ../dependencies/raylib-nuklear.h:419:58: warning: narrowing conversion of ‘(short int)t->nk_command_triangle::b.nk_vec2i::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   419 |                 DrawTriangleLines((Vector2){t->b.x, t->b.y}, (Vector2){t->a.x, t->a.y}, (Vector2){t->c.x, t->c.y}, color);
[build]       |                                                     ~~~~~^
[build] ../dependencies/raylib-nuklear.h:419:77: warning: narrowing conversion of ‘(short int)t->nk_command_triangle::a.nk_vec2i::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   419 |                 DrawTriangleLines((Vector2){t->b.x, t->b.y}, (Vector2){t->a.x, t->a.y}, (Vector2){t->c.x, t->c.y}, color);
[build]       |                                                                        ~~~~~^
[build] ../dependencies/raylib-nuklear.h:419:85: warning: narrowing conversion of ‘(short int)t->nk_command_triangle::a.nk_vec2i::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   419 |                 DrawTriangleLines((Vector2){t->b.x, t->b.y}, (Vector2){t->a.x, t->a.y}, (Vector2){t->c.x, t->c.y}, color);
[build]       |                                                                                ~~~~~^
[build] ../dependencies/raylib-nuklear.h:419:104: warning: narrowing conversion of ‘(short int)t->nk_command_triangle::c.nk_vec2i::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   419 |                 DrawTriangleLines((Vector2){t->b.x, t->b.y}, (Vector2){t->a.x, t->a.y}, (Vector2){t->c.x, t->c.y}, color);
[build]       |                                                                                                   ~~~~~^
[build] ../dependencies/raylib-nuklear.h:419:112: warning: narrowing conversion of ‘(short int)t->nk_command_triangle::c.nk_vec2i::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   419 |                 DrawTriangleLines((Vector2){t->b.x, t->b.y}, (Vector2){t->a.x, t->a.y}, (Vector2){t->c.x, t->c.y}, color);
[build]       |                                                                                                           ~~~~~^
[build] ../dependencies/raylib-nuklear.h:426:45: warning: narrowing conversion of ‘(short int)t->nk_command_triangle_filled::b.nk_vec2i::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   426 |                 DrawTriangle((Vector2){t->b.x, t->b.y}, (Vector2){t->a.x, t->a.y}, (Vector2){t->c.x, t->c.y}, color);
[build]       |                                        ~~~~~^
[build] ../dependencies/raylib-nuklear.h:426:53: warning: narrowing conversion of ‘(short int)t->nk_command_triangle_filled::b.nk_vec2i::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   426 |                 DrawTriangle((Vector2){t->b.x, t->b.y}, (Vector2){t->a.x, t->a.y}, (Vector2){t->c.x, t->c.y}, color);
[build]       |                                                ~~~~~^
[build] ../dependencies/raylib-nuklear.h:426:72: warning: narrowing conversion of ‘(short int)t->nk_command_triangle_filled::a.nk_vec2i::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   426 |                 DrawTriangle((Vector2){t->b.x, t->b.y}, (Vector2){t->a.x, t->a.y}, (Vector2){t->c.x, t->c.y}, color);
[build]       |                                                                   ~~~~~^
[build] ../dependencies/raylib-nuklear.h:426:80: warning: narrowing conversion of ‘(short int)t->nk_command_triangle_filled::a.nk_vec2i::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   426 |                 DrawTriangle((Vector2){t->b.x, t->b.y}, (Vector2){t->a.x, t->a.y}, (Vector2){t->c.x, t->c.y}, color);
[build]       |                                                                           ~~~~~^
[build] ../dependencies/raylib-nuklear.h:426:99: warning: narrowing conversion of ‘(short int)t->nk_command_triangle_filled::c.nk_vec2i::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   426 |                 DrawTriangle((Vector2){t->b.x, t->b.y}, (Vector2){t->a.x, t->a.y}, (Vector2){t->c.x, t->c.y}, color);
[build]       |                                                                                              ~~~~~^
[build] ../dependencies/raylib-nuklear.h:426:107: warning: narrowing conversion of ‘(short int)t->nk_command_triangle_filled::c.nk_vec2i::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   426 |                 DrawTriangle((Vector2){t->b.x, t->b.y}, (Vector2){t->a.x, t->a.y}, (Vector2){t->c.x, t->c.y}, color);
[build]       |                                                                                                      ~~~~~^
[build] ../dependencies/raylib-nuklear.h:435:56: warning: narrowing conversion of ‘(short int)p->nk_command_polygon::points[i].nk_vec2i::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   435 |                     points[i] = (Vector2){p->points[i].x, p->points[i].y};
[build]       |                                           ~~~~~~~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:435:72: warning: narrowing conversion of ‘(short int)p->nk_command_polygon::points[i].nk_vec2i::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   435 |                     points[i] = (Vector2){p->points[i].x, p->points[i].y};
[build]       |                                                           ~~~~~~~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:447:56: warning: narrowing conversion of ‘(short int)p->nk_command_polygon_filled::points[i].nk_vec2i::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   447 |                     points[i] = (Vector2){p->points[i].x, p->points[i].y};
[build]       |                                           ~~~~~~~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:447:72: warning: narrowing conversion of ‘(short int)p->nk_command_polygon_filled::points[i].nk_vec2i::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   447 |                     points[i] = (Vector2){p->points[i].x, p->points[i].y};
[build]       |                                                           ~~~~~~~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:458:56: warning: narrowing conversion of ‘(short int)p->nk_command_polyline::points[i].nk_vec2i::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   458 |                     points[i] = (Vector2){p->points[i].x, p->points[i].y};
[build]       |                                           ~~~~~~~~~~~~~^
[build] ../dependencies/raylib-nuklear.h:458:72: warning: narrowing conversion of ‘(short int)p->nk_command_polyline::points[i].nk_vec2i::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   458 |                     points[i] = (Vector2){p->points[i].x, p->points[i].y};
[build]       |                                                           ~~~~~~~~~~~~~^
[build] In file included from ../src/main.cpp:2:
[build] ../dependencies/raylib-nuklear.h:492:38: warning: narrowing conversion of ‘(short int)i->nk_command_image::x’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   492 |                 Rectangle dest = {i->x, i->y, i->w, i->h};
[build]       |                                   ~~~^
[build] ../dependencies/raylib-nuklear.h:492:44: warning: narrowing conversion of ‘(short int)i->nk_command_image::y’ from ‘short int’ to ‘float’ [-Wnarrowing]
[build]   492 |                 Rectangle dest = {i->x, i->y, i->w, i->h};
[build]       |                                         ~~~^
[build] ../dependencies/raylib-nuklear.h:492:50: warning: narrowing conversion of ‘(short unsigned int)i->nk_command_image::w’ from ‘short unsigned int’ to ‘float’ [-Wnarrowing]
[build]   492 |                 Rectangle dest = {i->x, i->y, i->w, i->h};
[build]       |                                               ~~~^
[build] ../dependencies/raylib-nuklear.h:492:56: warning: narrowing conversion of ‘(short unsigned int)i->nk_command_image::h’ from ‘short unsigned int’ to ‘float’ [-Wnarrowing]
[build]   492 |                 Rectangle dest = {i->x, i->y, i->w, i->h};
[build]       |                                                     ~~~^
[build] ../dependencies/raylib-nuklear.h: In function ‘void UpdateNuklear(nk_context*)’:
[build] ../dependencies/raylib-nuklear.h:656:66: error: invalid conversion from ‘int’ to ‘nk_buttons’ [-fpermissive]
[build]   656 |             nk_input_button(ctx, nk_raylib_translate_mouse_button(button), GetMouseX(), GetMouseY(), IsMouseButtonDown(button));
[build]       |                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
[build]       |                                                                  |
[build]       |                                                                  int
[build] In file included from ../dependencies/raylib-nuklear.h:80,
[build]                  from ../src/main.cpp:2:
[build] ../dependencies/nuklear.h:13998:57: note:   initializing argument 2 of ‘void nk_input_button(nk_context*, nk_buttons, int, int, int)’
[build] 13998 | nk_input_button(struct nk_context *ctx, enum nk_buttons id, int x, int y, int down)

Allow Static Overrie

https://github.com/nothings/stb/blob/master/docs/stb_howto.txt

  1. ALLOW STATIC IMPLEMENTATION

Have a #define which makes function declarations and
function definitions static. This makes the implementation
private to the source file that creates it. This allows
people to use your library multiple times in their project
without collision. (This is only necessary if your library
has configuration macros or global state, or if your
library has multiple versions that are not backwards
compatible. I've run into both of those cases.)

Support UI/HIDPI scaling

Right now it is very small and blurry at high res. HIDPI scale will work better on high res displays.

Unable to compile with MSVC because of Variable-Length Arrays in DrawNuklear

I'm not sure if there would be a performance impact but the easiest fix I could think of is just replacing the following lines:

Vector2 points[p->point_count];

Vector2 points[p->point_count];

Vector2 points[p->point_count];

with:

Vector2 * points = MemAlloc(p->point_count * sizeof(Vector2));

and the appropriate:

MemFree(points);

at the end of each case.

Errors when including raylib-nuklear.h

I'm attempting to compile the example in the read me. I'm using Clang in Ubuntu (in WSL) and cross compiling to Windows. I get these errors when compiling:

clang++ -o main.o -c -static --target=x86_64-w64-windows-gnu -std=c++17 -Iinclude main.cpp
In file included from main.cpp:2:
In file included from include/raylib-nuklear.h:45:
include/nuklear.h:435:1: error: '_dummy_array435' declared as an array with a negative size
NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/nuklear.h:293:75: note: expanded from macro 'NK_STATIC_ASSERT'
  #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1]
                                                                          ^~~~~~~~~~
include/nuklear.h:436:1: error: '_dummy_array436' declared as an array with a negative size
NK_STATIC_ASSERT(sizeof(nk_ptr) >= sizeof(void*));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/nuklear.h:293:75: note: expanded from macro 'NK_STATIC_ASSERT'
  #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1]
                                                                          ^~~~~~~~~~
In file included from main.cpp:2:
In file included from include/raylib-nuklear.h:105:
include/nuklear.h:5813:1: error: '_dummy_array5813' declared as an array with a negative size
NK_STATIC_ASSERT(sizeof(nk_size) >= sizeof(void*));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/nuklear.h:293:75: note: expanded from macro 'NK_STATIC_ASSERT'
  #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1]
                                                                          ^~~~~~~~~~
In file included from main.cpp:2:
In file included from include/raylib-nuklear.h:105:
include/nuklear.h:5814:1: error: '_dummy_array5814' declared as an array with a negative size
NK_STATIC_ASSERT(sizeof(nk_ptr) == sizeof(void*));
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/nuklear.h:293:75: note: expanded from macro 'NK_STATIC_ASSERT'
  #define NK_STATIC_ASSERT(exp) typedef char NK_UNIQUE_NAME(_dummy_array)[(exp)?1:-1]
                                                                          ^~~~~~~~~~
In file included from main.cpp:2:
In file included from include/raylib-nuklear.h:105:
include/nuklear.h:6442:13: error: cast from pointer to smaller type 'nk_ptr' (aka 'unsigned long') loses information
        t = (nk_ptr)src; /* only need low bits */
            ^~~~~~~~~~~
include/nuklear.h:6443:18: error: cast from pointer to smaller type 'nk_ptr' (aka 'unsigned long') loses information
        if ((t | (nk_ptr)dst) & nk_wmask) {
                 ^~~~~~~~~~~
include/nuklear.h:6444:22: error: cast from pointer to smaller type 'nk_ptr' (aka 'unsigned long') loses information
            if ((t ^ (nk_ptr)dst) & nk_wmask || length < nk_wsize)
                     ^~~~~~~~~~~
include/nuklear.h:6459:13: error: cast from pointer to smaller type 'nk_ptr' (aka 'unsigned long') loses information
        t = (nk_ptr)src;
            ^~~~~~~~~~~
include/nuklear.h:6460:18: error: cast from pointer to smaller type 'nk_ptr' (aka 'unsigned long') loses information
        if ((t | (nk_ptr)dst) & nk_wmask) {
                 ^~~~~~~~~~~
include/nuklear.h:6461:22: error: cast from pointer to smaller type 'nk_ptr' (aka 'unsigned long') loses information
            if ((t ^ (nk_ptr)dst) & nk_wmask || length <= nk_wsize)
                     ^~~~~~~~~~~
In file included from main.cpp:2:
include/raylib-nuklear.h:456:26: error: cannot initialize a variable of type 'Vector2 *' with an rvalue of type 'void *'
                Vector2* points = MemAlloc(p->point_count * (unsigned short)sizeof(Vector2));
                         ^        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/raylib-nuklear.h:470:26: error: cannot initialize a variable of type 'Vector2 *' with an rvalue of type 'void *'
                Vector2* points = MemAlloc(p->point_count * (unsigned short)sizeof(Vector2));
                         ^        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/raylib-nuklear.h:484:26: error: cannot initialize a variable of type 'Vector2 *' with an rvalue of type 'void *'
                Vector2* points = MemAlloc(p->point_count * (unsigned short)sizeof(Vector2));
                         ^        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
include/raylib-nuklear.h:752:11: error: cannot initialize a variable of type 'Texture *' with an rvalue of type 'void *'
        Texture* stored_tex = malloc(sizeof(Texture));
                 ^            ~~~~~~~~~~~~~~~~~~~~~~~
14 errors generated.

Input handling should stop on command

Noticing when using nk_edit_string that text handling can be a bit erratic.

An example is triggering Select All which is Ctrl + A.
raylib-nuklear correctly processes this input, but also keeps going through the rest of the keys, so what ends up happening for me is

  1. Enter text
  2. Press Ctrl + a
  3. The text is selected, and a is immediately inserted over the selection.

Expected behavior

nk_raylib_input_keyboard returns after an atomic command is captured.

Actual behavior

Commands run in succession unintentionally.

Can't compile without -fpermissive on with gnu g++ and std>=c++11.

I believe this is specific to new C++ and only on standard C++11 and above.

Compiling without -fpermissive outputs the following:
Output Paste

The problem seems to be in line 656:

for (int button = MOUSE_LEFT_BUTTON; button <= MOUSE_MIDDLE_BUTTON; button++) {
    nk_input_button(ctx, nk_raylib_translate_mouse_button(button), GetMouseX(), GetMouseY(), IsMouseButtonDown(button));
}

more specifically, the nk_raylib_translate_mouse_button(button) call stops compilation without -fpermissive.

From reading the code, I assume that for loop goes through 3 different values: MOUSE_LEFT_BUTTON, MOUSE_RIGHT_BUTTON and MOUSE_MIDDLE_BUTTON, which are of the int type.

I might be missing something, but in my test I simply replaced that loop with these and it seems to work, and compiles up to the latest C++20 standard, without -fpermissive.

nk_input_button(ctx, NK_BUTTON_LEFT, GetMouseX(), GetMouseY(), IsMouseButtonDown(NK_BUTTON_LEFT));
nk_input_button(ctx, NK_BUTTON_RIGHT, GetMouseX(), GetMouseY(), IsMouseButtonDown(NK_BUTTON_RIGHT));
nk_input_button(ctx, NK_BUTTON_MIDDLE, GetMouseX(), GetMouseY(), IsMouseButtonDown(NK_BUTTON_MIDDLE));
nk_input_button(ctx, NK_BUTTON_MAX, GetMouseX(), GetMouseY(), IsMouseButtonDown(NK_BUTTON_MAX));

This saves the problematic implicit cast, and also the control variables and jumping of the for loop. I'm not sure about NK_BUTTON_MAX or if I even need to have that last call (complete newb with nk).

Thank you for this integration!

Nuklear API wrapper functions

Provide wrapper functions for the Raylib standards...

Before

if (nk_begin(ctx, "Nuklear", nk_rect(WINDOW_WIDTH/2 - 110, WINDOW_HEIGHT/2 - 110, 220, 220),
             NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE))
{
    // Widgets code here
}
    nk_end(ctx);

After

if (NuklearBegin(ctx, "Nuklear", (Rectangle){WINDOW_WIDTH/2 - 110, WINDOW_HEIGHT/2 - 110, 220, 220},
             NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE))
{
    // Widgets code here
}
NuklearEnd(ctx);

Cleaner API

Wrap the nk_context* in a struct named Nuklear, and rename some of the functions to be more raylib-esque.

Nuklear nuklear = InitNuklear()
UpdateNuklear()
DrawNuklear()
UnloadNuklear()

Not make

After strict following the installation instructions, the make command did not executes:
returns message:

make: *** No targets specified and no makefile found. Stop.

Can help me, what do wrong?

Left-side of Button in Demo is cropped

Hi,

I'm seeing font rendering quality issues under Windows. Clean OpenGL Nuklear simple demo with Roboto-Medium 14 pts looks fine while the raylib-nuklear demo, not so much. Images below demonstrate the problem. MSAA x4 is enabled in raylib demo.

OpenGL 3.3 implementation:
nuklear_ogl33

Raylib-nuklear:
nuklear_raylib

The button also appears cut off at the left side with raylib-nuklear.

Windows are not properly closed.

If you draw a single window and try to close it, the window do not close.

The above code is a small example of this issue.

int main() {
    InitWindow(640, 480, "raylib-nuklear example");

    // Create the Nuklear Context
    int fontSize = 10;
    struct nk_context *ctx = InitNuklear(fontSize);

    while (!WindowShouldClose()) {
        // Update the Nuklear context, along with input
        UpdateNuklear(ctx);

        // Nuklear GUI Code
        // https://github.com/Immediate-Mode-UI/Nuklear/wiki/Window
        if (nk_begin(ctx, "Nuklear", nk_rect(100, 100, 220, 220),
                NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
            if (nk_button_label(ctx, "Button")) {
                // Button was clicked!
            }
        }
        nk_end(ctx);

        // Render
        BeginDrawing();
            ClearBackground(RAYWHITE);

            // Render the Nuklear GUI
            DrawNuklear(ctx);

        EndDrawing();
    }

    // De-initialize the Nuklear GUI
    UnloadNuklear(ctx);

    CloseWindow();
    return 0;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.