Commit de6b0a2995ed488bfe07274b95d17099e1e52c7f

Authored by Anton Obzhirov
1 parent 0d9cb8e0

Add update measured size for focus animation.

Change-Id: Ief3b7b310e90e6fb11587aa64f6f2615d9613c79
examples/layouting/animation-example.cpp
... ... @@ -17,6 +17,7 @@
17 17  
18 18 #include <string>
19 19 #include "animation-example.h"
  20 +#include <dali/devel-api/actors/actor-devel.h>
20 21 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
21 22 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
22 23 #include <dali-toolkit/devel-api/controls/control-devel.h>
... ... @@ -65,15 +66,17 @@ void CreateChild( ImageView&amp; child, int index, Size size )
65 66 {
66 67 child = ImageView::New();
67 68 Property::Map imagePropertyMap;
68   - imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
69   - imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = IMAGE_PATH[ index ];
  69 + imagePropertyMap[ Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
  70 + imagePropertyMap[ ImageVisual::Property::URL ] = IMAGE_PATH[ index ];
70 71 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = size.width;
71 72 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = size.height;
  73 + imagePropertyMap[ ImageVisual::Property::FITTING_MODE ] = FittingMode::SCALE_TO_FILL;
72 74 child.SetProperty( Toolkit::ImageView::Property::IMAGE, imagePropertyMap );
73 75 std::string name = "ImageView";
74 76 name.append( 1, '0' + index );
75 77 child.SetName( name );
76   - child.SetAnchorPoint( AnchorPoint::TOP_LEFT );
  78 + child.SetAnchorPoint( AnchorPoint::CENTER );
  79 + child.SetProperty( DevelActor::Property::POSITION_USES_ANCHOR_POINT, false );
77 80 }
78 81  
79 82 // Create set layout transition. A parent opacity increases 'ease in out' from semi-transparent to fully opaque and children pulse in order
... ... @@ -93,6 +96,19 @@ LayoutTransitionData CreateOnSetLayoutTransition( Control&amp; container )
93 96 // Apply to parent only
94 97 layoutTransitionData.AddPropertyAnimator( container, map );
95 98  
  99 + // Reset scale after possible focus animation
  100 + {
  101 + Property::Map map;
  102 + map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::SCALE;
  103 + map[ LayoutTransitionData::AnimatorKey::TARGET_VALUE ] = Vector3::ONE;
  104 + map[ LayoutTransitionData::AnimatorKey::ANIMATOR ] = Property::Map()
  105 + .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
  106 + .Add( LayoutTransitionData::AnimatorKey::DELAY, 0.0f)
  107 + .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.0f));
  108 + layoutTransitionData.AddPropertyAnimator( Actor(), map );
  109 + }
  110 +
  111 + // Children pulses in/out
96 112 for( size_t i = 0; i < container.GetChildCount(); i++ )
97 113 {
98 114 Property::Map map;
... ... @@ -106,6 +122,18 @@ LayoutTransitionData CreateOnSetLayoutTransition( Control&amp; container )
106 122 layoutTransitionData.AddPropertyAnimator( container.GetChildAt( i ), map );
107 123 }
108 124  
  125 + // Children move
  126 + {
  127 + Property::Map map;
  128 + map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::POSITION;
  129 + map[ LayoutTransitionData::AnimatorKey::ANIMATOR ] = Property::Map()
  130 + .Add( LayoutTransitionData::AnimatorKey::ALPHA_FUNCTION, AlphaFunction::LINEAR )
  131 + .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
  132 + .Add( LayoutTransitionData::AnimatorKey::DELAY, 0.0f )
  133 + .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.5f ) );
  134 + layoutTransitionData.AddPropertyAnimator( Actor(), map );
  135 + }
  136 +
109 137 return layoutTransitionData;
110 138 }
111 139  
... ... @@ -124,13 +152,25 @@ LayoutTransitionData CreateOnChildAddTransition( Control&amp; parent )
124 152 .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.0f ) );
125 153 layoutTransitionData.AddPropertyAnimator( parent, map );
126 154  
  155 + // Reset scale after possible focus animation
  156 + {
  157 + Property::Map map;
  158 + map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::SCALE;
  159 + map[ LayoutTransitionData::AnimatorKey::TARGET_VALUE ] = Vector3::ONE;
  160 + map[ LayoutTransitionData::AnimatorKey::ANIMATOR ] = Property::Map()
  161 + .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
  162 + .Add( LayoutTransitionData::AnimatorKey::DELAY, 0.0f)
  163 + .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.5f));
  164 + layoutTransitionData.AddPropertyAnimator( Actor(), map );
  165 + }
  166 +
127 167 // New child is growing
128 168 {
129 169 Property::Map map;
130 170 map[ LayoutTransitionData::AnimatorKey::CONDITION ] = LayoutTransitionData::Condition::ON_ADD;
131   - map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::SIZE;
132   - map[ LayoutTransitionData::AnimatorKey::INITIAL_VALUE ] = Vector3( 0.0f, 0.0f, 0 );
133   - map[ LayoutTransitionData::AnimatorKey::TARGET_VALUE ] = Vector3( 100.0f, 100.0f, 0 );
  171 + map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::SCALE;
  172 + map[ LayoutTransitionData::AnimatorKey::INITIAL_VALUE ] = Vector3::ZERO;
  173 + map[ LayoutTransitionData::AnimatorKey::TARGET_VALUE ] = Vector3::ONE;
134 174 map[ LayoutTransitionData::AnimatorKey::ANIMATOR ] = Property::Map()
135 175 .Add( LayoutTransitionData::AnimatorKey::ALPHA_FUNCTION, AlphaFunction::LINEAR )
136 176 .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
... ... @@ -152,6 +192,18 @@ LayoutTransitionData CreateOnChildAddTransition( Control&amp; parent )
152 192 layoutTransitionData.AddPropertyAnimator( Actor(), map );
153 193 }
154 194  
  195 + // Other just move
  196 + {
  197 + Property::Map map;
  198 + map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::POSITION;
  199 + map[ LayoutTransitionData::AnimatorKey::ANIMATOR ] = Property::Map()
  200 + .Add( LayoutTransitionData::AnimatorKey::ALPHA_FUNCTION, AlphaFunction::LINEAR )
  201 + .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
  202 + .Add( LayoutTransitionData::AnimatorKey::DELAY, 0.0f )
  203 + .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.5f ) );
  204 + layoutTransitionData.AddPropertyAnimator( Actor(), map );
  205 + }
  206 +
155 207 return layoutTransitionData;
156 208 }
157 209  
... ... @@ -160,56 +212,112 @@ LayoutTransitionData CreateOnChildRemoveTransition( Control&amp; container )
160 212 {
161 213 auto layoutTransitionData = LayoutTransitionData::New();
162 214  
163   - // Apply animation to remaining children
164   - Property::Map map;
165   - map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::POSITION;
166   - map[ LayoutTransitionData::AnimatorKey::ANIMATOR ] = Property::Map()
167   - .Add( LayoutTransitionData::AnimatorKey::ALPHA_FUNCTION, AlphaFunction::SIN )
168   - .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
169   - .Add( LayoutTransitionData::AnimatorKey::DELAY, 0.0f)
170   - .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.5f));
171   - layoutTransitionData.AddPropertyAnimator( Actor(), map );
  215 + // Reset scale after possible focus animation
  216 + {
  217 + Property::Map map;
  218 + map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::SCALE;
  219 + map[ LayoutTransitionData::AnimatorKey::TARGET_VALUE ] = Vector3::ONE;
  220 + map[ LayoutTransitionData::AnimatorKey::ANIMATOR ] = Property::Map()
  221 + .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
  222 + .Add( LayoutTransitionData::AnimatorKey::DELAY, 0.0f)
  223 + .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.0f));
  224 + layoutTransitionData.AddPropertyAnimator( Actor(), map );
  225 + }
  226 +
  227 + // Apply animation to remaining children - sin shaking
  228 + {
  229 + Property::Map map;
  230 + map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::POSITION;
  231 + map[ LayoutTransitionData::AnimatorKey::ANIMATOR ] = Property::Map()
  232 + .Add( LayoutTransitionData::AnimatorKey::ALPHA_FUNCTION, AlphaFunction::SIN )
  233 + .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
  234 + .Add( LayoutTransitionData::AnimatorKey::DELAY, 0.0f)
  235 + .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.5f));
  236 + layoutTransitionData.AddPropertyAnimator( Actor(), map );
  237 + }
  238 +
  239 + // Add a linear to reduce a linear to half
  240 + {
  241 + Property::Map map;
  242 + map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::POSITION;
  243 + map[ LayoutTransitionData::AnimatorKey::ANIMATOR ] = Property::Map()
  244 + .Add( LayoutTransitionData::AnimatorKey::ALPHA_FUNCTION, AlphaFunction::LINEAR )
  245 + .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
  246 + .Add( LayoutTransitionData::AnimatorKey::DELAY, 0.0f)
  247 + .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.5f));
  248 + layoutTransitionData.AddPropertyAnimator( Actor(), map );
  249 + }
172 250  
173 251 return layoutTransitionData;
174 252 }
175 253  
176   -// Create child focus transition. A focus gained child grows 115% and focus lost child gets its original size back
177   -LayoutTransitionData CreateOnChildFocusTransition( Control& parent )
  254 +// Create child focus transition. A focus gained child grows 120% and focus lost child gets its original size back
  255 +LayoutTransitionData CreateOnChildFocusTransition( Control& parent, bool affectsSiblings )
178 256 {
179 257 auto layoutTransitionData = LayoutTransitionData::New();
180 258  
  259 + // Focus gain child animation
181 260 {
182 261 Property::Map map;
183 262 map[ LayoutTransitionData::AnimatorKey::CONDITION ] = LayoutTransitionData::Condition::ON_FOCUS_GAINED;
184   - map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::SIZE;
185   - map[ LayoutTransitionData::AnimatorKey::TARGET_VALUE ] = Vector3( 115.0f, 115.0f, 0 );
  263 + map[ LayoutTransitionData::AnimatorKey::AFFECTS_SIBLINGS ] = affectsSiblings;
  264 + map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::SCALE;
  265 + map[ LayoutTransitionData::AnimatorKey::TARGET_VALUE ] = Vector3( 1.2f, 1.2f, 1.0f );
186 266 map[ LayoutTransitionData::AnimatorKey::ANIMATOR ] = Property::Map()
  267 + .Add( LayoutTransitionData::AnimatorKey::TYPE, LayoutTransitionData::Animator::ANIMATE_TO )
187 268 .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
188 269 .Add( LayoutTransitionData::AnimatorKey::DELAY, 0.0f )
189 270 .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.5f ) );
190 271 layoutTransitionData.AddPropertyAnimator( Actor(), map );
191 272 }
192 273  
  274 + // Focus lost child animation
193 275 {
194 276 Property::Map map;
195 277 map[ LayoutTransitionData::AnimatorKey::CONDITION ] = LayoutTransitionData::Condition::ON_FOCUS_LOST;
196   - map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::SIZE;
197   - map[ LayoutTransitionData::AnimatorKey::TARGET_VALUE ] = Vector3( 100.0f, 100.0f, 0 );
  278 + map[ LayoutTransitionData::AnimatorKey::AFFECTS_SIBLINGS ] = affectsSiblings;
  279 + map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::SCALE;
  280 + map[ LayoutTransitionData::AnimatorKey::TARGET_VALUE ] = Vector3( 1.0f, 1.0f, 1.0f );
198 281 map[ LayoutTransitionData::AnimatorKey::ANIMATOR ] = Property::Map()
  282 + .Add( LayoutTransitionData::AnimatorKey::TYPE, LayoutTransitionData::Animator::ANIMATE_TO )
199 283 .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
200 284 .Add( LayoutTransitionData::AnimatorKey::DELAY, 0.0f )
201 285 .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.5f ) );
202 286 layoutTransitionData.AddPropertyAnimator( Actor(), map );
203 287 }
204 288  
  289 + // Linear children positioning
  290 + {
  291 + Property::Map map;
  292 + map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::POSITION;
  293 + map[ LayoutTransitionData::AnimatorKey::TARGET_VALUE ] = Property::Value();
  294 + map[ LayoutTransitionData::AnimatorKey::ANIMATOR ] = Property::Map()
  295 + .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
  296 + .Add( LayoutTransitionData::AnimatorKey::DELAY, 0.0f )
  297 + .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.5f ) );
  298 + layoutTransitionData.AddPropertyAnimator( Actor(), map );
  299 + }
  300 +
205 301 return layoutTransitionData;
206 302 }
207 303  
208 304 // An example of custom default transition, ease in for position animation, ease out for size animation
209   -LayoutTransitionData CreateCustomDefaultTransition( Control& parent )
  305 +LayoutTransitionData CreateCustomDefaultTransition( Control& control )
210 306 {
211 307 auto layoutTransitionData = LayoutTransitionData::New();
  308 + // Resets control scale after possible focus animation
  309 + {
  310 + Property::Map map;
  311 + map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::SCALE;
  312 + map[ LayoutTransitionData::AnimatorKey::TARGET_VALUE ] = Vector3::ONE;
  313 + map[ LayoutTransitionData::AnimatorKey::ANIMATOR ] = Property::Map()
  314 + .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
  315 + .Add( LayoutTransitionData::AnimatorKey::DELAY, 0.0f )
  316 + .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.0f ) );
  317 + layoutTransitionData.AddPropertyAnimator( control, map );
  318 + }
212 319  
  320 + // Moves control ease in
213 321 {
214 322 Property::Map map;
215 323 map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::POSITION;
... ... @@ -218,9 +326,10 @@ LayoutTransitionData CreateCustomDefaultTransition( Control&amp; parent )
218 326 .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
219 327 .Add( LayoutTransitionData::AnimatorKey::DELAY, 0.0f )
220 328 .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.5f ) );
221   - layoutTransitionData.AddPropertyAnimator( parent, map );
  329 + layoutTransitionData.AddPropertyAnimator( control, map );
222 330 }
223 331  
  332 + // Sizes control ease out
224 333 {
225 334 Property::Map map;
226 335 map[ LayoutTransitionData::AnimatorKey::PROPERTY ] = Actor::Property::SIZE;
... ... @@ -229,7 +338,7 @@ LayoutTransitionData CreateCustomDefaultTransition( Control&amp; parent )
229 338 .Add( LayoutTransitionData::AnimatorKey::TIME_PERIOD, Property::Map()
230 339 .Add( LayoutTransitionData::AnimatorKey::DELAY, 0.0f )
231 340 .Add( LayoutTransitionData::AnimatorKey::DURATION, 0.5f ) );
232   - layoutTransitionData.AddPropertyAnimator( parent, map );
  341 + layoutTransitionData.AddPropertyAnimator( control, map );
233 342 }
234 343  
235 344 return layoutTransitionData;
... ... @@ -318,16 +427,16 @@ void AnimationExample::Create()
318 427 mHorizontalLayout.SetOrientation( LinearLayout::Orientation::HORIZONTAL );
319 428 mHorizontalLayout.SetAlignment( LinearLayout::Alignment::CENTER_HORIZONTAL | LinearLayout::Alignment::CENTER_VERTICAL );
320 429 mHorizontalLayout.SetAnimateLayout(true);
321   - mHorizontalLayout.SetTransitionData( LayoutTransitionData::ON_CHILD_FOCUS, CreateOnChildFocusTransition( mAnimationContainer ) );
  430 + mHorizontalLayout.SetTransitionData( LayoutTransitionData::ON_CHILD_FOCUS, CreateOnChildFocusTransition( mAnimationContainer, true ) );
322 431 mHorizontalLayout.SetTransitionData( LayoutTransitionData::ON_CHILD_REMOVE, CreateOnChildRemoveTransition( mAnimationContainer ) );
323 432 mHorizontalLayout.SetTransitionData( LayoutTransitionData::ON_CHILD_ADD, CreateOnChildAddTransition( mAnimationContainer ) );
324 433  
325 434 DevelControl::SetLayout( mAnimationContainer, mHorizontalLayout );
326 435  
327 436 mGridLayout = Grid::New();
328   - mGridLayout.SetAnimateLayout(true);
329   - mGridLayout.SetNumberOfColumns(2);
330   - mGridLayout.SetTransitionData( LayoutTransitionData::ON_CHILD_FOCUS, CreateOnChildFocusTransition( mAnimationContainer ) );
  437 + mGridLayout.SetAnimateLayout( true );
  438 + mGridLayout.SetNumberOfColumns( 2 );
  439 + mGridLayout.SetTransitionData( LayoutTransitionData::ON_CHILD_FOCUS, CreateOnChildFocusTransition( mAnimationContainer, false ) );
331 440 mGridLayout.SetTransitionData( LayoutTransitionData::ON_CHILD_REMOVE, CreateOnChildRemoveTransition( mAnimationContainer ) );
332 441 mGridLayout.SetTransitionData( LayoutTransitionData::ON_CHILD_ADD, CreateOnChildAddTransition( mAnimationContainer ) );
333 442  
... ... @@ -335,8 +444,7 @@ void AnimationExample::Create()
335 444 stage.Add( mAnimationContainer );
336 445 }
337 446  
338   -// Remove controls added by this example from stage mGridLayout.SetTransitionData( LayoutTransitionData::ON_CHILD_FOCUS, CreateOnChildFocusTransition( mAnimationContainer ) );
339   -
  447 +// Remove controls added by this example from stage
340 448 void AnimationExample::Remove()
341 449 {
342 450 if ( mAnimationContainer )
... ...