1 #ifndef DALI_TOOLKIT_INTERNAL_LAYOUTING_LAYOUT_TRANSITION_DATA_IMPL_H
2 #define DALI_TOOLKIT_INTERNAL_LAYOUTING_LAYOUT_TRANSITION_DATA_IMPL_H
4 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <dali/public-api/common/intrusive-ptr.h>
22 #include <dali/public-api/object/base-object.h>
23 #include <dali/public-api/object/property-map.h>
24 #include <dali/public-api/object/type-registry.h>
25 #include <dali/public-api/actors/actor-enumerations.h>
26 #include <dali/public-api/animation/animation.h>
28 #include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
29 #include <dali-toolkit/devel-api/layouting/layout-transition-data.h>
38 struct LayoutTransition
40 LayoutTransition( LayoutItem& layoutItem, int layoutTransitionType, Actor gainedChild, Actor lostChild )
41 : layoutItem( &layoutItem )
42 , layoutTransitionType( layoutTransitionType )
43 , gainedChild( gainedChild )
44 , lostChild( lostChild )
49 : layoutTransitionType( -1 )
53 bool operator==( const LayoutTransition& rhs )
55 return ( layoutItem.Get() == rhs.layoutItem.Get()
56 && layoutTransitionType == rhs.layoutTransitionType
57 && gainedChild == rhs.gainedChild
58 && lostChild == rhs.lostChild );
61 LayoutItemPtr layoutItem;
62 int layoutTransitionType;
67 const float DEFAULT_TRANSITION_DURATION( 0.5f );
69 struct LayoutDataAnimator
72 : animatorType( Toolkit::LayoutTransitionData::Animator::ANIMATE_TO ),
73 alphaFunction( AlphaFunction::LINEAR ),
74 timePeriod( 0.0f, DEFAULT_TRANSITION_DURATION ),
75 interpolation( Animation::Linear )
80 Toolkit::LayoutTransitionData::Animator::Type animatorType;
81 AlphaFunction alphaFunction;
82 TimePeriod timePeriod;
85 Animation::Interpolation interpolation;
91 using LayoutAnimatorArray = std::vector< LayoutDataAnimator >;
93 struct LayoutPositionData
95 LayoutPositionData( Handle handle, float left, float top, float right, float bottom, bool animated ) :
96 handle( handle ), left( left ), top( top ), right( right ), bottom( bottom ), animated( animated ), updateWithCurrentSize(false)
106 bool updateWithCurrentSize;
109 using LayoutPositionDataArray = std::vector< LayoutPositionData >;
111 struct LayoutDataElement
114 : propertyIndex( Property::INVALID_KEY ),
116 positionDataIndex(-1 ),
117 condition( Dali::Toolkit::LayoutTransitionData::Condition::NONE ),
118 updateMeasuredSize( false )
122 bool AdjustMeasuredSize( float& width, float& height, Toolkit::LayoutTransitionData::Animator::Type animatorType );
123 void UpdatePropertyIndex();
124 void UpdateAnimatorIndex( const LayoutAnimatorArray& animators );
125 void UpdatePositionDataIndex( LayoutData& layoutData );
128 std::string propertyName;
129 Property::Index propertyIndex;
130 Property::Value initialValue;
131 Property::Value targetValue;
132 std::string animatorName;
134 int positionDataIndex;
136 bool updateMeasuredSize;
139 using LayoutDataArray = std::vector< LayoutDataElement >;
141 class LayoutTransitionData;
142 using LayoutTransitionDataPtr = IntrusivePtr<LayoutTransitionData>;
145 * LayoutTransitionData implementation class.
147 class DALI_TOOLKIT_API LayoutTransitionData : public BaseObject
150 struct PropertyAnimator
153 PropertyAnimator( Actor actor, Property::Map map );
154 PropertyAnimator( Actor actor, Property::Map map, Path path, Vector3 forward );
155 PropertyAnimator( Actor actor, Property::Map map, KeyFrames keyFrames, Animation::Interpolation interpolation );
162 Animation::Interpolation interpolation;
167 using PropertyAnimatorArray = std::vector< PropertyAnimator >;
169 static LayoutTransitionDataPtr New();
171 LayoutTransitionData( const LayoutTransitionData& ) = delete;
172 LayoutTransitionData& operator=( const LayoutTransitionData& ) = delete;
175 * @brief Add a property animator for an actor in the transition
176 * @param[in] actor The actor
177 * @param[in] map The map containing the transition animator keys
179 * This will parse the property animator map and add the layout data element to the array of layout data elements related to this transition
181 void AddPropertyAnimator( Actor actor, Property::Map map );
184 * @brief Add a property animator for an actor in the transition
185 * @param[in] actor The actor
186 * @param[in] map The map containing the transition animator keys
187 * @param[in] keyFrames The key frames used by the property animator
188 * @param[in] interpolation The interpolation used by the property animator
190 * This will parse the property animator map and add the layout data element to the array of layout data elements related to this transition
192 void AddPropertyAnimator( Actor actor, Property::Map map, KeyFrames keyFrames, Animation::Interpolation interpolation );
195 * @brief Add a property animator for an actor in the transition
196 * @param[in] actor The actor
197 * @param[in] map The map containing the transition animator keys
198 * @param[in] path The path for the property animator
199 * @param[in] forward The forward vector for the property animator
201 * This will parse the property animator map and add the layout data element to the array of layout data elements related to this transition
203 void AddPropertyAnimator( Actor actor, Property::Map map, Path path, Vector3 forward );
206 * @brief Collect the transition layout data elements
207 * @param[in] actor The actor the transition property animators are applied to
208 * @param[in] layoutData The layout data containing layout data elements array for the layout update
210 * This will copy the transition layout data elements to the layout data elements array
212 void CollectLayoutDataElements( Actor, LayoutData& layoutData );
215 * @brief Collect the transition children layout data elements
216 * @param[in] actor The actor the transition property animators are applied to
217 * @param[in] layoutData The layout data containing layout data elements array for the layout update
219 * This will copy the children transition layout data elements to the layout data elements array
221 static void CollectChildrenLayoutDataElements( Actor, LayoutData& layoutData );
224 * @copydoc Dali::Toolkit::LayoutTransitionData::FinishedSignal()
226 Dali::Toolkit::LayoutTransitionData::LayoutTransitionSignalType& FinishedSignal();
229 * @brief Emit the transition finish signal
230 * @param[in] layoutTransitionType The transition type
232 void EmitSignalFinish( int layoutTransitionType );
235 * @brief Check if one of the layout data elements has updateMeasuredSize flag set
237 bool HasUpdateMeasuredSize();
241 * @brief Convert the property animator data to the layout data animator
242 * @param[in] animatorData The animator data map
243 * @param[in] propertyAnimator The property animator
244 * @param[in] layoutAnimator The layout animator
246 * This will parse the property animator map and add the layout data element animator to the layout animators array
248 bool ConvertToLayoutAnimator( const Property::Map& animatorData, const PropertyAnimator& propertyAnimator, LayoutDataAnimator& layoutAnimator );
251 * @brief Convert the property animator to the layout data element
252 * @param[in] propertyAnimator The property animator
253 * @param[in] layoutDataElement The layout data element
254 * @param[in] layoutDataElement The layout data
256 * This will parse the property animator map and add the layout data element to the layout data elements array
258 bool ConvertToLayoutDataElement( const PropertyAnimator& propertyAnimator, LayoutDataElement& layoutDataElement );
260 void UpdateAnimatorsIndices();
262 bool mUpdateMeasuredSize;
263 LayoutAnimatorArray mLayoutAnimators;
264 LayoutDataArray mLayoutDataElements;
267 * Ref counted object - Only allow construction via New().
269 LayoutTransitionData();
273 * A ref counted object may only be deleted by calling Unreference
275 virtual ~LayoutTransitionData();
277 Dali::Toolkit::LayoutTransitionData::LayoutTransitionSignalType mFinishedSignal;
280 using PropertyAnimatorArray = std::vector< LayoutTransitionData::PropertyAnimator >;
281 using LayoutTransitionDataArray = std::vector< LayoutTransitionDataPtr >;
282 using LayoutDataArray = std::vector< LayoutDataElement >;
286 LayoutData( LayoutTransition& layoutTransition, LayoutPositionDataArray& layoutPositionDataArray, LayoutAnimatorArray& layoutAnimatorArray,
287 LayoutDataArray& layoutDataArray, LayoutDataArray& childrenLayoutDataArray )
288 : speculativeLayout( false ),
289 updateMeasuredSize( false ),
290 layoutTransition( layoutTransition ),
291 layoutPositionDataArray( layoutPositionDataArray ),
292 layoutAnimatorArray( layoutAnimatorArray ),
293 layoutDataArray( layoutDataArray),
294 childrenLayoutDataArray( childrenLayoutDataArray )
298 bool speculativeLayout;
299 bool updateMeasuredSize;
300 LayoutTransition& layoutTransition;
301 LayoutPositionDataArray& layoutPositionDataArray;
302 LayoutAnimatorArray& layoutAnimatorArray;
303 LayoutDataArray& layoutDataArray;
304 LayoutDataArray& childrenLayoutDataArray;
307 } //namespace Internal
309 inline Internal::LayoutTransitionData& GetImplementation( Dali::Toolkit::LayoutTransitionData& handle )
311 DALI_ASSERT_ALWAYS( handle && "LayoutTransitionData handle is empty" );
312 BaseObject& object = handle.GetBaseObject();
313 return static_cast< Internal::LayoutTransitionData& >( object );
316 inline const Internal::LayoutTransitionData& GetImplementation( const Dali::Toolkit::LayoutTransitionData& handle )
318 DALI_ASSERT_ALWAYS( handle && "LayoutTransitionData handle is empty" );
319 const BaseObject& object = handle.GetBaseObject();
320 return static_cast< const Internal::LayoutTransitionData& >( object );
323 } //namespace Toolkit
326 #endif // DALI_TOOLKIT_INTERNAL_LAYOUTING_LAYOUT_TRANSITION_DATA_IMPL_H