Add new layouting support for TextLabel and ImageView.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / layout-utils.cpp
index 54ff302..81fd6bf 100755 (executable)
@@ -33,20 +33,24 @@ namespace Dali
 namespace Toolkit
 {
 
-Control CreateLeafControl( int width, int height )
+std::string CreateImageURL( Vector4 color, ImageDimensions size )
 {
-  auto control = Control::New();
-  control.SetName( "Leaf" );
-
-  auto pixelBuffer = Devel::PixelBuffer::New( 1, 1, Pixel::RGB888 );
+  auto pixelBuffer = Devel::PixelBuffer::New( size.GetWidth(), size.GetHeight(), Pixel::RGB888 );
   unsigned char* pixels = pixelBuffer.GetBuffer();
-  pixels[0] = 0xff;
-  pixels[1] = 0x00;
-  pixels[2] = 0x00;
-  auto texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGB888, 1, 1 );
+  pixels[0] = static_cast<unsigned char>( color.r );
+  pixels[1] = static_cast<unsigned char>( color.g );
+  pixels[2] = static_cast<unsigned char>( color.b );
+  auto texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGB888, size.GetWidth(), size.GetHeight() );
   auto pixelData = Devel::PixelBuffer::Convert( pixelBuffer );
   texture.Upload( pixelData );
-  std::string url = TextureManager::AddTexture( texture );
+  return TextureManager::AddTexture( texture );
+}
+
+Control CreateLeafControl( int width, int height )
+{
+  auto control = Control::New();
+  control.SetName( "Leaf" );
+  std::string url = CreateImageURL( Vector4( 255, 0, 0, 255 ), ImageDimensions( 1, 1 ) );
 
   Property::Map map;
   map[ Visual::Property::TYPE ] = Visual::IMAGE;
@@ -57,6 +61,24 @@ Control CreateLeafControl( int width, int height )
   return control;
 }
 
+TextLabel CreateTextLabel( const char* text )
+{
+  TextLabel textLabel = TextLabel::New(text);
+  textLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
+  textLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
+  textLabel.SetName( "TextLabel" );
+  textLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  return textLabel;
+}
+
+ImageView CreateImageView( std::string& url, ImageDimensions size )
+{
+  ImageView imageView = ImageView::New( url, size );
+  imageView.SetName( "ImageView" );
+  imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  return imageView;
+}
+
 } // namespace Toolkit
 
 } // namespace Dali