4#include "MRViewer/exports.h"
39 struct BoundedValue<std::string>
43 std::optional<std::vector<std::string>> allowedValues;
56 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;};
57 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;};
58 template <>
struct UnderlyingValueTypeHelper<std::string> {
using type = std::string;};
79template <AllowedValueType T>
80requires std::is_arithmetic_v<T>
81[[nodiscard]] std::optional<T>
createValue( std::string_view name, T value, T min, T max,
bool consumeValueOverride =
true,
const EntryAttributes& attrs = {} )
85 min = std::numeric_limits<T>::lowest();
86 max = std::numeric_limits<T>::max();
90 static_assert(
sizeof(T) <=
sizeof(U),
"The used type is too large.");
92 auto ret =
detail::createValueLow<U>( name, detail::BoundedValue<U>{ .value = U( value ), .min = U( min ), .max = U( max ) }, consumeValueOverride, attrs );
93 return ret ? std::optional<T>( T( *ret ) ) : std::nullopt;
96[[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,
const EntryAttributes& attrs = {} );
102template <AllowedValueType T>
106 return ret ? std::optional<T>( T( *ret ) ) : std::nullopt;
110MRVIEWER_API
void pushTree( std::string_view name );
124 static constexpr std::string_view
kindName =
"button";
130 template <
typename T>
145 template <std::same_as<std::
string> T>
165 static constexpr std::string_view
kindName =
"value";
171 std::map<std::string, Entry, std::less<>>
elems;
173 static constexpr std::string_view
kindName =
"group";
178 std::variant<ButtonEntry, ValueEntry, GroupEntry>
value;
190 template <
typename T>
195 ret = unexpected_( selfName, T::kindName );
198 template <
typename T>
201 return const_cast<Entry *
>( this )->
template getAs<T>( selfName );
205 [[nodiscard]] MRVIEWER_API
Unexpected<std::string> unexpected_( std::string_view selfName, std::string_view tKindName );
Definition MRUITestEngine.h:69
tl::expected< T, E > Expected
Definition MRExpected.h:31
tl::unexpected< E > Unexpected
Definition MRExpected.h:34
Definition MRUITestEngine.h:30
std::optional< T > createValueLow(std::string_view name, std::optional< BoundedValue< T > > value, bool consumeValueOverride=true, const EntryAttributes &attrs={})
typename UnderlyingValueTypeHelper< T >::type UnderlyingValueType
Definition MRUITestEngine.h:61
Definition MRUITestEngine.h:20
const GroupEntry & getRootEntry()
Returns the current entry tree.
void stageFileDialogPaths(std::vector< std::filesystem::path > paths)
std::optional< T > createValueTentative(std::string_view name, bool consumeValueOverride=true, const EntryAttributes &attrs={})
Definition MRUITestEngine.h:103
std::optional< T > createValue(std::string_view name, T value, T min, T max, bool consumeValueOverride=true, const EntryAttributes &attrs={})
Definition MRUITestEngine.h:81
void markFrameTriggered()
std::vector< std::filesystem::path > consumeStagedFileDialogPaths()
bool createButton(std::string_view name, const EntryAttributes &attrs={})
void pushTree(std::string_view name)
Use those to group buttons into named groups.
std::vector< std::string > consumeStatusMessages()
Drain and return all status messages accumulated since the last drain.
void appendStatusMessage(std::string msg)
Definition MRUITestEngine.h:116
bool simulateClick
Set this to true to simulate a button click.
Definition MRUITestEngine.h:118
std::string disabledReason
Definition MRUITestEngine.h:122
static constexpr std::string_view kindName
Definition MRUITestEngine.h:124
Optional attributes reported to the test engine each frame alongside a widget registration.
Definition MRUITestEngine.h:24
std::string_view disabledReason
Non-empty marks the widget as disabled with this reason. Only read during the call.
Definition MRUITestEngine.h:26
Definition MRUITestEngine.h:177
std::variant< ButtonEntry, ValueEntry, GroupEntry > value
Definition MRUITestEngine.h:178
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:199
bool visitedOnThisFrame
Definition MRUITestEngine.h:182
Expected< T * > getAs(std::string_view selfName={})
Definition MRUITestEngine.h:191
Definition MRUITestEngine.h:169
static constexpr std::string_view kindName
Definition MRUITestEngine.h:173
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:171
Value()
Definition MRUITestEngine.h:156
std::optional< std::string > simulatedValue
Set to override the value.
Definition MRUITestEngine.h:154
std::string value
The current value.
Definition MRUITestEngine.h:149
std::optional< std::vector< std::string > > allowedValues
Definition MRUITestEngine.h:151
Definition MRUITestEngine.h:132
Value()
Definition MRUITestEngine.h:143
T max
Definition MRUITestEngine.h:138
T value
The current value.
Definition MRUITestEngine.h:134
T min
Min/max bounds, INCLUSIVE. If none, those are set to the min/max values representable in this type.
Definition MRUITestEngine.h:137
std::optional< T > simulatedValue
Set to override the value.
Definition MRUITestEngine.h:141
For sliders, drags, etc.
Definition MRUITestEngine.h:129
std::variant< Value< std::int64_t >, Value< std::uint64_t >, Value< double >, Value< std::string > > ValueVar
Definition MRUITestEngine.h:158
ValueVar value
Definition MRUITestEngine.h:159
std::string disabledReason
Definition MRUITestEngine.h:163
static constexpr std::string_view kindName
Definition MRUITestEngine.h:165
Definition MRUITestEngine.h:33
T min
Definition MRUITestEngine.h:35
T max
Definition MRUITestEngine.h:36
T value
Definition MRUITestEngine.h:34
Definition MRUITestEngine.h:54