Internal cleanup ParseFormatPrecision() doesn't take a reference

This commit is contained in:
ocornut 2015-07-30 23:14:29 -06:00
parent 7650d4cc67
commit faa609a43c

View File

@ -5911,8 +5911,9 @@ static bool InputFloatReplaceWidget(const ImRect& aabb, const char* label, float
} }
// Parse display precision back from the display format string // Parse display precision back from the display format string
static inline void ParseFormatPrecision(const char* fmt, int& decimal_precision) static inline int ParseFormatPrecision(const char* fmt, int default_precision)
{ {
int precision = default_precision;
while ((fmt = strchr(fmt, '%')) != NULL) while ((fmt = strchr(fmt, '%')) != NULL)
{ {
fmt++; fmt++;
@ -5921,12 +5922,13 @@ static inline void ParseFormatPrecision(const char* fmt, int& decimal_precision)
fmt++; fmt++;
if (*fmt == '.') if (*fmt == '.')
{ {
decimal_precision = atoi(fmt + 1); precision = atoi(fmt + 1);
if (decimal_precision < 0 || decimal_precision > 10) if (precision < 0 || precision > 10)
decimal_precision = 3; precision = default_precision;
} }
break; break;
} }
return precision;
} }
static inline float RoundScalar(float value, int decimal_precision) static inline float RoundScalar(float value, int decimal_precision)
@ -6107,8 +6109,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c
if (!display_format) if (!display_format)
display_format = "%.3f"; display_format = "%.3f";
int decimal_precision = 3; int decimal_precision = ParseFormatPrecision(display_format, 3);
ParseFormatPrecision(display_format, decimal_precision);
// Tabbing or CTRL-clicking on Slider turns it into an input box // Tabbing or CTRL-clicking on Slider turns it into an input box
bool start_text_input = false; bool start_text_input = false;
@ -6167,8 +6168,7 @@ bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float
if (!display_format) if (!display_format)
display_format = "%.3f"; display_format = "%.3f";
int decimal_precision = 3; int decimal_precision = ParseFormatPrecision(display_format, 3);
ParseFormatPrecision(display_format, decimal_precision);
if (hovered && g.IO.MouseClicked[0]) if (hovered && g.IO.MouseClicked[0])
{ {
@ -6410,8 +6410,7 @@ bool ImGui::DragFloat(const char* label, float *v, float v_speed, float v_min, f
if (!display_format) if (!display_format)
display_format = "%.3f"; display_format = "%.3f";
int decimal_precision = 3; int decimal_precision = ParseFormatPrecision(display_format, 3);
ParseFormatPrecision(display_format, decimal_precision);
// Tabbing or CTRL-clicking on Drag turns it into an input box // Tabbing or CTRL-clicking on Drag turns it into an input box
bool start_text_input = false; bool start_text_input = false;