mirror of
https://github.com/nicbarker/clay.git
synced 2026-02-06 12:48:49 +00:00
[Core] Fix handling of letter spacing
This commit is contained in:
parent
80659eda04
commit
87575cb7c3
3 changed files with 11 additions and 6 deletions
|
|
@ -87,6 +87,8 @@ static inline Clay_Dimensions Raylib_MeasureText(Clay_StringSlice text, Clay_Tex
|
|||
|
||||
float maxTextWidth = 0.0f;
|
||||
float lineTextWidth = 0;
|
||||
int maxLineCharCount = 0;
|
||||
int lineCharCount = 0;
|
||||
|
||||
float textHeight = config->fontSize;
|
||||
Font* fonts = (Font*)userData;
|
||||
|
|
@ -99,11 +101,13 @@ static inline Clay_Dimensions Raylib_MeasureText(Clay_StringSlice text, Clay_Tex
|
|||
|
||||
float scaleFactor = config->fontSize/(float)fontToUse.baseSize;
|
||||
|
||||
for (int i = 0; i < text.length; ++i)
|
||||
for (int i = 0; i < text.length; ++i, lineCharCount++)
|
||||
{
|
||||
if (text.chars[i] == '\n') {
|
||||
maxTextWidth = fmax(maxTextWidth, lineTextWidth);
|
||||
maxLineCharCount = CLAY__MAX(maxLineCharCount, lineCharCount);
|
||||
lineTextWidth = 0;
|
||||
lineCharCount = 0;
|
||||
continue;
|
||||
}
|
||||
int index = text.chars[i] - 32;
|
||||
|
|
@ -112,8 +116,9 @@ static inline Clay_Dimensions Raylib_MeasureText(Clay_StringSlice text, Clay_Tex
|
|||
}
|
||||
|
||||
maxTextWidth = fmax(maxTextWidth, lineTextWidth);
|
||||
maxLineCharCount = CLAY__MAX(maxLineCharCount, lineCharCount);
|
||||
|
||||
textSize.width = maxTextWidth * scaleFactor;
|
||||
textSize.width = maxTextWidth * scaleFactor + (lineCharCount * config->letterSpacing);
|
||||
textSize.height = textHeight;
|
||||
|
||||
return textSize;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue