Nuklear icon indicating copy to clipboard operation
Nuklear copied to clipboard

Resizing main nuklear window's height depending on inner content size

Open 8dcc opened this issue 1 year ago • 2 comments

I am sure this has been asked before, but I can't find anything.

Let's say I have this code:

#define MENU_FLAGS NK_WINDOW_BORDER | NK_WINDOW_TITLE | NK_WINDOW_MOVABLE | NK_WINDOW_NO_SCROLLBAR
#define ITEMS 5
const char* strings[ITEMS];

if (nk_begin(ctx, "Main window", nk_rect(X, Y, W, 45 + ITEMS * 15), MENU_FLAGS)) {
    nk_layout_row_dynamic(ctx, 15, 1);

    for (int i = 0; i < ITEMS; i++)
        nk_label(ctx, strings[i], NK_TEXT_LEFT);
}

nk_end(ctx);

In there, I want to display N strings (as labels) inside the window. In this case, I am manually calculating the window height based on the number of items in my array + the base window size (which I don't know if it's really 45 by the way).

Is there any way the window can resize itself automatically based on the number of items?

Also, side note: With the code I sent, if I render N items, and then I remove 1 (e.g. render 5 labels and then 4), the window size remains as it was when I rendered 5.

8dcc avatar Aug 10 '23 20:08 8dcc

With immediate mode UIs you simply recalculate (and then set before next frame) the new geometry (e.g. window size) after you decided to change the number of items.

Does this help?

dumblob avatar Feb 17 '24 16:02 dumblob