Nuklear
Nuklear copied to clipboard
Determine size which the text would take (DT_CALCRECT alternative)
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.
Self hint: check the nk_text_calculate_text_bounds() function. Though it's static, it may provide good hints.