54ff30250d1ee7fadb405343784c57fff3f41251
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / layout-utils.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // FILE HEADER
19 #include "layout-utils.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali/devel-api/adaptor-framework/pixel-buffer.h>
24 #include <dali-toolkit/devel-api/image-loader/texture-manager.h>
25 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include <dali-toolkit/devel-api/layouting/flex-layout.h>
27
28 // INTERNAL INCLUDES
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 Control CreateLeafControl( int width, int height )
37 {
38   auto control = Control::New();
39   control.SetName( "Leaf" );
40
41   auto pixelBuffer = Devel::PixelBuffer::New( 1, 1, Pixel::RGB888 );
42   unsigned char* pixels = pixelBuffer.GetBuffer();
43   pixels[0] = 0xff;
44   pixels[1] = 0x00;
45   pixels[2] = 0x00;
46   auto texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGB888, 1, 1 );
47   auto pixelData = Devel::PixelBuffer::Convert( pixelBuffer );
48   texture.Upload( pixelData );
49   std::string url = TextureManager::AddTexture( texture );
50
51   Property::Map map;
52   map[ Visual::Property::TYPE ] = Visual::IMAGE;
53   map[ ImageVisual::Property::URL ] = url;
54   map[ ImageVisual::Property::DESIRED_WIDTH ] = (float) width;
55   map[ ImageVisual::Property::DESIRED_HEIGHT ] = (float) height;
56   control.SetProperty( Control::Property::BACKGROUND, map );
57   return control;
58 }
59
60 } // namespace Toolkit
61
62 } // namespace Dali