MCPcopy Create free account
hub / github.com/RenderKit/embree / RoundScalarWithFormatT

Method RoundScalarWithFormatT

tutorials/common/imgui/imgui_widgets.cpp:2113–2135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2111
2112template<typename TYPE>
2113TYPE ImGui::RoundScalarWithFormatT(const char* format, ImGuiDataType data_type, TYPE v)
2114{
2115 IM_UNUSED(data_type);
2116 IM_ASSERT(data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double);
2117 const char* fmt_start = ImParseFormatFindStart(format);
2118 if (fmt_start[0] != '%' || fmt_start[1] == '%') // Don't apply if the value is not visible in the format string
2119 return v;
2120
2121 // Sanitize format
2122 char fmt_sanitized[32];
2123 ImParseFormatSanitizeForPrinting(fmt_start, fmt_sanitized, IM_ARRAYSIZE(fmt_sanitized));
2124 fmt_start = fmt_sanitized;
2125
2126 // Format value with our rounding, and read back
2127 char v_str[64];
2128 ImFormatString(v_str, IM_ARRAYSIZE(v_str), fmt_start, v);
2129 const char* p = v_str;
2130 while (*p == ' ')
2131 p++;
2132 v = (TYPE)ImAtof(p);
2133
2134 return v;
2135}
2136
2137//-------------------------------------------------------------------------
2138// [SECTION] Widgets: DragScalar, DragFloat, DragInt, etc.

Callers

nothing calls this directly

Calls 3

ImParseFormatFindStartFunction · 0.85
ImFormatStringFunction · 0.85

Tested by

no test coverage detected