TTF_GetTextSubString(3)

πŸ’– TTF_GetTextSubString πŸ’–

okay bestie, welcome to the SDL_ttf3 FUNCTIONS corner of the manual, this one's literally about grabbing the little slice of a text object that wraps around a text offset πŸŽ€

✨ NAME ✨

TTF_GetTextSubString β€” Get the substring of a text object that surrounds a text offset.


🌸 HEADER FILE 🌸

Defined in SDL3_ttf/SDL_ttf.h β€” that's the one, no cap 🫢

πŸ¦‹ SYNOPSIS πŸ¦‹

#include "SDL3_ttf/SDL_ttf.h"

bool TTF_GetTextSubString(TTF_Text *text, int offset, TTF_SubString *substring);

πŸ’… DESCRIPTION πŸ’…

So here's the vibe check πŸ‘‘

If offset is less than 0, this will return a zero length substring at the beginning of the text with the TTF_SUBSTRING_TEXT_START flag set.

If offset is greater than or equal to the length of the text string, this will return a zero length substring at the end of the text with the TTF_SUBSTRING_TEXT_END flag set.

like. it never crashes out on you, it just clamps to the edges and flags it. iconic behaviour fr fr ✨

πŸ“ FUNCTION PARAMETERS πŸ“

  • text β€” the TTF_Text to query. the main character of this whole situation πŸ’–
  • offset β€” a byte offset into the text string. yes, byte, not character, don't come for me πŸ™ˆ
  • substring β€” a pointer filled in with the substring containing the offset. it writes into this, so hand it something real πŸŽ€

⭐ RETURN VALUE ⭐

Returns true on success or false on failure; call SDL_GetError() for more information. no silent L's here, it tells you what went wrong 🫢

🧚 THREAD SAFETY 🧚

This function should be called on the thread that created the text. like, don't be messy about it, stay on your own thread bestie πŸ’€

🌈 AVAILABILITY 🌈

This function is available since SDL_ttf 3.0.0 β€” she's been around, she's established, she's serving longevity πŸ‘‘


πŸ’œ quick reminder: the TTF_SUBSTRING_TEXT_START and TTF_SUBSTRING_TEXT_END flags only show up in those out-of-range cases, and the substring is zero length when they do. that's not a bug, that's the design, periodt.

mwah πŸ’‹ this page comes to you courtesy of SDL_ttf 3.2.2 β€” go off, read the rest of the docs, and stay hydrated πŸ¦‹βœ¨

πŸ“¦ where this page comes from