Nuklear icon indicating copy to clipboard operation
Nuklear copied to clipboard

Example included on Github page seems useless

Open mavavilj opened this issue 2 years ago • 3 comments

I was expecting the supplied example to be easily runnable, but copying the code from:

https://github.com/Immediate-Mode-UI/Nuklear#example

into a main() like:

#include "Nuklear-master/nuklear.h"
#include "stdlib.h"

int main(int argc, char *argv[])
{
    /* init gui state */
    struct nk_context ctx;
    nk_init_fixed(&ctx, calloc(1, MAX_MEMORY), MAX_MEMORY, &font);

    enum {EASY, HARD};
    static int op = EASY;
    static float value = 0.6f;
    static int i =  20;

    if (nk_begin(&ctx, "Show", nk_rect(50, 50, 220, 220),
        NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
        /* fixed widget pixel width */
        nk_layout_row_static(&ctx, 30, 80, 1);
        if (nk_button_label(&ctx, "button")) {
            /* event handling */
        }

        /* fixed widget window ratio width */
        nk_layout_row_dynamic(&ctx, 30, 2);
        if (nk_option_label(&ctx, "easy", op == EASY)) op = EASY;
        if (nk_option_label(&ctx, "hard", op == HARD)) op = HARD;

        /* custom widget pixel width */
        nk_layout_row_begin(&ctx, NK_STATIC, 30, 2);
        {
            nk_layout_row_push(&ctx, 50);
            nk_label(&ctx, "Volume:", NK_TEXT_LEFT);
            nk_layout_row_push(&ctx, 110);
            nk_slider_float(&ctx, 0, &value, 1.0f, 0.1f);
        }
        nk_layout_row_end(&ctx);
    }
    nk_end(&ctx);
}

has a bunch of stuff missing, like MAX_MEMORY and font.

mavavilj avatar Mar 13 '22 16:03 mavavilj

While i agree that for those unfamiliar with immediate mode / backend agnostic ui's it might seem as though the example does not "work", I also think its hard to provide a "runnable, visual" example without going into backends and all the things "around" nuklear.

The example is in my eyes the perfect example of how to use the nuklear api. Not so much the perfect example of how to integrate it into something runnable, those are in the demo folder.

We could maybe emphasize / structure the readme more towards "Please take a look at the demo folder for runnable, copy/pastable examples" to avoid confusion by those finding nuklear and wanting to try it out fast.

RobertLemmens avatar Apr 02 '22 18:04 RobertLemmens

While i agree that for those unfamiliar with immediate mode / backend agnostic ui's it might seem as though the example does not "work", I also think its hard to provide a "runnable, visual" example without going into backends and all the things "around" nuklear.

The example is in my eyes the perfect example of how to use the nuklear api. Not so much the perfect example of how to integrate it into something runnable, those are in the demo folder.

We could maybe emphasize / structure the readme more towards "Please take a look at the demo folder for runnable, copy/pastable examples" to avoid confusion by those finding nuklear and wanting to try it out fast.

Yes, I started with demo/x11/main.c, which was much easier to understand.

mavavilj avatar Apr 03 '22 05:04 mavavilj

We could maybe emphasize / structure the readme more towards "Please take a look at the demo folder for runnable, copy/pastable examples" to avoid confusion by those finding nuklear and wanting to try it out fast.

Good idea! PRs welcome!

dumblob avatar Apr 11 '22 08:04 dumblob