Animate Text Color of TextLabel 08/141208/1
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Fri, 28 Jul 2017 13:19:08 +0000 (14:19 +0100)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Fri, 28 Jul 2017 13:19:34 +0000 (14:19 +0100)
Change-Id: If1cf3c6bd484f9b2ce64b0fba79dbef0c23cb9fb

examples/text-label/text-label-example.cpp

index 85c51eb..d7c7315 100644 (file)
@@ -22,6 +22,7 @@
 
 // EXTERNAL INCLUDES
 #include <dali/devel-api/object/handle-devel.h>
+#include <dali-toolkit/devel-api/controls/text-controls/text-label-devel.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <iostream>
 
@@ -39,6 +40,7 @@ const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "grab-handle.png";
 
 const unsigned int KEY_ZERO = 10;
 const unsigned int KEY_ONE = 11;
+const unsigned int KEY_A = 38;
 const unsigned int KEY_F = 41;
 const unsigned int KEY_H = 43;
 const unsigned int KEY_V = 55;
@@ -163,7 +165,7 @@ public:
     mLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
     mLabel.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::HEIGHT );
     mLabel.SetProperty( TextLabel::Property::MULTI_LINE, true );
-    mLabel.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
+    mLabel.SetProperty( DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE, Color::BLUE );
     mLabel.SetProperty( TextLabel::Property::SHADOW_OFFSET, Vector2( 1.0f, 1.0f ) );
     mLabel.SetProperty( TextLabel::Property::SHADOW_COLOR, Color::BLACK );
     mLabel.SetBackgroundColor( Color::WHITE );
@@ -183,6 +185,12 @@ public:
     anim.SetLooping(true);
     anim.Play();
 
+    // Animate the text color 3 times from source color to RED
+    Animation animation = Animation::New( 2.f );
+    animation.AnimateTo( Property( mLabel, DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE ), Color::RED, AlphaFunction::SIN );
+    animation.SetLoopCount( 3 );
+    animation.Play();
+
     Property::Value labelText = mLabel.GetProperty( TextLabel::Property::TEXT );
     std::cout << "Displaying text: \"" << labelText.Get< std::string >() << "\"" << std::endl;
   }
@@ -240,6 +248,14 @@ public:
             mLabel.SetProperty( TextLabel::Property::RENDERING_BACKEND, event.keyCode - 10 );
             break;
           }
+          case KEY_A: // Animate text colour
+          {
+            Animation animation = Animation::New( 2.f );
+            animation.AnimateTo( Property( mLabel, DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE ), Color::RED, AlphaFunction::SIN );
+            animation.SetLooping( true );
+            animation.Play();
+            break;
+          }
           case KEY_F: // Fill vertically
           {
             if( ResizePolicy::DIMENSION_DEPENDENCY == mLabel.GetResizePolicy(Dimension::HEIGHT) )