mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Removed runtime patching of obsolete/invalid "%f"/"%.0f" types of format strings for DragInt()/SliderInt().
This commit is contained in:
@ -1895,7 +1895,6 @@ bool ImGui::Combo(const char* label, int* current_item, const char* items_separa
|
||||
//-------------------------------------------------------------------------
|
||||
// [SECTION] Data Type and Data Formatting Helpers [Internal]
|
||||
//-------------------------------------------------------------------------
|
||||
// - PatchFormatStringFloatToInt()
|
||||
// - DataTypeGetInfo()
|
||||
// - DataTypeFormatString()
|
||||
// - DataTypeApplyOp()
|
||||
@ -1926,30 +1925,6 @@ static const ImGuiDataTypeInfo GDataTypeInfo[] =
|
||||
};
|
||||
IM_STATIC_ASSERT(IM_ARRAYSIZE(GDataTypeInfo) == ImGuiDataType_COUNT);
|
||||
|
||||
// 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 enabled. What could possibly go wrong?!
|
||||
static const char* PatchFormatStringFloatToInt(const char* fmt)
|
||||
{
|
||||
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.
|
||||
return "%d";
|
||||
const char* fmt_start = ImParseFormatFindStart(fmt); // Find % (if any, and ignore %%)
|
||||
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).
|
||||
if (fmt_end > fmt_start && fmt_end[-1] == 'f')
|
||||
{
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
||||
if (fmt_start == fmt && fmt_end[0] == 0)
|
||||
return "%d";
|
||||
const char* tmp_format;
|
||||
ImFormatStringToTempBuffer(&tmp_format, NULL, "%.*s%%d%s", (int)(fmt_start - fmt), fmt, fmt_end); // Honor leading and trailing decorations, but lose alignment/precision.
|
||||
return tmp_format;
|
||||
#else
|
||||
IM_ASSERT(0 && "DragInt(): Invalid format string!"); // Old versions used a default parameter of "%.0f", please replace with e.g. "%d"
|
||||
#endif
|
||||
}
|
||||
return fmt;
|
||||
}
|
||||
|
||||
const ImGuiDataTypeInfo* ImGui::DataTypeGetInfo(ImGuiDataType data_type)
|
||||
{
|
||||
IM_ASSERT(data_type >= 0 && data_type < ImGuiDataType_COUNT);
|
||||
@ -2363,8 +2338,6 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data,
|
||||
// Default format string when passing NULL
|
||||
if (format == NULL)
|
||||
format = DataTypeGetInfo(data_type)->PrintFmt;
|
||||
else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.)
|
||||
format = PatchFormatStringFloatToInt(format);
|
||||
|
||||
const bool hovered = ItemHoverable(frame_bb, id);
|
||||
bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id);
|
||||
@ -2956,8 +2929,6 @@ bool ImGui::SliderScalar(const char* label, ImGuiDataType data_type, void* p_dat
|
||||
// Default format string when passing NULL
|
||||
if (format == NULL)
|
||||
format = DataTypeGetInfo(data_type)->PrintFmt;
|
||||
else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.)
|
||||
format = PatchFormatStringFloatToInt(format);
|
||||
|
||||
const bool hovered = ItemHoverable(frame_bb, id);
|
||||
bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id);
|
||||
@ -3123,8 +3094,6 @@ bool ImGui::VSliderScalar(const char* label, const ImVec2& size, ImGuiDataType d
|
||||
// Default format string when passing NULL
|
||||
if (format == NULL)
|
||||
format = DataTypeGetInfo(data_type)->PrintFmt;
|
||||
else if (data_type == ImGuiDataType_S32 && strcmp(format, "%d") != 0) // (FIXME-LEGACY: Patch old "%.0f" format string to use "%d", read function more details.)
|
||||
format = PatchFormatStringFloatToInt(format);
|
||||
|
||||
const bool hovered = ItemHoverable(frame_bb, id);
|
||||
if ((hovered && g.IO.MouseClicked[0]) || g.NavActivateId == id || g.NavActivateInputId == id)
|
||||
|
Reference in New Issue
Block a user