ResizePolicy for TextField
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / text-controls / text-field-impl.cpp
index 3bf4e67..f189207 100644 (file)
@@ -54,13 +54,21 @@ namespace
 namespace
 {
 
-const Scripting::StringEnum< Toolkit::Text::LayoutEngine::Alignment > ALIGNMENT_STRING_TABLE[] =
+const Scripting::StringEnum< Toolkit::Text::LayoutEngine::HorizontalAlignment > HORIZONTAL_ALIGNMENT_STRING_TABLE[] =
 {
-  { "BEGIN",  Toolkit::Text::LayoutEngine::ALIGN_BEGIN  },
-  { "CENTER", Toolkit::Text::LayoutEngine::ALIGN_CENTER },
-  { "END",    Toolkit::Text::LayoutEngine::ALIGN_END    },
+  { "BEGIN",  Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_BEGIN  },
+  { "CENTER", Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_CENTER },
+  { "END",    Toolkit::Text::LayoutEngine::HORIZONTAL_ALIGN_END    },
 };
-const unsigned int ALIGNMENT_STRING_TABLE_COUNT = sizeof( ALIGNMENT_STRING_TABLE ) / sizeof( ALIGNMENT_STRING_TABLE[0] );
+const unsigned int HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE ) / sizeof( HORIZONTAL_ALIGNMENT_STRING_TABLE[0] );
+
+const Scripting::StringEnum< Toolkit::Text::LayoutEngine::VerticalAlignment > VERTICAL_ALIGNMENT_STRING_TABLE[] =
+{
+  { "TOP",    Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_TOP    },
+  { "CENTER", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_CENTER },
+  { "BOTTOM", Toolkit::Text::LayoutEngine::VERTICAL_ALIGN_BOTTOM },
+};
+const unsigned int VERTICAL_ALIGNMENT_STRING_TABLE_COUNT = sizeof( VERTICAL_ALIGNMENT_STRING_TABLE ) / sizeof( VERTICAL_ALIGNMENT_STRING_TABLE[0] );
 
 // Type registration
 BaseHandle Create()
@@ -84,9 +92,9 @@ DALI_PROPERTY_REGISTRATION( TextField, "enable-cursor-blink",     BOOLEAN,   ENA
 DALI_PROPERTY_REGISTRATION( TextField, "cursor-blink-interval",   FLOAT,     CURSOR_BLINK_INTERVAL   )
 DALI_PROPERTY_REGISTRATION( TextField, "cursor-blink-duration",   FLOAT,     CURSOR_BLINK_DURATION   )
 DALI_PROPERTY_REGISTRATION( TextField, "grab-handle-image",       STRING,    GRAB_HANDLE_IMAGE       )
-DALI_PROPERTY_REGISTRATION( TextField, "decoration bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX )
-DALI_PROPERTY_REGISTRATION( TextField, "alignment",               STRING,    ALIGNMENT               )
-
+DALI_PROPERTY_REGISTRATION( TextField, "decoration-bounding-box", RECTANGLE, DECORATION_BOUNDING_BOX )
+DALI_PROPERTY_REGISTRATION( TextField, "horizontal-alignment",    STRING,    HORIZONTAL_ALIGNMENT    )
+DALI_PROPERTY_REGISTRATION( TextField, "vertical-alignment",      STRING,    VERTICAL_ALIGNMENT      )
 DALI_TYPE_REGISTRATION_END()
 
 } // namespace
@@ -248,22 +256,36 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr
         }
         break;
       }
-      case Toolkit::TextField::Property::ALIGNMENT:
+      case Toolkit::TextField::Property::HORIZONTAL_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 );
+        const LayoutEngine::HorizontalAlignment alignment = Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::HorizontalAlignment >( value.Get< std::string >().c_str(),
+                                                                                                                                           HORIZONTAL_ALIGNMENT_STRING_TABLE,
+                                                                                                                                           HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT );
 
-        if( engine.GetAlignment() != alignment )
+        if( engine.GetHorizontalAlignment() != alignment )
         {
-          engine.SetAlignment( alignment );
+          engine.SetHorizontalAlignment( alignment );
           impl.RequestTextRelayout();
         }
         break;
       }
-    }
-  }
+      case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
+      {
+        LayoutEngine& engine = impl.mController->GetLayoutEngine();
+        const LayoutEngine::VerticalAlignment alignment = Scripting::GetEnumeration< Toolkit::Text::LayoutEngine::VerticalAlignment >( value.Get< std::string >().c_str(),
+                                                                                                                                       VERTICAL_ALIGNMENT_STRING_TABLE,
+                                                                                                                                       VERTICAL_ALIGNMENT_STRING_TABLE_COUNT );
+
+        if( engine.GetVerticalAlignment() != alignment )
+        {
+          engine.SetVerticalAlignment( alignment );
+          impl.RequestTextRelayout();
+        }
+        break;
+      }
+    } // switch
+  } // textfield
 }
 
 Property::Value TextField::GetProperty( BaseObject* object, Property::Index index )
@@ -353,17 +375,27 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde
         }
         break;
       }
-      case Toolkit::TextField::Property::ALIGNMENT:
+      case Toolkit::TextField::Property::HORIZONTAL_ALIGNMENT:
       {
         if( impl.mController )
         {
-          value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::Alignment >( impl.mController->GetLayoutEngine().GetAlignment(),
-                                                                                                        ALIGNMENT_STRING_TABLE,
-                                                                                                        ALIGNMENT_STRING_TABLE_COUNT ) );
+          value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::HorizontalAlignment >( impl.mController->GetLayoutEngine().GetHorizontalAlignment(),
+                                                                                                                  HORIZONTAL_ALIGNMENT_STRING_TABLE,
+                                                                                                                  HORIZONTAL_ALIGNMENT_STRING_TABLE_COUNT ) );
         }
         break;
       }
-    }
+      case Toolkit::TextField::Property::VERTICAL_ALIGNMENT:
+      {
+        if( impl.mController )
+        {
+          value = std::string( Scripting::GetEnumerationName< Toolkit::Text::LayoutEngine::VerticalAlignment >( impl.mController->GetLayoutEngine().GetVerticalAlignment(),
+                                                                                                                  VERTICAL_ALIGNMENT_STRING_TABLE,
+                                                                                                                  VERTICAL_ALIGNMENT_STRING_TABLE_COUNT ) );
+        }
+        break;
+      }
+    } //switch
   }
 
   return value;
@@ -371,6 +403,8 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde
 
 void TextField::OnInitialize()
 {
+  Actor self = Self();
+
   mController = Text::Controller::New( *this );
 
   mDecorator = Text::Decorator::New( *this, *mController );
@@ -390,6 +424,10 @@ void TextField::OnInitialize()
     Vector2 stageSize = Dali::Stage::GetCurrent().GetSize();
     mDecorator->SetBoundingBox( Rect<int>( 0.0f, 0.0f, stageSize.width, stageSize.height ) );
   }
+
+  // Fill-parent area by default
+  self.SetResizePolicy( FILL_TO_PARENT, WIDTH );
+  self.SetResizePolicy( FILL_TO_PARENT, HEIGHT );
 }
 
 void TextField::OnStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
@@ -407,14 +445,19 @@ float TextField::GetHeightForWidth( float width )
   return mController->GetHeightForWidth( width );
 }
 
-void TextField::OnRelayout( const Vector2& size, ActorSizeContainer& container )
+void TextField::OnRelayout( const Vector2& size, RelayoutContainer& container )
 {
   if( mController->Relayout( size ) ||
       !mRenderer )
   {
+    const Vector2& scrollPosition = mController->GetScrollPosition();
+    const Vector2& alignmentOffset = mController->GetAlignmentOffset();
+
+    Vector2 offset = scrollPosition + alignmentOffset;
+
     if( mDecorator )
     {
-      mDecorator->Relayout( size, mController->GetScrollPosition() );
+      mDecorator->Relayout( size, offset );
     }
 
     if( !mRenderer )
@@ -438,8 +481,7 @@ void TextField::OnRelayout( const Vector2& size, ActorSizeContainer& container )
 
     if( mRenderableActor )
     {
-      const Vector2& scrollPosition = mController->GetScrollPosition();
-      mRenderableActor.SetPosition( scrollPosition.x, scrollPosition.y );
+      mRenderableActor.SetPosition( offset.x, offset.y );
 
       // Make sure the actor is parented correctly with/without clipping
       if( mClipper )