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/object/weak-handle.h>
26 #include <dali/public-api/actors/actor-enumerations.h>
27 #include <dali/public-api/animation/animation.h>
29 #include <dali-toolkit/devel-api/layouting/layout-item-impl.h>
30 #include <dali-toolkit/devel-api/layouting/layout-transition-data.h>
39 struct LayoutTransition
41 LayoutTransition( LayoutItem& layoutItem, int layoutTransitionType, Actor gainedChild, Actor lostChild )
42 : layoutItem( &layoutItem )
43 , layoutTransitionType( layoutTransitionType )
44 , gainedChild( gainedChild )
45 , lostChild( lostChild )
50 : layoutTransitionType( -1 )
54 bool operator==( const LayoutTransition& rhs )
56 return ( layoutItem.Get() == rhs.layoutItem.Get()
57 && layoutTransitionType == rhs.layoutTransitionType
58 && gainedChild == rhs.gainedChild
59 && lostChild == rhs.lostChild );
62 LayoutItemPtr layoutItem;
63 int layoutTransitionType;
64 WeakHandle<Actor> gainedChild;
65 WeakHandle<Actor> lostChild;
68 const float DEFAULT_TRANSITION_DURATION( 0.5f );
70 struct LayoutDataAnimator
73 : animatorType( Toolkit::LayoutTransitionData::Animator::ANIMATE_TO ),
74 alphaFunction( AlphaFunction::LINEAR ),
75 timePeriod( 0.0f, DEFAULT_TRANSITION_DURATION ),
76 interpolation( Animation::Linear )
81 Toolkit::LayoutTransitionData::Animator::Type animatorType;
82 AlphaFunction alphaFunction;
83 TimePeriod timePeriod;
86 Animation::Interpolation interpolation;
92 using LayoutAnimatorArray = std::vector< LayoutDataAnimator >;
94 struct LayoutPositionData
96 LayoutPositionData( Actor handle, float left, float top, float right, float bottom, bool animated ) :
97 handle( handle ), left( left ), top( top ), right( right ), bottom( bottom ), animated( animated ), updateWithCurrentSize(false)
101 WeakHandle<Actor> handle;
107 bool updateWithCurrentSize;
110 using LayoutPositionDataArray = std::vector< LayoutPositionData >;
112 struct LayoutDataElement
115 : propertyIndex( Property::INVALID_KEY ),
117 positionDataIndex(-1 ),
118 condition( Dali::Toolkit::LayoutTransitionData::Condition::NONE ),
119 updateMeasuredSize( false )
123 bool AdjustMeasuredSize( float& width, float& height, Toolkit::LayoutTransitionData::Animator::Type animatorType );
124 void UpdatePropertyIndex();
125 void UpdateAnimatorIndex( const LayoutAnimatorArray& animators );
126 void UpdatePositionDataIndex( LayoutData& layoutData );
128 WeakHandle<Actor> handle;
129 std::string propertyName;
130 Property::Index propertyIndex;
131 Property::Value initialValue;
132 Property::Value targetValue;
133 std::string animatorName;
135 int positionDataIndex;
137 bool updateMeasuredSize;
140 using LayoutDataArray = std::vector< LayoutDataElement >;
142 class LayoutTransitionData;
143 using LayoutTransitionDataPtr = IntrusivePtr<LayoutTransitionData>;
146 * LayoutTransitionData implementation class.
148 class DALI_TOOLKIT_API LayoutTransitionData : public BaseObject
151 struct PropertyAnimator
154 PropertyAnimator( Actor actor, Property::Map map );
155 PropertyAnimator( Actor actor, Property::Map map, Path path, Vector3 forward );
156 PropertyAnimator( Actor actor, Property::Map map, KeyFrames keyFrames, Animation::Interpolation interpolation );
158 WeakHandle<Actor> handle;
163 Animation::Interpolation interpolation;
168 using PropertyAnimatorArray = std::vector< PropertyAnimator >;
170 static LayoutTransitionDataPtr New();
172 LayoutTransitionData( const LayoutTransitionData& ) = delete;
173 LayoutTransitionData& operator=( const LayoutTransitionData& ) = delete;
176 * @brief Add a property animator for an actor in the transition
177 * @param[in] actor The actor
178 * @param[in] map The map containing the transition animator keys
180 * This will parse the property animator map and add the layout data element to the array of layout data elements related to this transition
182 void AddPropertyAnimator( Actor actor, Property::Map map );
185 * @brief Add a property animator for an actor in the transition
186 * @param[in] actor The actor
187 * @param[in] map The map containing the transition animator keys
188 * @param[in] keyFrames The key frames used by the property animator
189 * @param[in] interpolation The interpolation used by the property animator
191 * This will parse the property animator map and add the layout data element to the array of layout data elements related to this transition
193 void AddPropertyAnimator( Actor actor, Property::Map map, KeyFrames keyFrames, Animation::Interpolation interpolation );
196 * @brief Add a property animator for an actor in the transition
197 * @param[in] actor The actor
198 * @param[in] map The map containing the transition animator keys
199 * @param[in] path The path for the property animator
200 * @param[in] forward The forward vector for the property animator
202 * This will parse the property animator map and add the layout data element to the array of layout data elements related to this transition
204 void AddPropertyAnimator( Actor actor, Property::Map map, Path path, Vector3 forward );
207 * @brief Collect the transition layout data elements
208 * @param[in] actor The actor the transition property animators are applied to
209 * @param[in] layoutData The layout data containing layout data elements array for the layout update
211 * This will copy the transition layout data elements to the layout data elements array
213 void CollectLayoutDataElements( Actor, LayoutData& layoutData );
216 * @brief Collect the transition children layout data elements
217 * @param[in] actor The actor the transition property animators are applied to
218 * @param[in] layoutData The layout data containing layout data elements array for the layout update
220 * This will copy the children transition layout data elements to the layout data elements array
222 static void CollectChildrenLayoutDataElements( Actor, LayoutData& layoutData );
225 * @copydoc Dali::Toolkit::LayoutTransitionData::FinishedSignal()
227 Dali::Toolkit::LayoutTransitionData::LayoutTransitionSignalType& FinishedSignal();
230 * @brief Emit the transition finish signal
231 * @param[in] layoutTransitionType The transition type
233 void EmitSignalFinish( int layoutTransitionType );
236 * @brief Check if one of the layout data elements has updateMeasuredSize flag set
238 bool HasUpdateMeasuredSize();
242 * @brief Convert the property animator data to the layout data animator
243 * @param[in] animatorData The animator data map
244 * @param[in] propertyAnimator The property animator
245 * @param[in] layoutAnimator The layout animator
247 * This will parse the property animator map and add the layout data element animator to the layout animators array
249 bool ConvertToLayoutAnimator( const Property::Map& animatorData, const PropertyAnimator& propertyAnimator, LayoutDataAnimator& layoutAnimator );
252 * @brief Convert the property animator to the layout data element
253 * @param[in] propertyAnimator The property animator
254 * @param[in] layoutDataElement The layout data element
255 * @param[in] layoutDataElement The layout data
257 * This will parse the property animator map and add the layout data element to the layout data elements array
259 bool ConvertToLayoutDataElement( const PropertyAnimator& propertyAnimator, LayoutDataElement& layoutDataElement );
261 void UpdateAnimatorsIndices();
263 bool mUpdateMeasuredSize;
264 LayoutAnimatorArray mLayoutAnimators;
265 LayoutDataArray mLayoutDataElements;
268 * Ref counted object - Only allow construction via New().
270 LayoutTransitionData();
274 * A ref counted object may only be deleted by calling Unreference
276 virtual ~LayoutTransitionData();
278 Dali::Toolkit::LayoutTransitionData::LayoutTransitionSignalType mFinishedSignal;
281 using PropertyAnimatorArray = std::vector< LayoutTransitionData::PropertyAnimator >;
282 using LayoutTransitionDataArray = std::vector< LayoutTransitionDataPtr >;
283 using LayoutDataArray = std::vector< LayoutDataElement >;
287 LayoutData( LayoutTransition& layoutTransition, LayoutPositionDataArray& layoutPositionDataArray, LayoutAnimatorArray& layoutAnimatorArray,
288 LayoutDataArray& layoutDataArray, LayoutDataArray& childrenLayoutDataArray )
289 : speculativeLayout( false ),
290 updateMeasuredSize( false ),
291 layoutTransition( layoutTransition ),
292 layoutPositionDataArray( layoutPositionDataArray ),
293 layoutAnimatorArray( layoutAnimatorArray ),
294 layoutDataArray( layoutDataArray),
295 childrenLayoutDataArray( childrenLayoutDataArray )
299 bool speculativeLayout;
300 bool updateMeasuredSize;
301 LayoutTransition& layoutTransition;
302 LayoutPositionDataArray& layoutPositionDataArray;
303 LayoutAnimatorArray& layoutAnimatorArray;
304 LayoutDataArray& layoutDataArray;
305 LayoutDataArray& childrenLayoutDataArray;
308 } //namespace Internal
310 inline Internal::LayoutTransitionData& GetImplementation( Dali::Toolkit::LayoutTransitionData& handle )
312 DALI_ASSERT_ALWAYS( handle && "LayoutTransitionData handle is empty" );
313 BaseObject& object = handle.GetBaseObject();
314 return static_cast< Internal::LayoutTransitionData& >( object );
317 inline const Internal::LayoutTransitionData& GetImplementation( const Dali::Toolkit::LayoutTransitionData& handle )
319 DALI_ASSERT_ALWAYS( handle && "LayoutTransitionData handle is empty" );
320 const BaseObject& object = handle.GetBaseObject();
321 return static_cast< const Internal::LayoutTransitionData& >( object );
324 } //namespace Toolkit
327 #endif // DALI_TOOLKIT_INTERNAL_LAYOUTING_LAYOUT_TRANSITION_DATA_IMPL_H