-
Notifications
You must be signed in to change notification settings - Fork 679
feat: include "nuklear_config.h" when NK_INCLUDE_CONFIG is defined #955
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,98 +18,7 @@ | |
| #define SDL_MAIN_USE_CALLBACKS | ||
| #include <SDL3/SDL_main.h> | ||
|
|
||
| /* =============================================================== | ||
| * | ||
| * CONFIG | ||
| * | ||
| * ===============================================================*/ | ||
|
|
||
| /* optional: sdl3_renderer does not need any of these defines | ||
| * (but some examples might need them, so be careful) */ | ||
| #define NK_INCLUDE_STANDARD_VARARGS | ||
| #define NK_INCLUDE_STANDARD_IO | ||
|
|
||
| /* note that sdl3_renderer comes with nk_sdl_style_set_debug_font() | ||
| * so you may wish to use that instead of font baking */ | ||
| #define NK_INCLUDE_FONT_BAKING | ||
| #define NK_INCLUDE_DEFAULT_FONT | ||
|
|
||
| /* note that sdl3_renderer comes with nk_sdl_allocator() | ||
| * and you probably want to use that allocator instead of the default ones */ | ||
| /*#define NK_INCLUDE_DEFAULT_ALLOCATOR*/ | ||
|
|
||
| /* mandatory: sdl3_renderer depends on those defines */ | ||
| #define NK_INCLUDE_COMMAND_USERDATA | ||
| #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT | ||
|
|
||
|
|
||
| /* We can re-use the types provided by SDL which are extremely portable, | ||
| * so there is no need for Nuklear to detect those on its own */ | ||
| /*#define NK_INCLUDE_FIXED_TYPES*/ | ||
| #ifndef NK_INCLUDE_FIXED_TYPES | ||
| #define NK_INT8 Sint8 | ||
| #define NK_UINT8 Uint8 | ||
| #define NK_INT16 Sint16 | ||
| #define NK_UINT16 Uint16 | ||
| #define NK_INT32 Sint32 | ||
| #define NK_UINT32 Uint32 | ||
| /* SDL guarantees 'uintptr_t' typedef */ | ||
| #define NK_SIZE_TYPE uintptr_t | ||
| #define NK_POINTER_TYPE uintptr_t | ||
| #endif | ||
|
|
||
| /* We can reuse the `bool` symbol because SDL3 guarantees its existence */ | ||
| /*#define NK_INCLUDE_STANDARD_BOOL*/ | ||
| #ifndef NK_INCLUDE_STANDARD_BOOL | ||
| #define NK_BOOL bool | ||
| #endif | ||
|
|
||
| /* We can re-use various portable libc functions provided by SDL */ | ||
| #define NK_ASSERT(condition) SDL_assert(condition) | ||
| #define NK_STATIC_ASSERT(exp) SDL_COMPILE_TIME_ASSERT(, exp) | ||
| #define NK_MEMSET(dst, c, len) SDL_memset(dst, c, len) | ||
| #define NK_MEMCPY(dst, src, len) SDL_memcpy(dst, src, len) | ||
| #define NK_VSNPRINTF(s, n, f, a) SDL_vsnprintf(s, n, f, a) | ||
| #define NK_STRTOD(str, endptr) SDL_strtod(str, endptr) | ||
|
|
||
| /* SDL3 does not provide "dtoa" (only integer versions) | ||
| * but we can emulate it with SDL_snprintf */ | ||
| static char* nk_sdl_dtoa(char *str, double d); | ||
| #define NK_DTOA(str, d) nk_sdl_dtoa(str, d) | ||
|
|
||
| /* SDL can also provide us with math functions, but beware that Nuklear's own | ||
| * implementation can be slightly faster at the cost of some precision */ | ||
| #define NK_INV_SQRT(f) (1.0f / SDL_sqrtf(f)) | ||
| #define NK_SIN(f) SDL_sinf(f) | ||
| #define NK_COS(f) SDL_cosf(f) | ||
|
|
||
| /* HACK: Nuklear pulls two stb libraries in order to use font baking | ||
| * those libraries pull in some libc headers internally, creating a linkage dependency, | ||
| * so you’ll most likely want to use SDL symbols instead */ | ||
| #define STBTT_ifloor(x) ((int)SDL_floor(x)) | ||
| #define STBTT_iceil(x) ((int)SDL_ceil(x)) | ||
| #define STBTT_sqrt(x) SDL_sqrt(x) | ||
| #define STBTT_pow(x,y) SDL_pow(x,y) | ||
| #define STBTT_fmod(x,y) SDL_fmod(x,y) | ||
| #define STBTT_cos(x) SDL_cosf(x) | ||
| #define STBTT_acos(x) SDL_acos(x) | ||
| #define STBTT_fabs(x) SDL_fabs(x) | ||
| #define STBTT_assert(x) SDL_assert(x) | ||
| #define STBTT_strlen(x) SDL_strlen(x) | ||
| #define STBTT_memcpy SDL_memcpy | ||
| #define STBTT_memset SDL_memset | ||
| #define stbtt_uint8 Uint8 | ||
| #define stbtt_int8 Sint8 | ||
| #define stbtt_uint16 Uint16 | ||
| #define stbtt_int16 Sint16 | ||
| #define stbtt_uint32 Uint32 | ||
| #define stbtt_int32 Sint32 | ||
| #define STBRP_SORT SDL_qsort | ||
| #define STBRP_ASSERT SDL_assert | ||
| /* There is no need to define STBTT_malloc/STBTT_free macros | ||
| * Nuklear will define those to user-provided nk_allocator */ | ||
|
|
||
|
|
||
| #include "./nuklear_sdl3_renderer_config.h" | ||
| #define NK_IMPLEMENTATION | ||
| #include "../../nuklear.h" | ||
| #define NK_SDL3_RENDERER_IMPLEMENTATION | ||
|
|
@@ -421,12 +330,3 @@ SDL_AppQuit(void* appstate, SDL_AppResult result) | |
| } | ||
| } | ||
|
|
||
| static char* | ||
| nk_sdl_dtoa(char *str, double d) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it make sense to have this be part of the render instead of the config?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, not really. Every our demo works in the way that nuklear.h has to be included BEFORE the backend. If I would put it into the backend, it would not propagate correctly to nuklear.h, or would create some kind of circular dependency. It's just not possible without creating a mess. We already talked about something similar at #884 (comment)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small note: this thing should probably be |
||
| { | ||
| NK_ASSERT(str); | ||
| if (!str) return NULL; | ||
| (void)SDL_snprintf(str, 99999, "%.17g", d); | ||
| return str; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /* nuklear - public domain */ | ||
|
|
||
| /* =============================================================== | ||
| * | ||
| * CONFIG | ||
| * | ||
| * ===============================================================*/ | ||
|
|
||
| #ifndef NK_SDL3_RENDERER_CONFIG_H_ | ||
| #define NK_SDL3_RENDERER_CONFIG_H_ | ||
|
|
||
| #include <SDL3/SDL.h> | ||
|
|
||
| /* optional: sdl3_renderer does not need any of these defines | ||
| * (but some examples might need them, so be careful) */ | ||
| #define NK_INCLUDE_STANDARD_VARARGS | ||
| #define NK_INCLUDE_STANDARD_IO | ||
|
|
||
| /* note that sdl3_renderer comes with nk_sdl_style_set_debug_font() | ||
| * so you may wish to use that instead of font baking */ | ||
| #define NK_INCLUDE_FONT_BAKING | ||
| #define NK_INCLUDE_DEFAULT_FONT | ||
|
|
||
| /* note that sdl3_renderer comes with nk_sdl_allocator() | ||
| * and you probably want to use that allocator instead of the default ones */ | ||
| /*#define NK_INCLUDE_DEFAULT_ALLOCATOR*/ | ||
|
|
||
| /* mandatory: sdl3_renderer depends on those defines */ | ||
| #define NK_INCLUDE_COMMAND_USERDATA | ||
| #define NK_INCLUDE_VERTEX_BUFFER_OUTPUT | ||
|
|
||
|
|
||
| /* We can re-use the types provided by SDL which are extremely portable, | ||
| * so there is no need for Nuklear to detect those on its own */ | ||
| /*#define NK_INCLUDE_FIXED_TYPES*/ | ||
| #ifndef NK_INCLUDE_FIXED_TYPES | ||
| #define NK_INT8 Sint8 | ||
| #define NK_UINT8 Uint8 | ||
| #define NK_INT16 Sint16 | ||
| #define NK_UINT16 Uint16 | ||
| #define NK_INT32 Sint32 | ||
| #define NK_UINT32 Uint32 | ||
| /* SDL guarantees 'uintptr_t' typedef */ | ||
| #define NK_SIZE_TYPE uintptr_t | ||
| #define NK_POINTER_TYPE uintptr_t | ||
| #endif | ||
|
|
||
| /* We can reuse the `bool` symbol because SDL3 guarantees its existence */ | ||
| /*#define NK_INCLUDE_STANDARD_BOOL*/ | ||
| #ifndef NK_INCLUDE_STANDARD_BOOL | ||
| #define NK_BOOL bool | ||
| #endif | ||
|
|
||
| /* We can re-use various portable libc functions provided by SDL */ | ||
| #define NK_ASSERT(condition) SDL_assert(condition) | ||
| #define NK_STATIC_ASSERT(exp) SDL_COMPILE_TIME_ASSERT(, exp) | ||
| #define NK_MEMSET(dst, c, len) SDL_memset(dst, c, len) | ||
| #define NK_MEMCPY(dst, src, len) SDL_memcpy(dst, src, len) | ||
| #define NK_VSNPRINTF(s, n, f, a) SDL_vsnprintf(s, n, f, a) | ||
| #define NK_STRTOD(str, endptr) SDL_strtod(str, endptr) | ||
|
|
||
| /* SDL3 does not provide "dtoa" (only integer versions) | ||
| * but we can emulate it with SDL_snprintf */ | ||
| static char* | ||
| nk_sdl_dtoa(char *str, double d) | ||
| { | ||
| NK_ASSERT(str); | ||
| if (!str) return NULL; | ||
| (void)SDL_snprintf(str, 99999, "%.17g", d); | ||
| return str; | ||
| } | ||
| #define NK_DTOA(str, d) nk_sdl_dtoa(str, d) | ||
|
|
||
| /* SDL can also provide us with math functions, but beware that Nuklear's own | ||
| * implementation can be slightly faster at the cost of some precision */ | ||
| #define NK_INV_SQRT(f) (1.0f / SDL_sqrtf(f)) | ||
| #define NK_SIN(f) SDL_sinf(f) | ||
| #define NK_COS(f) SDL_cosf(f) | ||
|
|
||
| /* HACK: Nuklear pulls two stb libraries in order to use font baking | ||
| * those libraries pull in some libc headers internally, creating a linkage dependency, | ||
| * so you’ll most likely want to use SDL symbols instead */ | ||
| #define STBTT_ifloor(x) ((int)SDL_floor(x)) | ||
| #define STBTT_iceil(x) ((int)SDL_ceil(x)) | ||
| #define STBTT_sqrt(x) SDL_sqrt(x) | ||
| #define STBTT_pow(x,y) SDL_pow(x,y) | ||
| #define STBTT_fmod(x,y) SDL_fmod(x,y) | ||
| #define STBTT_cos(x) SDL_cosf(x) | ||
| #define STBTT_acos(x) SDL_acos(x) | ||
| #define STBTT_fabs(x) SDL_fabs(x) | ||
| #define STBTT_assert(x) SDL_assert(x) | ||
| #define STBTT_strlen(x) SDL_strlen(x) | ||
| #define STBTT_memcpy SDL_memcpy | ||
| #define STBTT_memset SDL_memset | ||
| #define stbtt_uint8 Uint8 | ||
| #define stbtt_int8 Sint8 | ||
| #define stbtt_uint16 Uint16 | ||
| #define stbtt_int16 Sint16 | ||
| #define stbtt_uint32 Uint32 | ||
| #define stbtt_int32 Sint32 | ||
| #define STBRP_SORT SDL_qsort | ||
| #define STBRP_ASSERT SDL_assert | ||
| /* There is no need to define STBTT_malloc/STBTT_free macros | ||
| * Nuklear will define those to user-provided nk_allocator */ | ||
|
|
||
| #endif /* NK_SDL3_RENDERER_CONFIG_H_ */ | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,13 @@ | ||
| #ifndef NK_INTERNAL_H | ||
| #define NK_INTERNAL_H | ||
|
|
||
| #ifdef NK_INCLUDE_CONFIG | ||
| #ifndef NK_NUKLEAR_CONFIG_H_ | ||
| #include "nuklear_config.h" | ||
| #define NK_NUKLEAR_CONFIG_H_ | ||
| #endif | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May have missed some previous discussion but this ends up appearing twice? I don't think there are people who include src/nuklear-internals.h... is that the use case?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it's just to ensure that config propagates correctly there. nuklear_internal.h doesn't include nuklear.h directly. It just "happens" that source files are including those in correct order. I'll be fine with removing this one, however, maybe we should simply fix the whole nuklear_internal.h inclusion problem in some other PR? I'm already tracking #889 that I could deal with at the same time. |
||
| #endif | ||
|
|
||
| #ifndef NK_POOL_DEFAULT_CAPACITY | ||
| #define NK_POOL_DEFAULT_CAPACITY 16 | ||
| #endif | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are foo and bar? And why are they used in the ci?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a proof that putting arbitrary functions/variables into the config would work fine.
Also ensures that config is being included only once, even without proper include guards.