Minor text demo tweaks 61/35961/2
authorPaul Wisbey <p.wisbey@samsung.com>
Thu, 26 Feb 2015 13:52:36 +0000 (13:52 +0000)
committerPaul Wisbey <p.wisbey@samsung.com>
Thu, 26 Feb 2015 13:54:03 +0000 (13:54 +0000)
     - Respond to back key
     - Start multi-language text at the top
     - Scroll to integer positions only

Change-Id: I7595e86ea31f6531683fb4589db009637222ab85

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

index 0cea836..a557927 100644 (file)
@@ -53,6 +53,8 @@ public:
   {
     Stage stage = Stage::GetCurrent();
 
+    stage.KeyEventSignal().Connect(this, &TextLabelExample::OnKeyEvent);
+
     TextLabel label = TextLabel::New();
     label.SetParentOrigin( ParentOrigin::CENTER );
     stage.Add( label );
@@ -66,6 +68,20 @@ public:
     //std::cout << "Got text from label: " << labelText.Get< std::string >() << std::endl;
   }
 
+  /**
+   * Main key event handler
+   */
+  void OnKeyEvent(const KeyEvent& event)
+  {
+    if(event.state == KeyEvent::Down)
+    {
+      if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
+      {
+        mApplication.Quit();
+      }
+    }
+  }
+
 private:
 
   Application& mApplication;
index da2d9b2..080251f 100644 (file)
@@ -227,8 +227,11 @@ public:
   {
     Stage stage = Stage::GetCurrent();
 
+    stage.KeyEventSignal().Connect(this, &TextLabelMultiLanguageExample::OnKeyEvent);
+
     mLayout = VerticalLayout::New();
-    mLayout.SetParentOrigin( ParentOrigin::CENTER );
+    mLayout.SetParentOrigin( ParentOrigin::TOP_LEFT );
+    mLayout.SetAnchorPoint( AnchorPoint::TOP_LEFT );
 
     stage.Add( mLayout );
 
@@ -259,17 +262,19 @@ public:
     if( 1u == event.GetPointCount() )
     {
       const TouchPoint::State state = event.GetPoint(0u).state;
+
+      // Clamp to integer values; this is to reduce flicking due to pixel misalignment
+      const float localPoint = static_cast<float>( static_cast<int>( event.GetPoint( 0 ).local.y ) );
+
       if( TouchPoint::Down == state )
       {
-        mLastPoint = event.GetPoint( 0 ).local.y;
+        mLastPoint = localPoint;
         mAnimation = Animation::New( 0.25f );
-        mAnimation.FinishedSignal().Connect( this, &TextLabelMultiLanguageExample::AnimationCompleted );
       }
       else if( TouchPoint::Motion == state )
       {
         if( mAnimation )
         {
-          const float localPoint = event.GetPoint( 0 ).local.y;
           mAnimation.MoveBy( mLayout, Vector3( 0.f, localPoint - mLastPoint, 0.f ), AlphaFunctions::Linear );
           mAnimation.Play();
           mLastPoint = localPoint;
@@ -280,9 +285,18 @@ public:
     return true;
   }
 
-  void AnimationCompleted(Animation& source)
+  /**
+   * Main key event handler
+   */
+  void OnKeyEvent(const KeyEvent& event)
   {
-    //mAnimation.Reset();
+    if(event.state == KeyEvent::Down)
+    {
+      if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
+      {
+        mApplication.Quit();
+      }
+    }
   }
 
 private: