Integrate nuklear into engine

This commit is contained in:
2023-11-08 10:04:47 +01:00
parent 16972e4f9a
commit efada40908
3 changed files with 66 additions and 35 deletions

View File

@@ -1,39 +1,40 @@
#include <raylib-nuklear.h>
#define BZ_ENTRYPOINT
#include <breeze.h>
int main() {
InitWindow(640, 480, "raylib-nuklear example");
enum {EASY, HARD};
static int op = EASY;
static float value = 0.6f;
static int i = 20;
// Create the Nuklear Context
int fontSize = 10;
struct nk_context *ctx = InitNuklear(fontSize);
void render(float dt, int *game) {
ClearBackground(WHITE);
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!
}
if (nk_begin(NK, "Show", nk_rect(50, 50, 220, 220),
NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
// fixed widget pixel width
nk_layout_row_static(NK, 30, 80, 1);
if (nk_button_label(NK, "button")) {
// event handling
}
nk_end(ctx);
// Render
BeginDrawing();
ClearBackground(RAYWHITE);
// Render the Nuklear GUI
DrawNuklear(ctx);
EndDrawing();
// fixed widget window ratio width
nk_layout_row_dynamic(NK, 30, 2);
if (nk_option_label(NK, "easy", op == EASY)) op = EASY;
if (nk_option_label(NK, "hard", op == HARD)) op = HARD;
// custom widget pixel width
nk_layout_row_begin(NK, NK_STATIC, 30, 2);
{
nk_layout_row_push(NK, 50);
nk_label(NK, "Volume:", NK_TEXT_LEFT);
nk_layout_row_push(NK, 110);
nk_slider_float(NK, 0, &value, 1.0f, 0.1f);
}
nk_layout_row_end(NK);
}
nk_end(NK);
}
// De-initialize the Nuklear GUI
UnloadNuklear(ctx);
CloseWindow();
return 0;
bool bzMain(BzAppDesc *appDesc, int argc, const char **argv) {
appDesc->render = (BzAppRenderFunc) render;
appDesc->useNuklear = true;
return true;
}