Update raygui.h

This commit is contained in:
Ray
2025-11-18 16:49:44 +01:00
parent ff4dbd0712
commit 773d1ec52b

View File

@ -3033,7 +3033,7 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
int result = 0; int result = 0;
GuiState state = guiState; GuiState state = guiState;
char textValue[RAYGUI_VALUEBOX_MAX_CHARS + 1] = "\0"; char textValue[RAYGUI_VALUEBOX_MAX_CHARS + 1] = { 0 };
snprintf(textValue, RAYGUI_VALUEBOX_MAX_CHARS + 1, "%i", *value); snprintf(textValue, RAYGUI_VALUEBOX_MAX_CHARS + 1, "%i", *value);
Rectangle textBounds = { 0 }; Rectangle textBounds = { 0 };
@ -3051,7 +3051,6 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
if ((state != STATE_DISABLED) && !guiLocked && !guiControlExclusiveMode) if ((state != STATE_DISABLED) && !guiLocked && !guiControlExclusiveMode)
{ {
Vector2 mousePoint = GetMousePosition(); Vector2 mousePoint = GetMousePosition();
bool valueHasChanged = false; bool valueHasChanged = false;
if (editMode) if (editMode)
@ -3070,7 +3069,7 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
keyCount--; keyCount--;
valueHasChanged = true; valueHasChanged = true;
} }
else if (keyCount < RAYGUI_VALUEBOX_MAX_CHARS -1) else if (keyCount < RAYGUI_VALUEBOX_MAX_CHARS)
{ {
if (keyCount == 0) if (keyCount == 0)
{ {
@ -3087,12 +3086,12 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
} }
} }
// Only allow keys in range [48..57] // Add new digit to text value
if (keyCount < RAYGUI_VALUEBOX_MAX_CHARS) if ((keyCount < RAYGUI_VALUEBOX_MAX_CHARS) && (GuiGetTextWidth(textValue) < bounds.width))
{
if (GuiGetTextWidth(textValue) < bounds.width)
{ {
int key = GetCharPressed(); int key = GetCharPressed();
// Only allow keys in range [48..57]
if ((key >= 48) && (key <= 57)) if ((key >= 48) && (key <= 57))
{ {
textValue[keyCount] = (char)key; textValue[keyCount] = (char)key;
@ -3100,18 +3099,14 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
valueHasChanged = true; valueHasChanged = true;
} }
} }
}
// Delete text // Delete text
if (keyCount > 0) if ((keyCount > 0) && IsKeyPressed(KEY_BACKSPACE))
{
if (IsKeyPressed(KEY_BACKSPACE))
{ {
keyCount--; keyCount--;
textValue[keyCount] = '\0'; textValue[keyCount] = '\0';
valueHasChanged = true; valueHasChanged = true;
} }
}
if (valueHasChanged) *value = TextToInteger(textValue); if (valueHasChanged) *value = TextToInteger(textValue);