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 "padding-example.h"
20 #include "layout-utilities.h"
21 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
22 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
23 #include <dali-toolkit/devel-api/controls/control-devel.h>
24 #include <dali-toolkit/devel-api/layouting/absolute-layout.h>
25 #include <dali-toolkit/devel-api/layouting/linear-layout.h>
28 using namespace Dali::Toolkit;
33 const char* const TITLE = "Padding Example";
35 // Helper function to create ImageViews with given filename and size.
36 void CreateChildImageView( ImageView& imageView, const char* filename, Size size )
38 imageView = ImageView::New();
39 Property::Map imagePropertyMap;
40 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
41 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = filename;
42 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = size.width;
43 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = size.height;
44 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
45 imageView.SetName("ImageView");
46 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
47 imageView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
55 PaddingExample::PaddingExample()
59 void PaddingExample::Create()
61 // The Init signal is received once (only) during the Application lifetime
63 auto stage = Stage::GetCurrent();
65 Control rootLayoutControl = LayoutUtilities::CreateRootContainer();
66 stage.Add( rootLayoutControl );
68 // Create a table view to show a pair of buttons above each image.
69 mHorizontalBox = Control::New();
71 // Create LinearLayout for this control.
72 auto hboxLayout = LinearLayout::New();
73 DevelControl::SetLayout( mHorizontalBox, hboxLayout );
74 mHorizontalBox.SetName("HBox");
75 mHorizontalBox.SetBackgroundColor( Color::WHITE );
76 mHorizontalBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 480 );
77 mHorizontalBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 700 );
78 mHorizontalBox.SetAnchorPoint( AnchorPoint::CENTER );
79 mHorizontalBox.SetParentOrigin( ParentOrigin::CENTER );
81 rootLayoutControl.Add( mHorizontalBox );
83 mToggleButton = Toolkit::PushButton::New();
84 mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Toggle Padding on #2" );
85 mToggleButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
86 mToggleButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
87 mToggleButton.ClickedSignal().Connect( this, &Demo::PaddingExample::ChangePaddingClicked );
88 mToggleButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
89 mToggleButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
91 stage.Add( mToggleButton );
93 for( unsigned int x = 0; x < NUMBER_OF_IMAGE_VIEWS; x++ )
95 CreateChildImageView( mImageViews[x], DEMO_IMAGE_DIR "gallery-small-23.jpg" , Size(100.0f, 100.0f) );
97 // Set Padding for second ImageView
100 mImageViews[x].SetProperty(Toolkit::Control::Property::PADDING, Extents( 10.0f,10.0f,5.0f, 5.0f));
103 // Set margin for first ImageView
106 mImageViews[x].SetProperty(Toolkit::Control::Property::MARGIN, Extents( 10.0f,10.0f,0.0f, 0.0f));
109 mHorizontalBox.Add( mImageViews[x] );
111 mImageViewToggleStatus[ x ] = true;
115 void PaddingExample::Remove()
117 UnparentAndReset( mToggleButton );
118 UnparentAndReset( mHorizontalBox );
121 bool PaddingExample::ChangePaddingClicked( Toolkit::Button button )
123 if ( true == mImageViewToggleStatus[ 1 ] )
125 mImageViews[1].SetProperty(Toolkit::Control::Property::PADDING, Extents( .0f, .0f, .0f, .0f));
126 mImageViews[1].SetProperty(Actor::Property::COLOR_ALPHA, 0.5f);
127 mImageViewToggleStatus[ 1 ] = false;
131 mImageViews[1].SetProperty(Toolkit::Control::Property::PADDING, Extents( 10.0f, 10.0f, 5.0f, 5.0f));
132 mImageViews[1].SetProperty(Actor::Property::COLOR_ALPHA, 1.0f);
133 mImageViewToggleStatus[ 1 ] = true;