Rob Loach 4 years ago
parent
commit
4522c17ed1
4 changed files with 29 additions and 23 deletions
  1. 17 16
      CMakeLists.txt
  2. 2 0
      README.md
  3. 1 1
      examples/raylib-nuklear-example.c
  4. 9 6
      include/raylib-nuklear.h

+ 17 - 16
CMakeLists.txt

@@ -2,33 +2,34 @@ cmake_minimum_required(VERSION 3.11)
 project(raylib-nuklear
 project(raylib-nuklear
     DESCRIPTION "raylib-nuklear: Nuklear immediate mode GUI for raylib."
     DESCRIPTION "raylib-nuklear: Nuklear immediate mode GUI for raylib."
     HOMEPAGE_URL "https://github.com/robloach/raylib-nuklear"
     HOMEPAGE_URL "https://github.com/robloach/raylib-nuklear"
-    VERSION 2.1.2
+    VERSION 4.0.1
     LANGUAGES C
     LANGUAGES C
 )
 )
 
 
 # raylib-nuklear
 # raylib-nuklear
 add_subdirectory(include)
 add_subdirectory(include)
 
 
-# raylib
-find_package(raylib QUIET)
-if (NOT raylib_FOUND)
-    set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
-    set(BUILD_GAMES    OFF CACHE BOOL "" FORCE)
-    add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vendor/raylib)
-endif()
-
 # Examples
 # Examples
 option(BUILD_RAYLIB_NUKLEAR_EXAMPLES "Build Examples" ON)
 option(BUILD_RAYLIB_NUKLEAR_EXAMPLES "Build Examples" ON)
 if (BUILD_RAYLIB_NUKLEAR_EXAMPLES)
 if (BUILD_RAYLIB_NUKLEAR_EXAMPLES)
+    # raylib
+    find_package(raylib QUIET)
+    if (NOT raylib_FOUND)
+        set(BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
+        set(BUILD_GAMES    OFF CACHE BOOL "" FORCE)
+        add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/vendor/raylib)
+    endif()
     add_subdirectory(examples)
     add_subdirectory(examples)
 endif()
 endif()
 
 
 # Testing
 # Testing
-include(CTest)
-enable_testing()
-if(BUILD_TESTING AND BUILD_RAYLIB_NUKLEAR_EXAMPLES)
-    set(CTEST_CUSTOM_TESTS_IGNORE
-        pkg-config--static
-    )
-    add_subdirectory(test)
+if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
+    include(CTest)
+    enable_testing()
+    if(BUILD_TESTING AND BUILD_RAYLIB_NUKLEAR_EXAMPLES)
+        set(CTEST_CUSTOM_TESTS_IGNORE
+            pkg-config--static
+        )
+        add_subdirectory(test)
+    endif()
 endif()
 endif()

+ 2 - 0
README.md

@@ -84,6 +84,8 @@ Rectangle RectangleFromNuklear(struct nk_rect rect);
 nk_rect RectangleToNuklear(Rectangle rect);
 nk_rect RectangleToNuklear(Rectangle rect);
 ```
 ```
 
 
+See the [Nuklear API documenation](https://immediate-mode-ui.github.io/Nuklear/doc/nuklear.html) for more how to use Nuklear.
+
 ## Development
 ## Development
 
 
 ```
 ```

+ 1 - 1
examples/raylib-nuklear-example.c

@@ -44,7 +44,7 @@ int main(void)
 
 
     /* GUI */
     /* GUI */
     struct nk_colorf bg = ColorToNuklearF(SKYBLUE);
     struct nk_colorf bg = ColorToNuklearF(SKYBLUE);
-    struct nk_context *ctx = InitNuklear(0);
+    struct nk_context *ctx = InitNuklear(10);
 
 
     // Main game loop
     // Main game loop
     while (!WindowShouldClose())    // Detect window close button or ESC key
     while (!WindowShouldClose())    // Detect window close button or ESC key

+ 9 - 6
include/raylib-nuklear.h

@@ -211,13 +211,14 @@ InitNuklearContext(struct nk_user_font* userFont)
 NK_API struct nk_context*
 NK_API struct nk_context*
 InitNuklear(int fontSize)
 InitNuklear(int fontSize)
 {
 {
+    // User font.
+    struct nk_user_font* userFont = (struct nk_user_font*)MemAlloc(sizeof(struct nk_user_font));
+
     // Use the default font size if desired.
     // Use the default font size if desired.
     if (fontSize <= 0) {
     if (fontSize <= 0) {
         fontSize = RAYLIB_NUKLEAR_DEFAULT_FONTSIZE;
         fontSize = RAYLIB_NUKLEAR_DEFAULT_FONTSIZE;
     }
     }
 
 
-    // User font.
-    struct nk_user_font* userFont = (struct nk_user_font*)MemAlloc(sizeof(struct nk_user_font));
     userFont->height = (float)fontSize;
     userFont->height = (float)fontSize;
     userFont->width = nk_raylib_font_get_text_width;
     userFont->width = nk_raylib_font_get_text_width;
     userFont->userdata = nk_handle_ptr(0);
     userFont->userdata = nk_handle_ptr(0);
@@ -237,13 +238,13 @@ InitNuklear(int fontSize)
 NK_API struct nk_context*
 NK_API struct nk_context*
 InitNuklearEx(Font font, float fontSize)
 InitNuklearEx(Font font, float fontSize)
 {
 {
+    // Copy the font to a new raylib font pointer.
+    struct Font* newFont = (struct Font*)MemAlloc(sizeof(struct Font));
+
     // Use the default font size if desired.
     // Use the default font size if desired.
     if (fontSize <= 0.0f) {
     if (fontSize <= 0.0f) {
         fontSize = (float)RAYLIB_NUKLEAR_DEFAULT_FONTSIZE;
         fontSize = (float)RAYLIB_NUKLEAR_DEFAULT_FONTSIZE;
     }
     }
-
-    // Copy the font to a new raylib font pointer.
-    struct Font* newFont = (struct Font*)MemAlloc(sizeof(struct Font));
     newFont->baseSize = font.baseSize;
     newFont->baseSize = font.baseSize;
     newFont->glyphCount = font.glyphCount;
     newFont->glyphCount = font.glyphCount;
     newFont->glyphPadding = font.glyphPadding;
     newFont->glyphPadding = font.glyphPadding;
@@ -665,13 +666,15 @@ UpdateNuklear(struct nk_context * ctx)
 NK_API void
 NK_API void
 UnloadNuklear(struct nk_context * ctx)
 UnloadNuklear(struct nk_context * ctx)
 {
 {
+    struct nk_user_font* userFont;
+
     // Skip unloading if it's not set.
     // Skip unloading if it's not set.
     if (ctx == NULL) {
     if (ctx == NULL) {
         return;
         return;
     }
     }
 
 
     // Unload the font.
     // Unload the font.
-    struct nk_user_font* userFont = (struct nk_user_font*)ctx->style.font;
+    userFont = (struct nk_user_font*)ctx->style.font;
     if (userFont != NULL) {
     if (userFont != NULL) {
         // Clear the raylib Font object.
         // Clear the raylib Font object.
         void* fontPtr = userFont->userdata.ptr;
         void* fontPtr = userFont->userdata.ptr;