Add GetDefaultFontSpacing()

This commit is contained in:
Jax Young 2025-09-08 22:49:38 +08:00
parent f6ae596a1d
commit acb6a25b8b
2 changed files with 13 additions and 4 deletions

View File

@ -1485,6 +1485,7 @@ RLAPI void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float f
RLAPI void DrawTextCodepoints(Font font, const int *codepoints, int codepointCount, Vector2 position, float fontSize, float spacing, Color tint); // Draw multiple character (codepoint)
// Text font info functions
RLAPI float GetDefaultFontSpacing(int fontSize); // Get the text spacing of the default font (only used in DrawText)
RLAPI void SetTextLineSpacing(int spacing); // Set vertical line spacing when drawing with line-breaks
RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font
RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing); // Measure string size for Font

View File

@ -1192,11 +1192,9 @@ void DrawText(const char *text, int posX, int posY, int fontSize, Color color)
{
Vector2 position = { (float)posX, (float)posY };
int defaultFontSize = 10; // Default Font chars height in pixel
if (fontSize < defaultFontSize) fontSize = defaultFontSize;
int spacing = fontSize/defaultFontSize;
float spacing = GetDefaultFontSpacing(fontSize);
DrawTextEx(GetFontDefault(), text, position, (float)fontSize, (float)spacing, color);
DrawTextEx(GetFontDefault(), text, position, (float)fontSize, spacing, color);
}
}
@ -1310,6 +1308,16 @@ void DrawTextCodepoints(Font font, const int *codepoints, int codepointCount, Ve
}
}
// Get the text spacing of the default font (only used in DrawText)
RLAPI float GetDefaultFontSpacing(int fontSize)
{
int defaultFontSize = 10; // Default Font chars height in pixel
if (fontSize < defaultFontSize) fontSize = defaultFontSize;
int spacing = fontSize/defaultFontSize;
return (float)spacing;
}
// Set vertical line spacing when drawing with line-breaks
void SetTextLineSpacing(int spacing)
{