Fixed property input for negative values

zr_strtof did not have a conversion case for negative float values
which caused problems for negative float text input. In addition
zr_filter_decimal had a bug that did not allow '-' as correct input.
Both bugs have been fixed and it should work now.
This commit is contained in:
vurtun 2016-02-06 16:45:35 +01:00
parent 835e3a04bb
commit 1db24e4ca3
1 changed files with 10 additions and 2 deletions

View File

@ -549,6 +549,7 @@ static int
zr_strtof(float *number, const char *buffer)
{
float m;
float neg = 1.0f;
const char *p = buffer;
float floatvalue = 0;
@ -557,6 +558,13 @@ zr_strtof(float *number, const char *buffer)
if (!number || !buffer) return 0;
*number = 0;
/* skip whitespace */
while (*p && *p == ' ') p++;
if (*p == '-') {
neg = -1.0f;
p++;
}
while( *p && *p != '.' && *p != 'e' ) {
floatvalue = floatvalue * 10.0f + (float) (*p - '0');
p++;
@ -590,7 +598,7 @@ zr_strtof(float *number, const char *buffer)
floatvalue /= m;
else floatvalue *= m;
}
*number = floatvalue;
*number = floatvalue * neg;
return 1;
}
@ -5492,7 +5500,7 @@ int
zr_filter_decimal(const struct zr_edit_box *box, zr_rune unicode)
{
ZR_UNUSED(box);
if (unicode < '0' || unicode > '9')
if ((unicode < '0' || unicode > '9') && unicode != '-')
return zr_false;
else return zr_true;
}