natiny_font_measure_wrapped
void natiny_font_measure_wrapped(NatinyFont font, const char* text,
float max_width, float* width,
float* height, uint32_t* lines);
Lays text out and reports the size of the block it makes, without drawing it.
Parameters
| Name | Type | Description |
|---|---|---|
font |
NatinyFont |
Font handle from natiny_font_create |
text |
const char* |
Null-terminated UTF-8 text |
max_width |
float |
Wrap width in drawing units; values at or below 0.0f do not wrap |
width |
float* |
Receives the widest-line width in drawing units; may be NULL |
height |
float* |
Receives the block height in drawing units; may be NULL |
lines |
uint32_t* |
Receives the line count; may be NULL |
Example
float w = 0.0f, h = 0.0f;
uint32_t lines = 0;
natiny_font_measure_wrapped(font, message, 300.0f, &w, &h, &lines);
natiny_render_rectangle(20.0f, 20.0f, w + 16.0f, h + 16.0f);
Notes
- Breaks the text exactly as
natiny_render_text_boxdoes, so a box sized from this holds what that draws into it. - Lines break at spaces and tabs, at
\n, and between Han, kana and Hangul characters, which are written without spaces. A word longer thanmax_widthis cut where it stops fitting rather than allowed to overflow. - Trailing spaces are neither measured nor drawn, and a wrapped line never begins with one.
- The height is
linestimesnatiny_font_get_line_height, so it followsnatiny_font_set_line_spacing. - An empty string is one empty line: the width is
0, the height is one line, andlinesis1. - Invalid handles or
NULLtext produce zero width, height, and lines.