4#include "MRViewer/exports.h"
31 struct BoundedValue<std::string>
35 std::optional<std::vector<std::string>> allowedValues;
39 [[nodiscard]] MRVIEWER_API std::optional<T>
createValueLow( std::string_view name, std::optional<
BoundedValue<T>> value,
bool consumeValueOverride =
true );
48 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;};
49 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;};
50 template <>
struct UnderlyingValueTypeHelper<std::string> {
using type = std::string;};
58[[nodiscard]] MRVIEWER_API
bool createButton( std::string_view name );
71template <AllowedValueType T>
72requires std::is_arithmetic_v<T>
73[[nodiscard]] std::optional<T>
createValue( std::string_view name, T value, T min, T max,
bool consumeValueOverride =
true )
77 min = std::numeric_limits<T>::lowest();
78 max = std::numeric_limits<T>::max();
82 static_assert(
sizeof(T) <=
sizeof(U),
"The used type is too large.");
85 return ret ? std::optional<T>( T( *ret ) ) : std::nullopt;
88[[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 );
94template <AllowedValueType T>
95[[nodiscard]] std::optional<T>
createValueTentative( std::string_view name,
bool consumeValueOverride =
true )
98 return ret ? std::optional<T>( T( *ret ) ) : std::nullopt;
102MRVIEWER_API
void pushTree( std::string_view name );
112 static constexpr std::string_view
kindName =
"button";
118 template <
typename T>
133 template <std::same_as<std::
string> T>
149 static constexpr std::string_view
kindName =
"value";
155 std::map<std::string, Entry, std::less<>>
elems;
157 static constexpr std::string_view
kindName =
"group";
162 std::variant<ButtonEntry, ValueEntry, GroupEntry>
value;
174 template <
typename T>
179 ret = unexpected_( selfName, T::kindName );
182 template <
typename T>
185 return const_cast<Entry *
>( this )->
template getAs<T>( selfName );
189 [[nodiscard]] MRVIEWER_API
Unexpected<std::string> unexpected_( std::string_view selfName, std::string_view tKindName );
Definition MRUITestEngine.h:61
tl::expected< T, E > Expected
Definition MRExpected.h:31
tl::unexpected< E > Unexpected
Definition MRExpected.h:34
Definition MRUITestEngine.h:22
std::optional< T > createValueLow(std::string_view name, std::optional< BoundedValue< T > > value, bool consumeValueOverride=true)
typename UnderlyingValueTypeHelper< T >::type UnderlyingValueType
Definition MRUITestEngine.h:53
Definition MRUITestEngine.h:19
const GroupEntry & getRootEntry()
Returns the current entry tree.
bool createButton(std::string_view name)
std::optional< T > createValueTentative(std::string_view name, bool consumeValueOverride=true)
Definition MRUITestEngine.h:95
void pushTree(std::string_view name)
Use those to group buttons into named groups.
std::optional< T > createValue(std::string_view name, T value, T min, T max, bool consumeValueOverride=true)
Definition MRUITestEngine.h:73
Definition MRUITestEngine.h:108
bool simulateClick
Set this to true to simulate a button click.
Definition MRUITestEngine.h:110
static constexpr std::string_view kindName
Definition MRUITestEngine.h:112
Definition MRUITestEngine.h:161
std::variant< ButtonEntry, ValueEntry, GroupEntry > value
Definition MRUITestEngine.h:162
std::string_view getKindName() const
Returns a string describing the type currently stored in value, which is T::kindName.
Expected< const T * > getAs(std::string_view selfName={}) const
Definition MRUITestEngine.h:183
bool visitedOnThisFrame
Definition MRUITestEngine.h:166
Expected< T * > getAs(std::string_view selfName={})
Definition MRUITestEngine.h:175
Definition MRUITestEngine.h:153
static constexpr std::string_view kindName
Definition MRUITestEngine.h:157
std::map< std::string, Entry, std::less<> > elems
Using std::map over std::unordered_map to be able to search by std::string_view keys directly.
Definition MRUITestEngine.h:155
Value()
Definition MRUITestEngine.h:144
std::optional< std::string > simulatedValue
Set to override the value.
Definition MRUITestEngine.h:142
std::string value
The current value.
Definition MRUITestEngine.h:137
std::optional< std::vector< std::string > > allowedValues
Definition MRUITestEngine.h:139
Definition MRUITestEngine.h:120
Value()
Definition MRUITestEngine.h:131
T max
Definition MRUITestEngine.h:126
T value
The current value.
Definition MRUITestEngine.h:122
T min
Min/max bounds, INCLUSIVE. If none, those are set to the min/max values representable in this type.
Definition MRUITestEngine.h:125
std::optional< T > simulatedValue
Set to override the value.
Definition MRUITestEngine.h:129
For sliders, drags, etc.
Definition MRUITestEngine.h:117
std::variant< Value< std::int64_t >, Value< std::uint64_t >, Value< double >, Value< std::string > > ValueVar
Definition MRUITestEngine.h:146
ValueVar value
Definition MRUITestEngine.h:147
static constexpr std::string_view kindName
Definition MRUITestEngine.h:149
Definition MRUITestEngine.h:25
T min
Definition MRUITestEngine.h:27
T max
Definition MRUITestEngine.h:28
T value
Definition MRUITestEngine.h:26
Definition MRUITestEngine.h:46