4#include "MRViewer/exports.h"
42 struct BoundedValue<std::string>
46 std::optional<std::vector<std::string>> allowedValues;
59 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;};
60 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;};
61 template <>
struct UnderlyingValueTypeHelper<std::string> {
using type = std::string;};
82template <AllowedValueType T>
83requires std::is_arithmetic_v<T>
84[[nodiscard]] std::optional<T>
createValue( std::string_view name, T value, T min, T max,
bool consumeValueOverride =
true,
const EntryAttributes& attrs = {} )
88 min = std::numeric_limits<T>::lowest();
89 max = std::numeric_limits<T>::max();
93 static_assert(
sizeof(T) <=
sizeof(U),
"The used type is too large.");
95 auto ret =
detail::createValueLow<U>( name, detail::BoundedValue<U>{ .value = U( value ), .min = U( min ), .max = U( max ) }, consumeValueOverride, attrs );
96 return ret ? std::optional<T>( T( *ret ) ) : std::nullopt;
99[[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 = {} );
105template <AllowedValueType T>
109 return ret ? std::optional<T>( T( *ret ) ) : std::nullopt;
113MRVIEWER_API
void pushTree( std::string_view name );
138 static constexpr std::string_view
kindName =
"button";
144 template <
typename T>
159 template <std::same_as<std::
string> T>
179 static constexpr std::string_view
kindName =
"value";
185 std::map<std::string, Entry, std::less<>>
elems;
187 static constexpr std::string_view
kindName =
"group";
192 std::variant<ButtonEntry, ValueEntry, GroupEntry>
value;
204 template <
typename T>
209 ret = unexpected_( selfName, T::kindName );
212 template <
typename T>
215 return const_cast<Entry *
>( this )->
template getAs<T>( selfName );
219 [[nodiscard]] MRVIEWER_API
Unexpected<std::string> unexpected_( std::string_view selfName, std::string_view tKindName );
TreeGuard & operator=(const TreeGuard &)=delete
TreeGuard(const TreeGuard &)=delete
TreeGuard(std::string_view name)
Definition MRUITestEngine.h:121
~TreeGuard()
Definition MRUITestEngine.h:122
Definition MRUITestEngine.h:72
tl::expected< T, E > Expected
Definition MRExpected.h:31
tl::unexpected< E > Unexpected
Definition MRExpected.h:34
Definition MRUITestEngine.h:33
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:64
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:106
std::optional< T > createValue(std::string_view name, T value, T min, T max, bool consumeValueOverride=true, const EntryAttributes &attrs={})
Definition MRUITestEngine.h:84
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:130
bool simulateClick
Set this to true to simulate a button click.
Definition MRUITestEngine.h:132
std::string disabledReason
Definition MRUITestEngine.h:136
static constexpr std::string_view kindName
Definition MRUITestEngine.h:138
Optional attributes reported to the test engine each frame alongside a widget registration.
Definition MRUITestEngine.h:24
bool ignoreBlockingModal
If true, the entry stays enabled while a modal popup is open, e.g. for a value registered outside of ...
Definition MRUITestEngine.h:29
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:191
std::variant< ButtonEntry, ValueEntry, GroupEntry > value
Definition MRUITestEngine.h:192
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:213
bool visitedOnThisFrame
Definition MRUITestEngine.h:196
Expected< T * > getAs(std::string_view selfName={})
Definition MRUITestEngine.h:205
Definition MRUITestEngine.h:183
static constexpr std::string_view kindName
Definition MRUITestEngine.h:187
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:185
Value()
Definition MRUITestEngine.h:170
std::optional< std::string > simulatedValue
Set to override the value.
Definition MRUITestEngine.h:168
std::string value
The current value.
Definition MRUITestEngine.h:163
std::optional< std::vector< std::string > > allowedValues
Definition MRUITestEngine.h:165
Definition MRUITestEngine.h:146
Value()
Definition MRUITestEngine.h:157
T max
Definition MRUITestEngine.h:152
T value
The current value.
Definition MRUITestEngine.h:148
T min
Min/max bounds, INCLUSIVE. If none, those are set to the min/max values representable in this type.
Definition MRUITestEngine.h:151
std::optional< T > simulatedValue
Set to override the value.
Definition MRUITestEngine.h:155
For sliders, drags, etc.
Definition MRUITestEngine.h:143
std::variant< Value< std::int64_t >, Value< std::uint64_t >, Value< double >, Value< std::string > > ValueVar
Definition MRUITestEngine.h:172
ValueVar value
Definition MRUITestEngine.h:173
std::string disabledReason
Definition MRUITestEngine.h:177
static constexpr std::string_view kindName
Definition MRUITestEngine.h:179
Definition MRUITestEngine.h:36
T min
Definition MRUITestEngine.h:38
T max
Definition MRUITestEngine.h:39
T value
Definition MRUITestEngine.h:37
Definition MRUITestEngine.h:57