mirror of
https://github.com/raysan5/raygui.git
synced 2025-12-25 10:22:33 -05:00
Add minus toggle for GuiValueBox & GuiValueBoxFloat (#485)
It was impossible to enter negative number. Now pressing KEY_MINUS toggles sign for the value when value is not 0. Due to original implementation it's not possible to start entry with minus symbol or have added minus while the value is 0. fix max index
This commit is contained in:
committed by
GitHub
parent
e00c4c18e0
commit
cb78993237
56
src/raygui.h
56
src/raygui.h
@ -3045,6 +3045,34 @@ int GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, in
|
|||||||
|
|
||||||
int keyCount = (int)strlen(textValue);
|
int keyCount = (int)strlen(textValue);
|
||||||
|
|
||||||
|
// Add or remove minus symbol
|
||||||
|
if (IsKeyPressed(KEY_MINUS))
|
||||||
|
{
|
||||||
|
if (textValue[0] == '-')
|
||||||
|
{
|
||||||
|
for(int i = 0 ; i < keyCount; i++ )
|
||||||
|
{
|
||||||
|
textValue[i] = textValue[i + 1];
|
||||||
|
}
|
||||||
|
keyCount--;
|
||||||
|
valueHasChanged = true;
|
||||||
|
}
|
||||||
|
else if (keyCount < RAYGUI_VALUEBOX_MAX_CHARS -1){
|
||||||
|
if (keyCount == 0){
|
||||||
|
textValue[0] = '0';
|
||||||
|
textValue[1] = '\0';
|
||||||
|
keyCount++;
|
||||||
|
}
|
||||||
|
for(int i = keyCount ; i > -1; i-- )
|
||||||
|
{
|
||||||
|
textValue[i + 1] = textValue[i];
|
||||||
|
}
|
||||||
|
textValue[0] = '-';
|
||||||
|
keyCount++;
|
||||||
|
valueHasChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Only allow keys in range [48..57]
|
// Only allow keys in range [48..57]
|
||||||
if (keyCount < RAYGUI_VALUEBOX_MAX_CHARS)
|
if (keyCount < RAYGUI_VALUEBOX_MAX_CHARS)
|
||||||
{
|
{
|
||||||
@ -3164,6 +3192,34 @@ int GuiValueBoxFloat(Rectangle bounds, const char *text, char *textValue, float
|
|||||||
|
|
||||||
int keyCount = (int)strlen(textValue);
|
int keyCount = (int)strlen(textValue);
|
||||||
|
|
||||||
|
// Add or remove minus symbol
|
||||||
|
if (IsKeyPressed(KEY_MINUS))
|
||||||
|
{
|
||||||
|
if (textValue[0] == '-')
|
||||||
|
{
|
||||||
|
for (int i = 0; i < keyCount; i++)
|
||||||
|
{
|
||||||
|
textValue[i] = textValue[i + 1];
|
||||||
|
}
|
||||||
|
keyCount--;
|
||||||
|
valueHasChanged = true;
|
||||||
|
}
|
||||||
|
else if (keyCount < RAYGUI_VALUEBOX_MAX_CHARS - 1) {
|
||||||
|
if (keyCount == 0) {
|
||||||
|
textValue[0] = '0';
|
||||||
|
textValue[1] = '\0';
|
||||||
|
keyCount++;
|
||||||
|
}
|
||||||
|
for (int i = keyCount; i > -1; i--)
|
||||||
|
{
|
||||||
|
textValue[i + 1] = textValue[i];
|
||||||
|
}
|
||||||
|
textValue[0] = '-';
|
||||||
|
keyCount++;
|
||||||
|
valueHasChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Only allow keys in range [48..57]
|
// Only allow keys in range [48..57]
|
||||||
if (keyCount < RAYGUI_VALUEBOX_MAX_CHARS)
|
if (keyCount < RAYGUI_VALUEBOX_MAX_CHARS)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user