TTF_GetStringSizeWrapped(3)

πŸ’– TTF_GetStringSizeWrapped πŸ’–

okay bestie, welcome to the SDL_ttf3 FUNCTIONS corner of the manual, this one's called TTF_GetStringSizeWrapped and it's genuinely so useful, like the little measuring tape of the text-rendering world πŸ“βœ¨


πŸŽ€ NAME πŸŽ€

TTF_GetStringSizeWrapped β€” figure out the dimensions of a rendered string of UTF-8 text. like, how much pixel real estate is this thing gonna take up, fr fr πŸ’…


🌸 HEADER FILE 🌸

it lives in SDL3_ttf/SDL_ttf.h, that's the whole vibe πŸ¦‹


✨ SYNOPSIS ✨

#include "SDL3_ttf/SDL_ttf.h"

bool TTF_GetStringSizeWrapped(TTF_Font *font, const char *text, size_t length, int wrap_width, int *w, int *h);

πŸ’œ DESCRIPTION πŸ’œ

so what it does is: it reports the width and height, in pixels, of the space that the string you gave it will take to fully render. no cap, that's the whole point β€” you get to know before you commit πŸ‘‘

Text gets wrapped to multiple lines on line endings and on word boundaries, but only if it extends beyond wrap_width in pixels. so it's not just gonna let your words run off the edge of the earth, it wraps them, iconic behavior 🧚

and if wrap_width is 0, this function will only wrap on newline characters. periodt.


🫢 FUNCTION PARAMETERS 🫢

  • font β€” the font you're querying. the main character of this whole operation πŸ’–
  • text β€” the text you wanna calculate, in UTF-8 encoding. yes, UTF-8, keep it cute ✨
  • length β€” the length of the text, in bytes, or 0 for null terminated text. your call bestie πŸŽ€
  • wrap_width β€” the maximum width, or 0 to wrap on newline characters only 🌸
  • w β€” will be filled with the width, in pixels, on return. it's an out-param, she's reporting back πŸ¦‹
  • h β€” will be filled with the height, in pixels, on return. same deal πŸ’«

⭐ RETURN VALUE ⭐

Returns true on success or false on failure. and if it fails? call SDL_GetError() for more information, she'll tell you what went wrong πŸ”


πŸ’… THREAD SAFETY πŸ’…

this function should be called on the thread that created the font. no side-eyeing, no hopping threads, keep it loyal to the font's origin thread πŸ™ˆ

🌈 AVAILABILITY 🌈

this function is available since SDL_ttf 3.0.0. she's been around, she's established, she ate πŸ”₯


and that's the whole page bestie!! mwah πŸ’‹ this gorgeous little manual page came to you courtesy of SDL_ttf 3.2.2, and it's the TTF_GetStringSizeWrapped(3) page from the SDL_ttf docs β€” go measure some strings, you're gonna do amazing πŸ«ΆπŸŽ€βœ¨

πŸ“¦ where this page comes from