MCPcopy Create free account
hub / github.com/YosysHQ/nextpnr / PatchFormatStringFloatToInt

Function PatchFormatStringFloatToInt

3rdparty/imgui/imgui_widgets.cpp:1495–1514  ·  view source on GitHub ↗

FIXME-LEGACY: Prior to 1.61 our DragInt() function internally used floats and because of this the compile-time default value for format was "%.0f". Even though we changed the compile-time default, we expect users to have carried %f around, which would break the display of DragInt() calls. To honor backward compatibility we are rewriting the format string, unless IMGUI_DISABLE_OBSOLETE_FUNCTIONS is

Source from the content-addressed store, hash-verified

1493// Even though we changed the compile-time default, we expect users to have carried %f around, which would break the display of DragInt() calls.
1494// To honor backward compatibility we are rewriting the format string, unless IMGUI_DISABLE_OBSOLETE_FUNCTIONS is enabled. What could possibly go wrong?!
1495static const char* PatchFormatStringFloatToInt(const char* fmt)
1496{
1497 if (fmt[0] == '%' && fmt[1] == '.' && fmt[2] == '0' && fmt[3] == 'f' && fmt[4] == 0) // Fast legacy path for "%.0f" which is expected to be the most common case.
1498 return "%d";
1499 const char* fmt_start = ImParseFormatFindStart(fmt); // Find % (if any, and ignore %%)
1500 const char* fmt_end = ImParseFormatFindEnd(fmt_start); // Find end of format specifier, which itself is an exercise of confidence/recklessness (because snprintf is dependent on libc or user).
1501 if (fmt_end > fmt_start && fmt_end[-1] == 'f')
1502 {
1503#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
1504 if (fmt_start == fmt && fmt_end[0] == 0)
1505 return "%d";
1506 ImGuiContext& g = *GImGui;
1507 ImFormatString(g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer), "%.*s%%d%s", (int)(fmt_start - fmt), fmt, fmt_end); // Honor leading and trailing decorations, but lose alignment/precision.
1508 return g.TempBuffer;
1509#else
1510 IM_ASSERT(0 && "DragInt(): Invalid format string!"); // Old versions used a default parameter of "%.0f", please replace with e.g. "%d"
1511#endif
1512 }
1513 return fmt;
1514}
1515
1516static inline int DataTypeFormatString(char* buf, int buf_size, ImGuiDataType data_type, const void* data_ptr, const char* format)
1517{

Callers 3

DragScalarMethod · 0.85
SliderScalarMethod · 0.85
VSliderScalarMethod · 0.85

Calls 3

ImParseFormatFindStartFunction · 0.85
ImParseFormatFindEndFunction · 0.85
ImFormatStringFunction · 0.85

Tested by

no test coverage detected