Text Alignment
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-label-impl.cpp
index bb0607d..118c2b3 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/internal/styling/style-manager-impl.h>
 
 using Dali::Toolkit::Text::LayoutEngine;
 using Dali::Toolkit::Text::Backend;
 
-namespace
-{
-
-const unsigned int DEFAULT_RENDERING_BACKEND = 0;
-
-} // namespace
-
 namespace Dali
 {
 
@@ -48,6 +44,19 @@ namespace Internal
 
 namespace
 {
+  const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
+}
+
+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()
@@ -64,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()
 
@@ -95,11 +105,11 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr
     {
       case Toolkit::TextLabel::Property::RENDERING_BACKEND:
       {
-        unsigned int backend = value.Get< int >();
+        int backend = value.Get< int >();
 
         if( impl.mRenderingBackend != backend )
         {
-          impl.mRenderingBackend = static_cast< unsigned int >( backend );
+          impl.mRenderingBackend = backend;
           impl.mRenderer.Reset();
           impl.RequestTextRelayout();
         }
@@ -165,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;
+      }
     }
   }
 }
@@ -199,8 +223,6 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde
           impl.mController->GetText( text );
           value = text;
         }
-
-        DALI_LOG_WARNING( "UTF-8 text representation was discarded\n" );
         break;
       }
       case Toolkit::TextLabel::Property::MULTI_LINE:
@@ -211,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;
+      }
     }
   }
 
@@ -222,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();
@@ -268,7 +305,7 @@ void TextLabel::RequestTextRelayout()
 }
 
 TextLabel::TextLabel()
-: Control( ControlBehaviour( CONTROL_BEHAVIOUR_NONE ) ),
+: Control( ControlBehaviour( REQUIRES_STYLE_CHANGE_SIGNALS ) ),
   mRenderingBackend( DEFAULT_RENDERING_BACKEND )
 {
 }