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 <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/absolute-layout.h>
24 #include <dali-toolkit/devel-api/layouting/linear-layout.h>
27 using namespace Dali::Toolkit;
33 // Helper function to create ImageViews with given filename and size.
34 void CreateChildImageView( ImageView& imageView, const char* filename, Size size )
36 imageView = ImageView::New();
37 Property::Map imagePropertyMap;
38 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
39 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = filename;
40 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = size.width;
41 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = size.height;
42 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
43 imageView.SetName("ImageView");
44 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
45 imageView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
53 void PaddingExample::Create()
55 // The Init signal is received once (only) during the Application lifetime
57 // Create a root layout, ideally Dali would have a default layout in the root layer.
58 // Without this root layer the mAbsoluteLayout (or any other layout) will not
59 // honour WIDTH_SPECIFICATION or HEIGHT_SPECIFICATION settings.
60 // It uses the default stage size and ideally should have a layout added to it.
61 auto stage = Stage::GetCurrent();
62 auto rootLayoutControl = Control::New();
63 rootLayoutControl.SetName( "AbsoluteLayout");
64 auto rootLayout = AbsoluteLayout::New();
65 DevelControl::SetLayout( rootLayoutControl, rootLayout );
66 rootLayoutControl.SetAnchorPoint( AnchorPoint::CENTER );
67 rootLayoutControl.SetParentOrigin( ParentOrigin::CENTER );
68 stage.Add( rootLayoutControl );
70 // Create a table view to show a pair of buttons above each image.
71 mHorizontalBox = Control::New();
73 // Create LinearLayout for this control.
74 auto hboxLayout = LinearLayout::New();
75 DevelControl::SetLayout( mHorizontalBox, hboxLayout );
76 mHorizontalBox.SetName("HBox");
77 mHorizontalBox.SetBackgroundColor( Color::WHITE );
78 mHorizontalBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 480 );
79 mHorizontalBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 700 );
80 mHorizontalBox.SetAnchorPoint( AnchorPoint::CENTER );
81 mHorizontalBox.SetParentOrigin( ParentOrigin::CENTER );
83 rootLayoutControl.Add( mHorizontalBox );
85 mToggleButton = Toolkit::PushButton::New();
86 mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Toggle Padding on #2" );
87 mToggleButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
88 mToggleButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
89 mToggleButton.ClickedSignal().Connect( this, &Demo::PaddingExample::ChangePaddingClicked );
90 mToggleButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
91 mToggleButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
93 stage.Add( mToggleButton );
95 for( unsigned int x = 0; x < NUMBER_OF_IMAGE_VIEWS; x++ )
97 CreateChildImageView( mImageViews[x], DEMO_IMAGE_DIR "gallery-small-23.jpg" , Size(100.0f, 100.0f) );
99 // Set Padding for second ImageView
102 mImageViews[x].SetProperty(Toolkit::Control::Property::PADDING, Extents( 10.0f,10.0f,5.0f, 5.0f));
105 // Set margin for first ImageView
108 mImageViews[x].SetProperty(Toolkit::Control::Property::MARGIN, Extents( 10.0f,10.0f,0.0f, 0.0f));
111 mHorizontalBox.Add( mImageViews[x] );
113 mImageViewToggleStatus[ x ] = true;
117 void PaddingExample::Remove()
119 UnparentAndReset( mToggleButton );
120 UnparentAndReset( mHorizontalBox );
123 bool PaddingExample::ChangePaddingClicked( Toolkit::Button button )
125 if ( true == mImageViewToggleStatus[ 1 ] )
127 mImageViews[1].SetProperty(Toolkit::Control::Property::PADDING, Extents( .0f, .0f, .0f, .0f));
128 mImageViews[1].SetProperty(Actor::Property::COLOR_ALPHA, 0.5f);
129 mImageViewToggleStatus[ 1 ] = false;
133 mImageViews[1].SetProperty(Toolkit::Control::Property::PADDING, Extents( 10.0f, 10.0f, 5.0f, 5.0f));
134 mImageViews[1].SetProperty(Actor::Property::COLOR_ALPHA, 1.0f);
135 mImageViewToggleStatus[ 1 ] = true;