Skip to content

Commit 1393397

Browse files
authored
MRUITestEngine.h does not #include "MRPch/MRFmt.h" (#5274)
1 parent 200268d commit 1393397

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

source/MRViewer/MRUIQualityControl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "MRUIQualityControl.h"
2-
32
#include "MRViewer/MRUIStyle.h"
3+
#include "MRPch/MRFmt.h"
44

55
namespace MR::QualityControl
66
{

source/MRViewer/MRUIStyle.ipp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,14 @@ namespace detail
106106
ImGui::PushItemWidth( x - prevX );
107107
MR_FINALLY{ ImGui::PopItemWidth(); };
108108
prevX = x;
109+
std::string s;
110+
if ( i + 1 != VectorTraits<T>::size )
111+
s = "###";
112+
s += label;
113+
s += "##";
114+
s += std::to_string( i );
109115
bool elemChanged = func(
110-
fmt::format( "{}{}##{}", i == VectorTraits<T>::size - 1 ? "" : "###", label, i ).c_str(),
116+
s.c_str(),
111117
VectorTraits<T>::getElem( i, value ),
112118
i
113119
);
@@ -160,11 +166,11 @@ namespace detail
160166
std::string maxString = valueToString<E>( max, unitParams );
161167

162168
if ( haveMin && haveMax )
163-
return fmt::format( "Range: {} .. {}", minString, maxString );
169+
return "Range: " + minString + " .. " + maxString;
164170
if ( haveMin )
165-
return fmt::format( "Range: at least {}", minString );
171+
return "Range: at least " + minString;
166172
if ( haveMax )
167-
return fmt::format( "Range: at most {}", maxString );
173+
return "Range: at most " + maxString;
168174
return "";
169175
}
170176

@@ -464,20 +470,20 @@ bool plusMinusGeneric( const char* label, T& plus, T& minus, UnitToStringParams<
464470
auto getStateKeyIsAsym = [&, ret = std::string{}]() mutable -> const std::string&
465471
{
466472
if ( ret.empty() )
467-
ret = fmt::format( "MR::plusMinus:{}", label );
473+
ret = std::string( "MR::plusMinus:" ) + label;
468474
return ret;
469475
};
470476

471477
auto getPlusName = [&, ret = std::string{}]() mutable -> const std::string&
472478
{
473479
if ( ret.empty() )
474-
ret = fmt::format( "###plus:{}", label );
480+
ret = std::string( "###plus:" ) + label;
475481
return ret;
476482
};
477483
auto getMinusName = [&, ret = std::string{}]() mutable -> const std::string&
478484
{
479485
if ( ret.empty() )
480-
ret = fmt::format( "###minus:{}", label );
486+
ret = std::string( "###minus:" ) + label;
481487
return ret;
482488
};
483489

@@ -510,7 +516,7 @@ bool plusMinusGeneric( const char* label, T& plus, T& minus, UnitToStringParams<
510516

511517
// The symmetry toggle.
512518
ImGui::SetCursorPosX( ImGui::GetCursorPosX() + fullWidth - toggleSymButtonWidth );
513-
if ( ( buttonEx )( fmt::format( "{}###toggleSymmetry:{}", isAsym ? "\xC2\xB1"/*U+00B1 PLUS-MINUS SIGN*/ : "+/-", label ).c_str(), ImVec2( toggleSymButtonWidth, ImGui::GetFrameHeight() ), { .customTexture = UI::getTexture( UI::TextureType::GradientBtnGray ).get() } ) )
519+
if ( ( buttonEx )( ( ( isAsym ? "\xC2\xB1"/*U+00B1 PLUS-MINUS SIGN*/ : "+/-" ) + std::string( "###toggleSymmetry:" ) + label ).c_str(), ImVec2( toggleSymButtonWidth, ImGui::GetFrameHeight() ), { .customTexture = UI::getTexture( UI::TextureType::GradientBtnGray ).get() } ) )
514520
{
515521
isAsym = !isAsym;
516522

@@ -587,7 +593,7 @@ bool plusMinusGeneric( const char* label, T& plus, T& minus, UnitToStringParams<
587593
}
588594

589595
// This name can't match the plus/minus names, because we check if those are active above.
590-
if ( func( fmt::format( "###sym:{}", label ).c_str(), plus, std::move( unitToStringParams ) ) ) // Move the params on the last usage, in case the lambda decides to take them by value for some reason.
596+
if ( func( ( std::string( "###sym:" ) + label ).c_str(), plus, std::move( unitToStringParams ) ) ) // Move the params on the last usage, in case the lambda decides to take them by value for some reason.
591597
{
592598
minus = -plus;
593599
ret = true;

source/MRViewer/MRUITestEngine.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "MRUITestEngine.h"
2-
#include "MRPch/MRSpdlog.h"
32
#include "MRImGui.h"
3+
#include "MRPch/MRFmt.h"
44

55
#ifndef MR_ENABLE_UI_TEST_ENGINE
66
// Set to 0 to disable the UI test engine. All functions will act as if no UI elements are registered.
@@ -220,4 +220,12 @@ const GroupEntry& getRootEntry()
220220
return state.root;
221221
}
222222

223+
[[nodiscard]] MRVIEWER_API Unexpected<std::string> Entry::unexpected_( std::string_view selfName, std::string_view tKindName )
224+
{
225+
if ( selfName.empty() )
226+
return unexpected( fmt::format( "Expected UI entity to be a `{}` but got a `{}`.", tKindName, getKindName() ) );
227+
else
228+
return unexpected( fmt::format( "Expected UI entity `{}` to be a `{}` but got a `{}`.", selfName, tKindName, getKindName() ) );
223229
}
230+
231+
} // namespace MR::UI::TestEngine

source/MRViewer/MRUITestEngine.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include "MRMesh/MRExpected.h"
4-
#include "MRPch/MRFmt.h"
54
#include "MRViewer/exports.h"
65

76
#include <cstdint>
@@ -175,19 +174,17 @@ struct Entry
175174
{
176175
Expected<T *> ret = std::get_if<T>( &value );
177176
if ( !*ret )
178-
{
179-
if ( selfName.empty() )
180-
ret = unexpected( fmt::format( "Expected UI entity to be a `{}` but got a `{}`.", T::kindName, getKindName() ) );
181-
else
182-
ret = unexpected( fmt::format( "Expected UI entity `{}` to be a `{}` but got a `{}`.", selfName, T::kindName, getKindName() ) );
183-
}
177+
ret = unexpected_( selfName, T::kindName );
184178
return ret;
185179
}
186180
template <typename T>
187181
[[nodiscard]] Expected<const T *> getAs( std::string_view selfName = {} ) const
188182
{
189183
return const_cast<Entry *>( this )->template getAs<T>( selfName );
190184
}
185+
186+
private:
187+
[[nodiscard]] MRVIEWER_API Unexpected<std::string> unexpected_( std::string_view selfName, std::string_view tKindName );
191188
};
192189

193190
// Returns the current entry tree.

0 commit comments

Comments
 (0)