al_do_multiline_text(3alleg5)
π al_do_multiline_text β Allegro 5 API π
okay bestie, pull up a chair, we're in the 3alleg5 section of the Allegro reference manual and this one is so useful it's not even funny β¨
πΈ SYNOPSIS πΈ
#include <allegro5/allegro_font.h>
void al_do_multiline_text(const ALLEGRO_FONT *font,
float max_width, const char *text,
bool (*cb)(int line_num, const char *line, int size, void *extra),
void *extra)
π¦ DESCRIPTION π¦
so basically, this function takes your text, does the whole line-splitting thing exactly the way al_draw_multiline_text(3alleg5) would do it, and then calls your callback cb once for every single line. no cap. one line, one callback, every time π
it's giving custom drawing of multiline text, and it's also giving calculating the size of multiline text ahead of time β both iconic uses, both valid. if you wanna know how the splitting algorithm actually works, go read the docs on al_draw_multiline_text(3alleg5), because that's where the explanation lives π«Ά
π the callback parameters (aka the tea) π
for every line that this function splits text into, the callback cb gets called once with these cuties:
line_numβ the number of the line, starting from zero and counting up β¬οΈlineβ a pointer to the beginning character of the line (more on this below, don't skip it π)sizeβ the size of the line (0 for empty lines)extraβ the exact same pointer that was passed toal_do_multiline_text
π the line pointer warning (read this, fr fr) π
not me about to save you from a segfault. line is NOT guaranteed to be a NUL-terminated string. it just points to a character inside text, or to an empty string if the line is empty. that's it. that's all you get.
so if you need a NUL-terminated string, you're gonna have to copy line into a buffer and NUL-terminate it yourself. no one's doing it for you bestie π
and listen β if you need the contents of line after cb has returned, you also have to make your own copy, because line is not guaranteed to be valid after that. it's giving expired. it's giving use-after-free waiting to happen. so copy it or lose it π
π₯ the return value behaviour π₯
- if your callback
cbreturnsfalse,al_do_multiline_textstops immediately π - otherwise, it keeps going on to the next line, and the next, and the next β
that's your early-exit button. use it with intention, queen π
β SINCE β
5.1.9
π SEE ALSO π
okay that's the whole page, you absolutely ate this one π«Ά go forth and split some lines responsibly. this was al_do_multiline_text(3alleg5) straight outta the Allegro reference manual β mwah, catch you in the next one πβ¨π
π¦ where this page comes from
- debian trixie: allegro5-doc 2:5.2.10.1+dfsg-1 Β· Zlib
- ubuntu questing: allegro5-doc 2:5.2.10.1+dfsg-1build1
- ubuntu resolute: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- ubuntu stonking: allegro5-doc 2:5.2.11.3+dfsg-1 Β· Zlib
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms