Update raygui.h

This commit is contained in:
Ray
2025-03-13 16:42:25 +01:00
parent fc9d852d4a
commit d5459559e5

View File

@ -160,6 +160,8 @@
* REVIEWED: GuiIconText(), increase buffer size and reviewed padding
* REVIEWED: GuiDrawText(), improved wrap mode drawing
* REVIEWED: GuiScrollBar(), minor tweaks
* REVIEWED: GuiProgressBar(), improved borders computing
* REVIEWED: GuiTextBox(), multiple improvements: autocursor and more
* REVIEWED: Functions descriptions, removed wrong return value reference
* REDESIGNED: GuiColorPanel(), improved HSV <-> RGBA convertion
*
@ -2501,7 +2503,7 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
int wrapMode = GuiGetStyle(DEFAULT, TEXT_WRAP_MODE);
Rectangle textBounds = GetTextBounds(TEXTBOX, bounds);
int textLength = (int)strlen(text); // Get current text length
int textLength = (text != NULL)? (int)strlen(text) : 0; // Get current text length
int thisCursorIndex = textBoxCursorIndex;
if (thisCursorIndex > textLength) thisCursorIndex = textLength;
int textWidth = GetTextWidth(text) - GetTextWidth(text + thisCursorIndex);
@ -2545,10 +2547,8 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
// GLOBAL: Auto-cursor movement logic
// NOTE: Keystrokes are handled repeatedly when button is held down for some time
if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_UP) || IsKeyDown(KEY_DOWN) || IsKeyDown(KEY_BACKSPACE) || IsKeyDown(KEY_DELETE)) autoCursorCounter++;
else
{
autoCursorCounter = 0;
}
else autoCursorCounter = 0;
bool autoCursorShouldTrigger = (autoCursorCounter > RAYGUI_TEXTBOX_AUTO_CURSOR_COOLDOWN) && ((autoCursorCounter % RAYGUI_TEXTBOX_AUTO_CURSOR_DELAY) == 0);
state = STATE_PRESSED;
@ -2686,8 +2686,8 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
while (offset > 0)
{
prevCodepoint = GetCodepointPrevious(text + offset, &prevCodepointSize);
if (!isspace(prevCodepoint & 0xFF))
break;
if (!isspace(prevCodepoint & 0xFF)) break;
offset -= prevCodepointSize;
accCodepointSize += prevCodepointSize;
}
@ -2697,8 +2697,8 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
while (offset > 0)
{
prevCodepoint = GetCodepointPrevious(text + offset, &prevCodepointSize);
if ((puctuation && !ispunct(prevCodepoint & 0xFF)) || (!puctuation && (isspace(prevCodepoint & 0xFF) || ispunct(prevCodepoint & 0xFF))))
break;
if ((puctuation && !ispunct(prevCodepoint & 0xFF)) || (!puctuation && (isspace(prevCodepoint & 0xFF) || ispunct(prevCodepoint & 0xFF)))) break;
offset -= prevCodepointSize;
accCodepointSize += prevCodepointSize;
}
@ -2735,19 +2735,20 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
while (offset > 0)
{
prevCodepoint = GetCodepointPrevious(text + offset, &prevCodepointSize);
if (!isspace(prevCodepoint & 0xFF))
break;
if (!isspace(prevCodepoint & 0xFF)) break;
offset -= prevCodepointSize;
accCodepointSize += prevCodepointSize;
}
// Check characters of the same type to skip (either ASCII punctuation or anything non-whitespace)
// Not using isalnum() since it only works on ASCII characters
bool puctuation = ispunct(prevCodepoint & 0xFF);
while (offset > 0)
{
prevCodepoint = GetCodepointPrevious(text + offset, &prevCodepointSize);
if ((puctuation && !ispunct(prevCodepoint & 0xFF)) || (!puctuation && (isspace(prevCodepoint & 0xFF) || ispunct(prevCodepoint & 0xFF))))
break;
if ((puctuation && !ispunct(prevCodepoint & 0xFF)) || (!puctuation && (isspace(prevCodepoint & 0xFF) || ispunct(prevCodepoint & 0xFF)))) break;
offset -= prevCodepointSize;
accCodepointSize += prevCodepointSize;
}
@ -2767,23 +2768,25 @@ int GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode)
int accCodepointSize = 0;
int nextCodepointSize;
int nextCodepoint;
// Check characters of the same type to skip (either ASCII punctuation or anything non-whitespace)
// Not using isalnum() since it only works on ASCII characters
nextCodepoint = GetCodepointNext(text + offset, &nextCodepointSize);
bool puctuation = ispunct(nextCodepoint & 0xFF);
while (offset < textLength)
{
if ((puctuation && !ispunct(nextCodepoint & 0xFF)) || (!puctuation && (isspace(nextCodepoint & 0xFF) || ispunct(nextCodepoint & 0xFF))))
break;
if ((puctuation && !ispunct(nextCodepoint & 0xFF)) || (!puctuation && (isspace(nextCodepoint & 0xFF) || ispunct(nextCodepoint & 0xFF)))) break;
offset += nextCodepointSize;
accCodepointSize += nextCodepointSize;
nextCodepoint = GetCodepointNext(text + offset, &nextCodepointSize);
}
// Check whitespace to skip (ASCII only)
while (offset < textLength)
{
if (!isspace(nextCodepoint & 0xFF))
break;
if (!isspace(nextCodepoint & 0xFF)) break;
offset += nextCodepointSize;
accCodepointSize += nextCodepointSize;
nextCodepoint = GetCodepointNext(text + offset, &nextCodepointSize);
@ -3408,6 +3411,7 @@ int GuiProgressBar(Rectangle bounds, const char *textLeft, const char *textRight
GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x + (int)progress.width + (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.y + bounds.height - 1, bounds.width - (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) - (int)progress.width - 1, (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH) }, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_NORMAL)));
GuiDrawRectangle(RAYGUI_CLITERAL(Rectangle){ bounds.x + bounds.width - (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.y, (float)GuiGetStyle(PROGRESSBAR, BORDER_WIDTH), bounds.height+GuiGetStyle(PROGRESSBAR, BORDER_WIDTH)-1 }, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BORDER_COLOR_NORMAL)));
}
// Draw slider internal progress bar (depends on state)
progress.width -= 2*GuiGetStyle(PROGRESSBAR, PROGRESS_PADDING);
GuiDrawRectangle(progress, 0, BLANK, GetColor(GuiGetStyle(PROGRESSBAR, BASE_COLOR_PRESSED)));