Fix for text alignmnet and scrolling.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-label-impl.cpp
index fdce0ed..efcecbf 100644 (file)
 // EXTERNAL INCLUDES
 #include <dali/public-api/object/type-registry.h>
 #include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/scripting/scripting.h>
 #include <dali/integration-api/debug.h>
 
 // INTERNAL INCLUDES
+#include <dali-toolkit/public-api/text/rendering-backend.h>
 #include <dali-toolkit/internal/text/layouts/layout-engine.h>
 #include <dali-toolkit/internal/text/rendering/text-backend.h>
-#include <dali-toolkit/public-api/text/rendering-backend.h>
+#include <dali-toolkit/internal/styling/style-manager-impl.h>
 
 using Dali::Toolkit::Text::LayoutEngine;
 using Dali::Toolkit::Text::Backend;
@@ -48,6 +50,14 @@ namespace
 namespace
 {
 
+const Scripting::StringEnum< Toolkit::Text::LayoutEngine::Alignment > ALIGNMENT_STRING_TABLE[] =
+{
+  { "BEGIN",  Toolkit::Text::LayoutEngine::ALIGN_BEGIN  },
+  { "CENTER", Toolkit::Text::LayoutEngine::ALIGN_CENTER },
+  { "END",    Toolkit::Text::LayoutEngine::ALIGN_END    },
+};
+const unsigned int ALIGNMENT_STRING_TABLE_COUNT = sizeof( ALIGNMENT_STRING_TABLE ) / sizeof( ALIGNMENT_STRING_TABLE[0] );
+
 // Type registration
 BaseHandle Create()
 {
@@ -63,6 +73,7 @@ DALI_PROPERTY_REGISTRATION( TextLabel, "font-family",       STRING,  FONT_FAMILY
 DALI_PROPERTY_REGISTRATION( TextLabel, "font-style",        STRING,  FONT_STYLE        )
 DALI_PROPERTY_REGISTRATION( TextLabel, "point-size",        FLOAT,   POINT_SIZE        )
 DALI_PROPERTY_REGISTRATION( TextLabel, "multi-line",        BOOLEAN, MULTI_LINE        )
+DALI_PROPERTY_REGISTRATION( TextLabel, "alignment",         STRING,  ALIGNMENT         )
 
 DALI_TYPE_REGISTRATION_END()
 
@@ -164,12 +175,26 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr
 
           if( engine.GetLayout() != layout )
           {
-            impl.mController->GetLayoutEngine().SetLayout( layout );
+            engine.SetLayout( layout );
             impl.RequestTextRelayout();
           }
         }
         break;
       }
+      case Toolkit::TextLabel::Property::ALIGNMENT:
+      {
+        LayoutEngine& engine = impl.mController->GetLayoutEngine();
+        const LayoutEngine::Alignment alignment = Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::Alignment >( value.Get< std::string >().c_str(),
+                                                                                                                       ALIGNMENT_STRING_TABLE,
+                                                                                                                       ALIGNMENT_STRING_TABLE_COUNT );
+
+        if( engine.GetAlignment() != alignment )
+        {
+          engine.SetAlignment( alignment );
+          impl.RequestTextRelayout();
+        }
+        break;
+      }
     }
   }
 }
@@ -208,6 +233,16 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde
         }
         break;
       }
+      case Toolkit::TextLabel::Property::ALIGNMENT:
+      {
+        if( impl.mController )
+        {
+          value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::Alignment >( impl.mController->GetLayoutEngine().GetAlignment(),
+                                                                                                        ALIGNMENT_STRING_TABLE,
+                                                                                                        ALIGNMENT_STRING_TABLE_COUNT ) );
+        }
+        break;
+      }
     }
   }
 
@@ -219,6 +254,11 @@ void TextLabel::OnInitialize()
   mController = Text::Controller::New( *this );
 }
 
+void TextLabel::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
+{
+  GetImpl( styleManager ).ApplyThemeStyle( Toolkit::Control( GetOwner() ) );
+}
+
 Vector3 TextLabel::GetNaturalSize()
 {
   return mController->GetNaturalSize();
@@ -251,6 +291,9 @@ void TextLabel::OnRelayout( const Vector2& size, ActorSizeContainer& container )
 
       if( renderableActor )
       {
+        const Vector2& alignmentOffset = mController->GetAlignmentOffset();
+        renderableActor.SetPosition( alignmentOffset.x, alignmentOffset.y );
+
         Self().Add( renderableActor );
       }
 
@@ -265,7 +308,7 @@ void TextLabel::RequestTextRelayout()
 }
 
 TextLabel::TextLabel()
-: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ),
+: Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
   mRenderingBackend( DEFAULT_RENDERING_BACKEND )
 {
 }