mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
Internals: Tweaked ParseFormatPrecision(), clarified its more limited purpose, allowing 2-digits precisions since it makes (some) sense for doubles. (#648)
This commit is contained in:
parent
92f0165f85
commit
a1da7f9860
17
imgui.cpp
17
imgui.cpp
@ -8625,26 +8625,27 @@ const char* ImGui::ParseFormatTrimDecorations(const char* fmt, char* buf, int bu
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse display precision back from the display format string
|
// Parse display precision back from the display format string
|
||||||
|
// FIXME: This is still used by some navigation code path to infer a minimum tweak step, but we should aim to rework widgets so it isn't needed.
|
||||||
int ImGui::ParseFormatPrecision(const char* fmt, int default_precision)
|
int ImGui::ParseFormatPrecision(const char* fmt, int default_precision)
|
||||||
{
|
{
|
||||||
int precision = default_precision;
|
fmt = ParseFormatTrimDecorationsLeading(fmt);
|
||||||
while ((fmt = strchr(fmt, '%')) != NULL)
|
if (fmt[0] != '%')
|
||||||
{
|
return default_precision;
|
||||||
fmt++;
|
fmt++;
|
||||||
if (fmt[0] == '%') { fmt++; continue; } // Ignore "%%"
|
|
||||||
while (*fmt >= '0' && *fmt <= '9')
|
while (*fmt >= '0' && *fmt <= '9')
|
||||||
fmt++;
|
fmt++;
|
||||||
|
int precision = INT_MAX;
|
||||||
if (*fmt == '.')
|
if (*fmt == '.')
|
||||||
{
|
{
|
||||||
fmt = ImAtoi(fmt + 1, &precision);
|
fmt = ImAtoi(fmt + 1, &precision);
|
||||||
if (precision < 0 || precision > 10)
|
if (precision < 0 || precision > 99)
|
||||||
precision = default_precision;
|
precision = default_precision;
|
||||||
}
|
}
|
||||||
if (*fmt == 'e' || *fmt == 'E') // Maximum precision with scientific notation
|
if (*fmt == 'e' || *fmt == 'E') // Maximum precision with scientific notation
|
||||||
precision = -1;
|
precision = -1;
|
||||||
break;
|
if ((*fmt == 'g' || *fmt == 'G') && precision == INT_MAX)
|
||||||
}
|
precision = -1;
|
||||||
return precision;
|
return (precision == INT_MAX) ? default_precision : precision;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float GetMinimumStepAtDecimalPrecision(int decimal_precision)
|
static float GetMinimumStepAtDecimalPrecision(int decimal_precision)
|
||||||
|
Loading…
Reference in New Issue
Block a user