2 * Copyright (c) 2017 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 "padding-example.h"
20 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
21 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
22 #include <dali-toolkit/devel-api/controls/control-devel.h>
23 #include <dali-toolkit/devel-api/layouting/hbox-layout.h>
26 using namespace Dali::Toolkit;
32 // Helper function to create ImageViews with given filename and size.
33 void CreateChildImageView( ImageView& imageView, const char* filename, Size size )
35 imageView = ImageView::New();
36 Property::Map imagePropertyMap;
37 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
38 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = filename;
39 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = size.width;
40 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = size.height;
41 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
42 imageView.SetName("ImageView");
43 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
44 imageView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
52 void PaddingExample::Create()
54 // The Init signal is received once (only) during the Application lifetime
56 // Creates a default view with a default tool bar.
57 // The view is added to the stage.
58 auto stage = Stage::GetCurrent();
59 // Create a table view to show a pair of buttons above each image.
60 mHorizontalBox = Control::New();
62 // Create HBoxLayout for this control.
63 auto hboxLayout = HboxLayout::New();
64 DevelControl::SetLayout( mHorizontalBox, hboxLayout );
65 mHorizontalBox.SetName("HBox");
67 mHorizontalBox.SetAnchorPoint( AnchorPoint::CENTER );
68 mHorizontalBox.SetParentOrigin( ParentOrigin::CENTER );
70 stage.Add( mHorizontalBox );
72 for( unsigned int x = 0; x < NUMBER_OF_IMAGE_VIEWS; x++ )
74 mToggleButton = Toolkit::PushButton::New();
75 mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Toggle Padding on #2" );
76 mToggleButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
77 mToggleButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
78 mToggleButton.ClickedSignal().Connect( this, &Demo::PaddingExample::ChangePaddingClicked );
79 mToggleButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
80 mToggleButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
82 stage.Add( mToggleButton );
84 CreateChildImageView( mImageViews[x], DEMO_IMAGE_DIR "gallery-small-23.jpg" , Size(100.0f, 100.0f) );
86 // Set Padding for second ImageView
89 mImageViews[x].SetProperty(Toolkit::Control::Property::PADDING, Extents(10.0f,10.0f,5.0f, 5.0f));
92 // Set margin for first ImageView
95 mImageViews[x].SetProperty(Toolkit::Control::Property::MARGIN, Extents(10.0f,10.0f,0.0f, 0.0f));
98 mHorizontalBox.Add( mImageViews[x] );
100 mImageViewToggleStatus[ x ] = true;
104 void PaddingExample::Remove()
106 UnparentAndReset( mToggleButton );
107 UnparentAndReset( mHorizontalBox );
110 bool PaddingExample::ChangePaddingClicked( Toolkit::Button button )
112 if ( true == mImageViewToggleStatus[ 1 ] )
114 mImageViews[1].SetProperty(Toolkit::Control::Property::PADDING, Extents( .0f, .0f, .0f, .0f));
115 mImageViews[1].SetProperty(Actor::Property::COLOR_ALPHA, 0.5f);
116 mImageViewToggleStatus[ 1 ] = false;
120 mImageViews[1].SetProperty(Toolkit::Control::Property::PADDING, Extents( 10.0f, 10.0f, 5.0f, 5.0f));
121 mImageViews[1].SetProperty(Actor::Property::COLOR_ALPHA, 1.0f);
122 mImageViewToggleStatus[ 1 ] = true;