/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
DALI_TEST_EQUALS( propertySetCheck.mValue, Property::Value( 29 ), TEST_LOCATION );
END_TEST;
}
+
+int UtcDaliHandlePropertySetProperties(void)
+{
+ TestApplication application;
+ const Vector3 actorSize( 10.0f, 20.0f, 30.0f );
+ const Vector3 anchorPoint( 1.0f, 0.5f, 0.0f );
+ const Vector4 color( 0.1f, 0.2, 0.3f, 0.4f );
+
+ Handle handle = Actor::New();
+ DevelHandle::SetProperties(
+ handle,
+ Property::Map
+ {
+ { Actor::Property::SIZE, actorSize },
+ { Actor::Property::ANCHOR_POINT, anchorPoint },
+ { "color", color },
+ { "invalid", Vector2::ZERO } // It should quietly ignore invalid data
+ }
+ );
+ DALI_TEST_EQUALS( handle.GetProperty( Actor::Property::SIZE ).Get< Vector3 >(), actorSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( handle.GetProperty( Actor::Property::ANCHOR_POINT ).Get< Vector3 >(), anchorPoint, TEST_LOCATION );
+ DALI_TEST_EQUALS( handle.GetProperty( Actor::Property::COLOR ).Get< Vector4 >(), color, TEST_LOCATION );
+
+ END_TEST;
+}
+
+int UtcDaliHandleTemplateNew(void)
+{
+ TestApplication application;
+ const Vector3 actorSize( 10.0f, 20.0f, 30.0f );
+ const Vector3 anchorPoint( 1.0f, 0.5f, 0.0f );
+ const Vector4 color( 0.1f, 0.2, 0.3f, 0.4f );
+
+ Handle handle = DevelHandle::New< Actor >(
+ Property::Map
+ {
+ { Actor::Property::SIZE, actorSize },
+ { Actor::Property::ANCHOR_POINT, anchorPoint },
+ { "color", color },
+ { "invalid", Vector2::ZERO } // It should quietly ignore invalid data
+ }
+ );
+
+ DALI_TEST_EQUALS( handle.GetProperty( Actor::Property::SIZE ).Get< Vector3 >(), actorSize, TEST_LOCATION );
+ DALI_TEST_EQUALS( handle.GetProperty( Actor::Property::ANCHOR_POINT ).Get< Vector3 >(), anchorPoint, TEST_LOCATION );
+ DALI_TEST_EQUALS( handle.GetProperty( Actor::Property::COLOR ).Get< Vector4 >(), color, TEST_LOCATION );
+
+ END_TEST;
+}
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return GetImplementation( handle ).RegisterProperty( name, key, propertyValue );
}
+void SetProperties( Handle handle, const Property::Map& properties )
+{
+ GetImplementation( handle ).SetProperties( properties );
+}
+
void SetTypeInfo( Handle& handle, const TypeInfo& typeInfo )
{
GetImplementation( handle ).SetTypeInfo( &GetImplementation( typeInfo ) );
#define DALI_HANDLE_DEVEL_H
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
DALI_CORE_API Property::Index RegisterProperty( Handle handle, Property::Index key, const std::string& name, const Property::Value& propertyValue );
/**
+ * @brief Sets all the properties in the given property map.
+ *
+ * @param[in] handle The handle to set the properties on
+ * @param[in] properties The properties to set
+ */
+DALI_CORE_API void SetProperties( Handle handle, const Property::Map& properties );
+
+/**
* @brief Set the type-info that the object is created by.
*
* @note This is particularly useful to link C# custom control with its correct type-info in the native side
*/
DALI_CORE_API PropertySetSignalType& PropertySetSignal( Handle handle );
+/**
+ * @brief Template to create a derived handle and set properties on it.
+ *
+ * @tparam T The derived class to create
+ *
+ * @param[in] properties The properties to set
+ */
+template< typename T >
+DALI_INTERNAL T New( const Property::Map& properties )
+{
+ T handle = T::New();
+ SetProperties( handle, properties );
+ return handle;
+}
} // namespace DevelHandle
/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
return RegisterProperty( name, key, propertyValue, Property::ANIMATABLE );
}
+void Object::SetProperties( const Property::Map& properties )
+{
+ const auto count = properties.Count();
+ for( auto position = 0u; position < count; ++position )
+ {
+ // GetKeyAt and GetValue both return references which means no potential copying of maps/arrays.
+ // Iterating twice to get the value we want should still be fairly quick in a Property::Map.
+
+ const auto& key = properties.GetKeyAt( position );
+ const auto propertyIndex = ( key.type == Property::Key::INDEX ) ? key.indexKey : GetPropertyIndex( key.stringKey );
+
+ if( propertyIndex != Property::INVALID_INDEX )
+ {
+ const auto& value = properties.GetValue( position );
+ SetProperty( propertyIndex, value );
+ }
+ }
+}
+
Property::Index Object::RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode )
{
return RegisterProperty( name, Property::INVALID_KEY, propertyValue, accessMode );
#include <dali/public-api/object/property.h>
#include <dali/public-api/object/property-index-ranges.h>
#include <dali/public-api/object/property-input.h>
+#include <dali/public-api/object/property-map.h>
#include <dali/public-api/object/property-notification.h>
#include <dali/devel-api/common/owner-container.h>
#include <dali/devel-api/object/handle-devel.h>
Property::Index RegisterProperty( const std::string& name, Property::Index key, const Property::Value& propertyValue );
/**
+ * @copydoc Dali::DevelHandle::SetProperties()
+ */
+ void SetProperties( const Property::Map& properties );
+
+ /**
* @copydoc Dali::Handle::RegisterProperty(std::string name, Property::Value propertyValue, Property::AccessMode accessMode)
*/
Property::Index RegisterProperty( const std::string& name, const Property::Value& propertyValue, Property::AccessMode accessMode );