Added unit tests for groups and toggle groups, fixed comments and syntax

Signed-off-by: Jose <jotamkin@amazon.com>
This commit is contained in:
Jose
2021-07-13 14:55:05 -05:00
parent bbf9a06133
commit bc9d0eb0e1
8 changed files with 363 additions and 65 deletions
@@ -237,13 +237,13 @@ namespace AZ
/**
* Declare element with attributes that belong to the class SerializeContext::Class, this is a logical structure, you can have one or more ClassElements.
* \uiId is the logical element ID (for instance "Group" when you want to group certain elements this class.
* then in each DataElement you can attach the appropriate group attribute.
* \param memberVariable - reference to the member variable to we can bind to serializations data.
* Declare element with attributes that belong to the class SerializeContext::Class, this is a logical structure, you can have one or more GroupElementToggles.
* T must be a boolean variable that will enable and disable each DataElement attached to this structure.
* \param description - Descriptive name of the field that will typically appear in a tooltip.
* \param memberVariable - reference to the member variable so we can bind to serialization data.
*/
template<class T>
ClassBuilder* ClassElement(Crc32 elementIdCrc, const char* description, T memberVariable);
ClassBuilder* GroupElementToggle(const char* description, T memberVariable);
/**
@@ -529,48 +529,9 @@ namespace AZ
// ClassElement
//=========================================================================
template<class T>
inline EditContext::ClassBuilder* EditContext::ClassBuilder::ClassElement(Crc32 elementIdCrc, const char* description, T memberVariable)
inline EditContext::ClassBuilder* EditContext::ClassBuilder::GroupElementToggle(const char* name, T memberVariable)
{
if (IsValid())
{
using ElementTypeInfo = typename SerializeInternal::ElementInfo<T>;
AZ_Assert(
m_classData->m_typeId == AzTypeInfo<typename ElementTypeInfo::ClassType>::Uuid(),
"Data element (%s) belongs to a different class!", description);
// Not really portable but works for the supported compilers
size_t offset =
reinterpret_cast<size_t>(&(reinterpret_cast<typename ElementTypeInfo::ClassType const volatile*>(0)->*memberVariable));
// offset = or pass it to the function with offsetof(typename ElementTypeInfo::ClassType,memberVariable);
SerializeContext::ClassElement* classElement = nullptr;
for (size_t i = 0; i < m_classData->m_elements.size(); ++i)
{
SerializeContext::ClassElement* element = &m_classData->m_elements[i];
if (element->m_offset == offset)
{
classElement = element;
break;
}
}
// We cannot continue past this point, we must alert the user to fix their serialization config and crash
AZ_Assert(
classElement,
"Class element for editor data element reflection '%s' was NOT found in the serialize context! This member MUST be "
"serializable to be editable!",
description);
m_classElement->m_elements.push_back();
Edit::ElementData& ed = m_classElement->m_elements.back();
classElement->m_editData = &ed;
m_editElement = &ed;
ed.m_elementId = elementIdCrc;
ed.m_name = description;
ed.m_description = description;
ed.m_serializeClassElement = classElement;
}
return this;
return DataElement(AZ::Edit::ClassElements::Group, memberVariable, name, name, "");
}
//=========================================================================