REVIEWED: Long words proper word-wrap
This commit is contained in:
parent
a2726c8600
commit
d60885cd49
@ -82,7 +82,7 @@ int main()
|
|||||||
char textBoxText[64] = "Text box";
|
char textBoxText[64] = "Text box";
|
||||||
bool textBoxEditMode = false;
|
bool textBoxEditMode = false;
|
||||||
|
|
||||||
char textBoxMultiText[1024] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
|
char textBoxMultiText[1024] = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\n\nDuis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.\n\nThisisastringlongerthanexpectedwithoutspacestotestcharbreaksforthosecases,checkingifworkingasexpected.\n\nExcepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
|
||||||
bool textBoxMultiEditMode = false;
|
bool textBoxMultiEditMode = false;
|
||||||
|
|
||||||
int listViewScrollIndex = 0;
|
int listViewScrollIndex = 0;
|
||||||
|
24
src/raygui.h
24
src/raygui.h
@ -4829,6 +4829,9 @@ static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, C
|
|||||||
for (int c = 0; (lines[i][c] != '\0') && (lines[i][c] != '\n') && (lines[i][c] != '\r'); c++, lineSize++){ }
|
for (int c = 0; (lines[i][c] != '\0') && (lines[i][c] != '\n') && (lines[i][c] != '\r'); c++, lineSize++){ }
|
||||||
float scaleFactor = (float)GuiGetStyle(DEFAULT, TEXT_SIZE)/guiFont.baseSize;
|
float scaleFactor = (float)GuiGetStyle(DEFAULT, TEXT_SIZE)/guiFont.baseSize;
|
||||||
|
|
||||||
|
int lastSpaceIndex = 0;
|
||||||
|
bool tempWrapCharMode = false;
|
||||||
|
|
||||||
int textOffsetY = 0;
|
int textOffsetY = 0;
|
||||||
float textOffsetX = 0.0f;
|
float textOffsetX = 0.0f;
|
||||||
float glyphWidth = 0;
|
float glyphWidth = 0;
|
||||||
@ -4854,21 +4857,36 @@ static void GuiDrawText(const char *text, Rectangle textBounds, int alignment, C
|
|||||||
{
|
{
|
||||||
textOffsetX = 0.0f;
|
textOffsetX = 0.0f;
|
||||||
textOffsetY += GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
|
textOffsetY += GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
|
||||||
|
|
||||||
|
if (tempWrapCharMode) // Wrap at char level when too long words
|
||||||
|
{
|
||||||
|
wrapMode = TEXT_WRAP_WORD;
|
||||||
|
tempWrapCharMode = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (wrapMode == TEXT_WRAP_WORD)
|
else if (wrapMode == TEXT_WRAP_WORD)
|
||||||
{
|
{
|
||||||
|
if (codepoint == 32) lastSpaceIndex = c;
|
||||||
|
|
||||||
// Get width to next space in line
|
// Get width to next space in line
|
||||||
int nextSpaceIndex = 0;
|
int nextSpaceIndex = 0;
|
||||||
float nextSpaceWidth = GetNextSpaceWidth(lines[i] + c, &nextSpaceIndex);
|
float nextSpaceWidth = GetNextSpaceWidth(lines[i] + c, &nextSpaceIndex);
|
||||||
|
|
||||||
if ((textOffsetX + nextSpaceWidth) > textBounds.width)
|
int nextSpaceIndex2 = 0;
|
||||||
|
float nextWordSize = GetNextSpaceWidth(lines[i] + lastSpaceIndex + 1, &nextSpaceIndex2);
|
||||||
|
|
||||||
|
if (nextWordSize > textBounds.width)
|
||||||
|
{
|
||||||
|
// Considering the case the next word is longer than boudns
|
||||||
|
tempWrapCharMode = true;
|
||||||
|
wrapMode = TEXT_WRAP_CHAR;
|
||||||
|
}
|
||||||
|
else if ((textOffsetX + nextSpaceWidth) > textBounds.width)
|
||||||
{
|
{
|
||||||
textOffsetX = 0.0f;
|
textOffsetX = 0.0f;
|
||||||
textOffsetY += GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
|
textOffsetY += GuiGetStyle(DEFAULT, TEXT_LINE_SPACING);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Consider case: (nextSpaceWidth >= textBounds.width)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (codepoint == '\n') break; // WARNING: Lines are already processed manually, no need to keep drawing after this codepoint
|
if (codepoint == '\n') break; // WARNING: Lines are already processed manually, no need to keep drawing after this codepoint
|
||||||
|
Loading…
x
Reference in New Issue
Block a user