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

Determine size which the text would take (DT_CALCRECT alternative) #761

Open
trexxet opened this issue Jan 6, 2025 · 1 comment
Open

Comments

@trexxet
Copy link

trexxet commented Jan 6, 2025

Imagine that you need to determine which window size you should use to contain a label, using current style, font, and for simplicity using no wrap. Label text is defined in runtime (e.g. by input or by setting locale). How would you do that?

E.g.:

char some_string[128];
fgets(some_string, sizeof(some_string), stdin);
if (nk_begin (nk_ctx, some_string, nk_rect( /* ???? */ ), NK_WINDOW_NO_SCROLLBAR)) {
        nk_layout_row_dynamic (nk_ctx, /* ???? */ , 1);
        nk_label (nk_ctx, some_string, NK_TEXT_CENTERED);
}
nk_end (nk_ctx);

In other words, is there any alternative to WinGDI's DrawText(text, &rect, DT_CALCRECT), which determines the width and height of the rectangle the text would occupy?

Thanks.

@trexxet
Copy link
Author

trexxet commented Jan 9, 2025

Self hint: check the nk_text_calculate_text_bounds() function. Though it's static, it may provide good hints.

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

1 participant