text_length(3alleg4)
β¨ text_length β¨
okay bestie, welcome to text_length from the Allegro manual β yes, that Allegro, the game programming library π
πΈ NAME πΈ
text_length β it hands you the length of a string in pixels. that's it, that's the whole job. Allegro game programming library, as always π
π¦ SYNOPSIS π¦
#include <allegro.h>
int text_length(const FONT *f, const char *str);
π DESCRIPTION π
so like, you give it a string and a font, and it tells you how wide that string is gonna be when it's actually drawn β in pixels, not in characters. which is lowkey the thing you actually need, because a string of 40 "i"s and a string of 40 "W"s are absolutely not the same width, and the computer knows it even if your brain doesn't π
the font is the FONT *f, the string is the const char *str, and the return value is that pixel length as an int. that's it. iconic behaviour, no cap β¨
and here's why you'd care β the classic move is measuring first, then making a bitmap exactly that big. like this:
int width = text_length(font, "I love spam");
...
bmp = create_bitmap(width, height);
see what she did there? measured the vibe, THEN built the canvas. main character energy fr fr π
π«Ά SEE ALSO π«Ά
text_height(3alleg4)β the vertical bestieex12bit(3alleg4)exmidi(3alleg4)expat(3alleg4)exunicod(3alleg4)
not me writing an entire love letter to a function that returns an int π but she's useful, okay?? go read the friends above, they're all part of the same squad.
Allegro, version 4.4.3, text_length(3alleg4) β mwah, that's a wrap, go measure some strings, you absolute legend πβπ
π¦ where this page comes from
- debian bookworm: allegro4-doc 2:4.4.3.1-3 Β· Allegro-gift-ware
- debian trixie: allegro4-doc 2:4.4.3.1-5 Β· Allegro-gift-ware
- ubuntu jammy: allegro4-doc 2:4.4.3.1-2 Β· Allegro-gift-ware
- ubuntu noble: allegro4-doc 2:4.4.3.1-4.1build3 Β· Allegro-gift-ware
- ubuntu questing: allegro4-doc 2:4.4.3.1-6
- ubuntu resolute: allegro4-doc 2:4.4.3.1-7 Β· Allegro-gift-ware
- ubuntu stonking: allegro4-doc 2:4.4.3.1-9 Β· Allegro-gift-ware
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms