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

Multiple window instances #640

Closed
bolt-blue opened this issue May 12, 2024 · 2 comments
Closed

Multiple window instances #640

bolt-blue opened this issue May 12, 2024 · 2 comments

Comments

@bolt-blue
Copy link

Is it possible to have multiple windows, each with the same "template" so-to-speak, but with varying content?

With what I know of the code base so far, I don't think this can be done.

Each window has a hard-coded string identifier, which I believe is used predominantly to store and reference it's scroll position(s).
I don't see a way around this.

Is there perhaps an alternative to help effectively achieve the same ends?

@RobLoach
Copy link
Contributor

Possible solution is to make a function for the "template", and call it after defining each window

void mytemplate(ctx) {
    /* fixed widget pixel width */
    nk_layout_row_static(ctx, 30, 80, 1);
    if (nk_button_label(ctx, "button")) {
        /* event handling */
    }
}

// ....
struct nk_context ctx;

if (nk_begin(&ctx, "Window 1", nk_rect(50, 50, 220, 220),
    NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
    mytemplate(ctx);
}
nk_end(&ctx);

if (nk_begin(&ctx, "Window 2", nk_rect(50, 50, 220, 220),
    NK_WINDOW_BORDER|NK_WINDOW_MOVABLE|NK_WINDOW_CLOSABLE)) {
    mytemplate(ctx);
}
nk_end(&ctx);

@bolt-blue
Copy link
Author

Thank you.
That could be a workable solution.

I suppose I've had in my head that the string id's would have to be compile-time defined.
But I guess there's no reason they couldn't be generated at run time. Unless I'm mistaken.

If that's reasonable, then this approach is definitely fine.

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