Skip to content

Commit 3ef1b9a

Browse files
committed
Update raygui.h
1 parent 03b1715 commit 3ef1b9a

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

headers/extras/raygui.h

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4829,6 +4829,9 @@ static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, C
48294829
for (int c = 0; (lines[i][c] != '\0') && (lines[i][c] != '\n') && (lines[i][c] != '\r'); c++, lineSize++){ }
48304830
float scaleFactor = (float)GuiGetStyle(DEFAULT, TEXT_SIZE)/guiFont.baseSize;
48314831

4832+
int lastSpaceIndex = 0;
4833+
bool tempWrapCharMode = false;
4834+
48324835
int textOffsetY = 0;
48334836
float textOffsetX = 0.0f;
48344837
float glyphWidth = 0;
@@ -4839,10 +4842,10 @@ static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, C
48394842

48404843
// NOTE: Normally we exit the decoding sequence as soon as a bad byte is found (and return 0x3f)
48414844
// but we need to draw all of the bad bytes using the '?' symbol moving one byte
4842-
if (codepoint == 0x3f) codepointSize = 1; // TODO: Review not recognized codepoints size
4845+
if (codepoint == 0x3f) codepointSize = 1; // TODO: Review not recognized codepoints size
48434846

4844-
// Wrap mode text measuring to space to validate if it can be drawn or
4845-
// a new line is required
4847+
// Wrap mode text measuring, to validate if
4848+
// it can be drawn or a new line is required
48464849
if (wrapMode == TEXT_WRAP_CHAR)
48474850
{
48484851
// Get glyph width to check if it goes out of bounds
@@ -4854,21 +4857,36 @@ static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, C
48544857
{
48554858
textOffsetX = 0.0f;
48564859
textOffsetY += GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
4860+
4861+
if (tempWrapCharMode) // Wrap at char level when too long words
4862+
{
4863+
wrapMode = TEXT_WRAP_WORD;
4864+
tempWrapCharMode = false;
4865+
}
48574866
}
48584867
}
48594868
else if (wrapMode == TEXT_WRAP_WORD)
48604869
{
4870+
if (codepoint == 32) lastSpaceIndex = c;
4871+
48614872
// Get width to next space in line
48624873
int nextSpaceIndex = 0;
48634874
float nextSpaceWidth = GetNextSpaceWidth(lines[i] + c, &nextSpaceIndex);
48644875

4865-
if ((textOffsetX + nextSpaceWidth) > textBounds.width)
4876+
int nextSpaceIndex2 = 0;
4877+
float nextWordSize = GetNextSpaceWidth(lines[i] + lastSpaceIndex + 1, &nextSpaceIndex2);
4878+
4879+
if (nextWordSize > textBounds.width)
4880+
{
4881+
// Considering the case the next word is longer than bounds
4882+
tempWrapCharMode = true;
4883+
wrapMode = TEXT_WRAP_CHAR;
4884+
}
4885+
else if ((textOffsetX + nextSpaceWidth) > textBounds.width)
48664886
{
48674887
textOffsetX = 0.0f;
48684888
textOffsetY += GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
48694889
}
4870-
4871-
// TODO: Consider case: (nextSpaceWidth >= textBounds.width)
48724890
}
48734891

48744892
if (codepoint == '\n') break; // WARNING: Lines are already processed manually, no need to keep drawing after this codepoint

0 commit comments

Comments
 (0)