4#include "MRPch/MRFmt.h"
5#include "MRViewer/exports.h"
32 struct BoundedValue<std::string>
36 std::optional<std::vector<std::string>> allowedValues;
48 using UnderlyingValueType = std::conditional_t<std::is_floating_point_v<T>, double, std::conditional_t<std::is_signed_v<T>, std::int64_t, std::uint64_t>>;
53[[nodiscard]] MRVIEWER_API
bool createButton( std::string_view name );
62template <AllowedValueType T>
63requires std::is_arithmetic_v<T>
64[[nodiscard]] std::optional<T>
createValue( std::string_view name, T value, T min, T max )
68 min = std::numeric_limits<T>::lowest();
69 max = std::numeric_limits<T>::max();
73 static_assert(
sizeof(T) <=
sizeof(U),
"The used type is too large.");
76 return ret ? std::optional<T>( T( *ret ) ) : std::nullopt;
79[[nodiscard]] MRVIEWER_API std::optional<std::string>
createValue( std::string_view name, std::string value, std::optional<std::vector<std::string>> allowedValues = std::nullopt );
85template <AllowedValueType T>
89 return ret ? std::optional<T>( T( *ret ) ) : std::nullopt;
93MRVIEWER_API
void pushTree( std::string_view name );
103 static constexpr std::string_view
kindName =
"button";
109 template <
typename T>
124 template <std::same_as<std::
string> T>
140 static constexpr std::string_view
kindName =
"value";
146 std::map<std::string, Entry, std::less<>>
elems;
148 static constexpr std::string_view
kindName =
"group";
153 std::variant<ButtonEntry, ValueEntry, GroupEntry>
value;
165 template <
typename T>
171 if ( selfName.empty() )
172 ret =
unexpected( fmt::format(
"Expected UI entity to be a `{}` but got a `{}`.", T::kindName,
getKindName() ) );
174 ret =
unexpected( fmt::format(
"Expected UI entity `{}` to be a `{}` but got a `{}`.", selfName, T::kindName,
getKindName() ) );
178 template <
typename T>
181 return const_cast<Entry *
>( this )->
template getAs<T>( selfName );
Definition MRUITestEngine.h:56
MRVIEWER_API std::optional< T > createValueLow(std::string_view name, std::optional< BoundedValue< T > > value)
std::conditional_t< std::is_floating_point_v< T >, double, std::conditional_t< std::is_signed_v< T >, std::int64_t, std::uint64_t > > UnderlyingValueType
Definition MRUITestEngine.h:48
Definition MRUITestEngine.h:20
std::optional< T > createValue(std::string_view name, T value, T min, T max)
Definition MRUITestEngine.h:64
MRVIEWER_API bool createButton(std::string_view name)
std::optional< T > createValueTentative(std::string_view name)
Definition MRUITestEngine.h:86
MRVIEWER_API const GroupEntry & getRootEntry()
MRVIEWER_API void popTree()
MRVIEWER_API void pushTree(std::string_view name)
MR_BIND_IGNORE auto unexpected(E &&e)
Definition MRExpected.h:61
tl::expected< T, E > Expected
Definition MRExpected.h:58
Definition MRUITestEngine.h:99
bool simulateClick
Definition MRUITestEngine.h:101
static constexpr std::string_view kindName
Definition MRUITestEngine.h:103
Definition MRUITestEngine.h:152
std::variant< ButtonEntry, ValueEntry, GroupEntry > value
Definition MRUITestEngine.h:153
Expected< const T * > getAs(std::string_view selfName={}) const
Definition MRUITestEngine.h:179
MRVIEWER_API std::string_view getKindName() const
bool visitedOnThisFrame
Definition MRUITestEngine.h:157
Expected< T * > getAs(std::string_view selfName={})
Definition MRUITestEngine.h:166
Definition MRUITestEngine.h:144
static constexpr std::string_view kindName
Definition MRUITestEngine.h:148
std::map< std::string, Entry, std::less<> > elems
Definition MRUITestEngine.h:146
Value()
Definition MRUITestEngine.h:135
std::optional< std::string > simulatedValue
Definition MRUITestEngine.h:133
std::string value
Definition MRUITestEngine.h:128
std::optional< std::vector< std::string > > allowedValues
Definition MRUITestEngine.h:130
Definition MRUITestEngine.h:111
Value()
Definition MRUITestEngine.h:122
T max
Definition MRUITestEngine.h:117
T value
Definition MRUITestEngine.h:113
T min
Definition MRUITestEngine.h:116
std::optional< T > simulatedValue
Definition MRUITestEngine.h:120
Definition MRUITestEngine.h:108
std::variant< Value< std::int64_t >, Value< std::uint64_t >, Value< double >, Value< std::string > > ValueVar
Definition MRUITestEngine.h:137
ValueVar value
Definition MRUITestEngine.h:138
static constexpr std::string_view kindName
Definition MRUITestEngine.h:140
Definition MRUITestEngine.h:26
T min
Definition MRUITestEngine.h:28
T max
Definition MRUITestEngine.h:29
T value
Definition MRUITestEngine.h:27