2 * Copyright (c) 2018 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "layout-utils.h"
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>
36 std::string CreateImageURL( Vector4 color, ImageDimensions size )
38 auto pixelBuffer = Devel::PixelBuffer::New( size.GetWidth(), size.GetHeight(), Pixel::RGB888 );
39 unsigned char* pixels = pixelBuffer.GetBuffer();
40 pixels[0] = static_cast<unsigned char>( color.r );
41 pixels[1] = static_cast<unsigned char>( color.g );
42 pixels[2] = static_cast<unsigned char>( color.b );
43 auto texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGB888, size.GetWidth(), size.GetHeight() );
44 auto pixelData = Devel::PixelBuffer::Convert( pixelBuffer );
45 texture.Upload( pixelData );
46 return TextureManager::AddTexture( texture );
49 Control CreateLeafControl( int width, int height )
51 auto control = Control::New();
52 control.SetName( "Leaf" );
53 std::string url = CreateImageURL( Vector4( 255, 0, 0, 255 ), ImageDimensions( 1, 1 ) );
56 map[ Visual::Property::TYPE ] = Visual::IMAGE;
57 map[ ImageVisual::Property::URL ] = url;
58 map[ ImageVisual::Property::DESIRED_WIDTH ] = (float) width;
59 map[ ImageVisual::Property::DESIRED_HEIGHT ] = (float) height;
60 control.SetProperty( Control::Property::BACKGROUND, map );
64 TextLabel CreateTextLabel( const char* text )
66 TextLabel textLabel = TextLabel::New(text);
67 textLabel.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
68 textLabel.SetProperty( TextLabel::Property::VERTICAL_ALIGNMENT, "CENTER" );
69 textLabel.SetName( "TextLabel" );
70 textLabel.SetAnchorPoint( AnchorPoint::TOP_LEFT );
74 ImageView CreateImageView( std::string& url, ImageDimensions size )
76 ImageView imageView = ImageView::New( url, size );
77 imageView.SetName( "ImageView" );
78 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
82 } // namespace Toolkit