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;
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);
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)
{
Vector2 mousePoint = GetMousePosition();
bool valueHasChanged = false;
if (editMode)
@ -3070,7 +3069,7 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
keyCount--;
valueHasChanged = true;
}
else if (keyCount < RAYGUI_VALUEBOX_MAX_CHARS -1)
else if (keyCount < RAYGUI_VALUEBOX_MAX_CHARS)
{
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]
if (keyCount < RAYGUI_VALUEBOX_MAX_CHARS)
{
if (GuiGetTextWidth(textValue) < bounds.width)
// Add new digit to text value
if ((keyCount < RAYGUI_VALUEBOX_MAX_CHARS) && (GuiGetTextWidth(textValue) < bounds.width))
{
int key = GetCharPressed();
// Only allow keys in range [48..57]
if ((key >= 48) && (key <= 57))
{
textValue[keyCount] = (char)key;
@ -3100,18 +3099,14 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
valueHasChanged = true;
}
}
}
// Delete text
if (keyCount > 0)
{
if (IsKeyPressed(KEY_BACKSPACE))
if ((keyCount > 0) && IsKeyPressed(KEY_BACKSPACE))
{
keyCount--;
textValue[keyCount] = '\0';
valueHasChanged = true;
}
}
if (valueHasChanged) *value = TextToInteger(textValue);