Skip to content
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

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

Open
8dcc opened this issue Aug 10, 2023 · 1 comment
Open

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

8dcc opened this issue Aug 10, 2023 · 1 comment

Comments

@8dcc
Copy link

8dcc commented Aug 10, 2023

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.

@dumblob
Copy link
Member

dumblob commented Feb 17, 2024

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?

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

No branches or pull requests

2 participants