MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / valueToImGuiFormatString

Function valueToImGuiFormatString

source/MRViewer/MRUnits.cpp:582–639  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

580
581template <UnitEnum E, detail::Units::Scalar T>
582std::string valueToImGuiFormatString( T value, const UnitToStringParams<E>& params )
583{
584 std::string ret = replace( valueToString( value, params ), "%", "%%" );
585 ret += "##%";
586
587 if constexpr ( std::is_integral_v<T> )
588 {
589 using SignedT = std::make_signed_t<T>;
590 if constexpr ( std::is_same_v<SignedT, signed char> )
591 ret += "hh";
592 else if constexpr ( std::is_same_v<SignedT, short> )
593 ret += "h";
594 else if constexpr ( std::is_same_v<SignedT, int> )
595 ret += "";
596 else if constexpr ( std::is_same_v<SignedT, long> )
597 ret += "l";
598 else if constexpr ( std::is_same_v<SignedT, long long> )
599 ret += "ll";
600 else
601 static_assert( dependent_false<SignedT>, "Unknown integral type." );
602
603 ret += std::is_signed_v<T> ? "d" : "u";
604 }
605 else
606 {
607 int precision = 0;
608 std::size_t pos = ret.find( '.' );
609 if ( pos != std::string::npos )
610 {
611 pos++;
612 while (
613 std::isdigit( (unsigned char)ret[pos + precision] ) ||
614 ( params.thousandsSeparatorFrac && ret[pos + precision] == params.thousandsSeparatorFrac )
615 )
616 precision++;
617 }
618
619 fmt::format_to( std::back_inserter( ret ), ".{}", precision );
620
621 if constexpr ( std::is_same_v<T, float> )
622 ; // Nothing.
623 else if constexpr ( std::is_same_v<T, double> )
624 ; // Nothing. Same as for `float`, yes.
625 else if constexpr ( std::is_same_v<T, long double> )
626 ret += 'L';
627 else
628 static_assert( dependent_false<T>, "Unknown floating-point type." );
629
630 if ( params.style == NumberStyle::exponential )
631 ret += 'e';
632 else if ( params.style == NumberStyle::maybeExponential )
633 ret += 'g';
634 else
635 ret += 'f';
636 }
637
638 return ret;
639}

Callers 3

drawPoltHorizontalAxisFunction · 0.85
drawPoltVerticalAxisFunction · 0.85
MRUnits.hFile · 0.85

Calls 3

replaceFunction · 0.85
valueToStringFunction · 0.85
findMethod · 0.45

Tested by

no test coverage detected