Feature: Line-break support for text
This commit is contained in:
parent
165b3dd215
commit
f13b30d606
1 changed files with 16 additions and 3 deletions
15
src/text.c
15
src/text.c
|
@ -293,6 +293,7 @@ void DrawTextEx(SpriteFont spriteFont, const char *text, Vector2 position, int f
|
||||||
{
|
{
|
||||||
int length = strlen(text);
|
int length = strlen(text);
|
||||||
int offsetX = 0;
|
int offsetX = 0;
|
||||||
|
int offsetY = 0; // Line break!
|
||||||
float scaleFactor;
|
float scaleFactor;
|
||||||
unsigned char letter;
|
unsigned char letter;
|
||||||
|
|
||||||
|
@ -323,12 +324,24 @@ void DrawTextEx(SpriteFont spriteFont, const char *text, Vector2 position, int f
|
||||||
rec = spriteFont.charRecs[letter - FONT_FIRST_CHAR + 64];
|
rec = spriteFont.charRecs[letter - FONT_FIRST_CHAR + 64];
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ((unsigned char)text[i] == '\n')
|
||||||
|
{
|
||||||
|
offsetY += ((spriteFont.size + spriteFont.size/2)*scaleFactor);
|
||||||
|
offsetX = 0;
|
||||||
|
rec.x = -1;
|
||||||
|
}
|
||||||
else rec = spriteFont.charRecs[(int)text[i] - FONT_FIRST_CHAR];
|
else rec = spriteFont.charRecs[(int)text[i] - FONT_FIRST_CHAR];
|
||||||
|
}
|
||||||
|
|
||||||
DrawTexturePro(spriteFont.texture, rec, (Rectangle){ position.x + offsetX, position.y, rec.width*scaleFactor, rec.height*scaleFactor} , (Vector2){ 0, 0 }, 0.0f, tint);
|
if (rec.x > 0)
|
||||||
|
{
|
||||||
|
DrawTexturePro(spriteFont.texture, rec, (Rectangle){ position.x + offsetX, position.y + offsetY, rec.width*scaleFactor, rec.height*scaleFactor} , (Vector2){ 0, 0 }, 0.0f, tint);
|
||||||
|
|
||||||
offsetX += (rec.width*scaleFactor + spacing);
|
offsetX += (rec.width*scaleFactor + spacing);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Formatting of text with variables to 'embed'
|
// Formatting of text with variables to 'embed'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue