improve cutcolorstring

now takes the width of characters into account

also: fix wraparound for docrefs
This commit is contained in:
ac-stef
2017-04-24 21:48:57 +02:00
parent 9739464381
commit 8e08cddaa7
5 changed files with 20 additions and 16 deletions
+15
View File
@@ -384,3 +384,18 @@ void reloadfonts()
if(!reloadtexture(*f.tex)) fatal("failed to reload font texture");
);
}
void cutcolorstring(char *text, int maxlen)
{ // limit string length, ignore color codes
if(!curfont) return;
int len = 0;
maxlen *= curfont->defaultw;
while(*text)
{
if(*text == '\f' && text[1]) text++;
else if(*text == '\t') len = TABALIGN(len);
else len += curfont->chars.inrange(*text - curfont->skip) ? curfont->chars[*text - curfont->skip].w : curfont->defaultw;
if(len > maxlen) { *text = '\0'; break; }
text++;
}
}