4#include "MRPch/MRFmt.h"
5#include "MRViewer/exports.h"
32 struct BoundedValue<std::string>
36 std::optional<std::vector<std::string>> allowedValues;
40 [[nodiscard]] MRVIEWER_API std::optional<T>
createValueLow( std::string_view name, std::optional<
BoundedValue<T>> value,
bool consumeValueOverride =
true );
49 template <
typename T>
struct UnderlyingValueTypeHelper<T, std::enable_if_t<std::is_integral_v<T> && std::is_signed_v<T>>> {
using type = std::int64_t;};
50 template <
typename T>
struct UnderlyingValueTypeHelper<T, std::enable_if_t<std::is_integral_v<T> && std::is_unsigned_v<T>>> {
using type = std::uint64_t;};
51 template <>
struct UnderlyingValueTypeHelper<std::string> {
using type = std::string;};
59[[nodiscard]] MRVIEWER_API
bool createButton( std::string_view name );
70template <AllowedValueType T>
71requires std::is_arithmetic_v<T>
72[[nodiscard]] std::optional<T>
createValue( std::string_view name, T value, T min, T max,
bool consumeValueOverride =
true )
76 min = std::numeric_limits<T>::lowest();
77 max = std::numeric_limits<T>::max();
81 static_assert(
sizeof(T) <=
sizeof(U),
"The used type is too large.");
84 return ret ? std::optional<T>( T( *ret ) ) : std::nullopt;
87[[nodiscard]] MRVIEWER_API std::optional<std::string>
createValue( std::string_view name, std::string value,
bool consumeValueOverride =
true, std::optional<std::vector<std::string>> allowedValues = std::nullopt );
93template <AllowedValueType T>
94[[nodiscard]] std::optional<T>
createValueTentative( std::string_view name,
bool consumeValueOverride =
true )
97 return ret ? std::optional<T>( T( *ret ) ) : std::nullopt;
101MRVIEWER_API
void pushTree( std::string_view name );
111 static constexpr std::string_view
kindName =
"button";
117 template <
typename T>
132 template <std::same_as<std::
string> T>
148 static constexpr std::string_view
kindName =
"value";
154 std::map<std::string, Entry, std::less<>>
elems;
156 static constexpr std::string_view
kindName =
"group";
161 std::variant<ButtonEntry, ValueEntry, GroupEntry>
value;
173 template <
typename T>
179 if ( selfName.empty() )
180 ret =
unexpected( fmt::format(
"Expected UI entity to be a `{}` but got a `{}`.", T::kindName,
getKindName() ) );
182 ret =
unexpected( fmt::format(
"Expected UI entity `{}` to be a `{}` but got a `{}`.", selfName, T::kindName,
getKindName() ) );
186 template <
typename T>
189 return const_cast<Entry *
>( this )->
template getAs<T>( selfName );
Definition MRUITestEngine.h:62
MRVIEWER_API std::optional< T > createValueLow(std::string_view name, std::optional< BoundedValue< T > > value, bool consumeValueOverride=true)
typename UnderlyingValueTypeHelper< T >::type UnderlyingValueType
Definition MRUITestEngine.h:54
Definition MRUITestEngine.h:20
MRVIEWER_API bool createButton(std::string_view name)
std::optional< T > createValueTentative(std::string_view name, bool consumeValueOverride=true)
Definition MRUITestEngine.h:94
MRVIEWER_API const GroupEntry & getRootEntry()
std::optional< T > createValue(std::string_view name, T value, T min, T max, bool consumeValueOverride=true)
Definition MRUITestEngine.h:72
MRVIEWER_API void popTree()
MRVIEWER_API void pushTree(std::string_view name)
MR_BIND_IGNORE auto unexpected(E &&e)
Definition MRExpected.h:28
tl::expected< T, E > Expected
Definition MRExpected.h:25
Definition MRUITestEngine.h:107
bool simulateClick
Definition MRUITestEngine.h:109
static constexpr std::string_view kindName
Definition MRUITestEngine.h:111
Definition MRUITestEngine.h:160
std::variant< ButtonEntry, ValueEntry, GroupEntry > value
Definition MRUITestEngine.h:161
Expected< const T * > getAs(std::string_view selfName={}) const
Definition MRUITestEngine.h:187
MRVIEWER_API std::string_view getKindName() const
bool visitedOnThisFrame
Definition MRUITestEngine.h:165
Expected< T * > getAs(std::string_view selfName={})
Definition MRUITestEngine.h:174
Definition MRUITestEngine.h:152
static constexpr std::string_view kindName
Definition MRUITestEngine.h:156
std::map< std::string, Entry, std::less<> > elems
Definition MRUITestEngine.h:154
Value()
Definition MRUITestEngine.h:143
std::optional< std::string > simulatedValue
Definition MRUITestEngine.h:141
std::string value
Definition MRUITestEngine.h:136
std::optional< std::vector< std::string > > allowedValues
Definition MRUITestEngine.h:138
Definition MRUITestEngine.h:119
Value()
Definition MRUITestEngine.h:130
T max
Definition MRUITestEngine.h:125
T value
Definition MRUITestEngine.h:121
T min
Definition MRUITestEngine.h:124
std::optional< T > simulatedValue
Definition MRUITestEngine.h:128
Definition MRUITestEngine.h:116
std::variant< Value< std::int64_t >, Value< std::uint64_t >, Value< double >, Value< std::string > > ValueVar
Definition MRUITestEngine.h:145
ValueVar value
Definition MRUITestEngine.h:146
static constexpr std::string_view kindName
Definition MRUITestEngine.h:148
Definition MRUITestEngine.h:26
T min
Definition MRUITestEngine.h:28
T max
Definition MRUITestEngine.h:29
T value
Definition MRUITestEngine.h:27
Definition MRUITestEngine.h:47