Skip to content

feat: include "nuklear_config.h" when NK_INCLUDE_CONFIG is defined#955

Open
sleeptightAnsiC wants to merge 1 commit into
Immediate-Mode-UI:masterfrom
sleeptightAnsiC:feat_user_config
Open

feat: include "nuklear_config.h" when NK_INCLUDE_CONFIG is defined#955
sleeptightAnsiC wants to merge 1 commit into
Immediate-Mode-UI:masterfrom
sleeptightAnsiC:feat_user_config

Conversation

@sleeptightAnsiC
Copy link
Copy Markdown
Contributor

Resolves: #886

See linked issue and commit message for more details and reasoning.

I found this to be a rather good moment to submit this feature as I was updating some of my private repos with it. Also I'm planning to share some code that reuses demo/sdl3_renderer with different main.c for the purpose of #726 (comment) and #888 (comment), and having its config split into another file will be helpful there.

Comment thread src/nuklear.h Outdated
@sleeptightAnsiC sleeptightAnsiC force-pushed the feat_user_config branch 2 times, most recently from 3acb495 to e146fe5 Compare May 8, 2026 20:54
@sleeptightAnsiC sleeptightAnsiC changed the title feat: include "nk_user_config.h" when NK_USER_CONFIG is defined feat: include "nk_user_config.h" when NK_INCLUDE_USER_CONFIG is defined May 8, 2026
@sleeptightAnsiC sleeptightAnsiC marked this pull request as ready for review May 8, 2026 21:23
Comment thread src/nuklear.h Outdated
Adds a way to inject config header with predefined macros and includes.
This is not so important for regular users of amalgamated ./nuklear.h
but becomes useful when building from ./src/*.c with actual build system
See linked issue for more details and reasoning about this.

Resolves: Immediate-Mode-UI#886
@sleeptightAnsiC sleeptightAnsiC changed the title feat: include "nk_user_config.h" when NK_INCLUDE_USER_CONFIG is defined feat: include "nuklear_config.h" when NK_INCLUDE_CONFIG is defined May 12, 2026
cat <<'EOF' >"${tmpdir}/nuklear_config.h"
/* intentionally without header guards */
static int foo;
static int bar(void) { return 0; }
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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.

Comment thread demo/sdl3_renderer/main.c
}

static char*
nk_sdl_dtoa(char *str, double d)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small note: this thing should be inline, but I had to keep it static for compatibility with C89. It's not a problem when using amalgamation, but it will trigger -Wunused-function when building into separate TUs.

Comment thread src/nuklear_internal.h
#ifndef NK_NUKLEAR_CONFIG_H_
#include "nuklear_config.h"
#define NK_NUKLEAR_CONFIG_H_
#endif
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there are people who include src/nuklear-internals.h... is that the use case?

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add a way to reuse Nuklear configuration across multiple source files

2 participants