natiny_font_offset_at

C
uint32_t natiny_font_offset_at(NatinyFont font, const char* text, float x);

Returns the byte offset in text nearest to horizontal position x.

Parameters

Name Type Description
font NatinyFont Font handle from natiny_font_create
text const char* Null-terminated UTF-8 text of one line
x float Distance from the start of the line, in drawing units

Returns

Type Description
uint32_t Byte offset from 0 through strlen(text); 0 for an invalid handle or NULL text

Example

C
uint32_t caret = natiny_font_offset_at(font, line, mouse_x - text_x);

/*  the text up to the caret  */
fwrite(line, 1, caret, stdout);