فهرست منبع

Add global registry function for custom data variable definition (#367)

Maximilian Stark 3 سال پیش
والد
کامیت
cacd8f820c
1فایلهای تغییر یافته به همراه19 افزوده شده و 0 حذف شده
  1. 19 0
      Include/RmlUi/Core/DataModelHandle.h

+ 19 - 0
Include/RmlUi/Core/DataModelHandle.h

@@ -107,6 +107,10 @@ public:
 	template<typename T>
 	template<typename T>
 	StructHandle<T> RegisterStruct();
 	StructHandle<T> RegisterStruct();
 
 
+	// Register a user-declared VariableDefinition to describe a custom type behaviour.
+	template<typename T>
+	bool RegisterCustomDataVariableDefinition(UniquePtr<VariableDefinition> definition);
+
 	// Register an array type.
 	// Register an array type.
 	// @note The type applies to every data model associated with the current Context.
 	// @note The type applies to every data model associated with the current Context.
 	// @note If 'Container::value_type' represents a non-scalar type, that type must already have been registered with the appropriate 'Register...()' functions.
 	// @note If 'Container::value_type' represents a non-scalar type, that type must already have been registered with the appropriate 'Register...()' functions.
@@ -149,6 +153,21 @@ inline bool DataModelConstructor::RegisterScalar(DataTypeGetFunc<T> get_func, Da
 	return true;
 	return true;
 }
 }
 
 
+template<typename T>
+inline bool DataModelConstructor::RegisterCustomDataVariableDefinition(UniquePtr<VariableDefinition> definition)
+{
+	const FamilyId id = Family<T>::Id();
+
+	const bool inserted = type_register->RegisterDefinition(id, std::move(definition));
+	if (!inserted)
+	{
+		RMLUI_LOG_TYPE_ERROR(T, "Custom data type already registered.");
+		return false;
+	}
+
+	return true;
+}
+
 template<typename T>
 template<typename T>
 inline StructHandle<T> DataModelConstructor::RegisterStruct()
 inline StructHandle<T> DataModelConstructor::RegisterStruct()
 {
 {