padding-example.cpp
4.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <string>
#include "padding-example.h"
#include "layout-utilities.h"
#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
#include <dali-toolkit/devel-api/controls/control-devel.h>
#include <dali-toolkit/devel-api/layouting/absolute-layout.h>
#include <dali-toolkit/devel-api/layouting/linear-layout.h>
using namespace Dali;
using namespace Dali::Toolkit;
namespace
{
const char* const TITLE = "Padding Example";
// Helper function to create ImageViews with given filename and size.
void CreateChildImageView( ImageView& imageView, const char* filename, Size size )
{
imageView = ImageView::New();
Property::Map imagePropertyMap;
imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = filename;
imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = size.width;
imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = size.height;
imageView.SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
imageView.SetName("ImageView");
imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
imageView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
}
}
namespace Demo
{
PaddingExample::PaddingExample()
: Example( TITLE )
{}
void PaddingExample::Create()
{
// The Init signal is received once (only) during the Application lifetime
auto stage = Stage::GetCurrent();
Control rootLayoutControl = LayoutUtilities::CreateRootContainer();
stage.Add( rootLayoutControl );
// Create a table view to show a pair of buttons above each image.
mHorizontalBox = Control::New();
// Create LinearLayout for this control.
auto hboxLayout = LinearLayout::New();
DevelControl::SetLayout( mHorizontalBox, hboxLayout );
mHorizontalBox.SetName("HBox");
mHorizontalBox.SetBackgroundColor( Color::WHITE );
mHorizontalBox.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 480 );
mHorizontalBox.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 700 );
mHorizontalBox.SetAnchorPoint( AnchorPoint::CENTER );
mHorizontalBox.SetParentOrigin( ParentOrigin::CENTER );
rootLayoutControl.Add( mHorizontalBox );
mToggleButton = Toolkit::PushButton::New();
mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Toggle Padding on #2" );
mToggleButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
mToggleButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
mToggleButton.ClickedSignal().Connect( this, &Demo::PaddingExample::ChangePaddingClicked );
mToggleButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
mToggleButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
stage.Add( mToggleButton );
for( unsigned int x = 0; x < NUMBER_OF_IMAGE_VIEWS; x++ )
{
CreateChildImageView( mImageViews[x], DEMO_IMAGE_DIR "gallery-small-23.jpg" , Size(100.0f, 100.0f) );
// Set Padding for second ImageView
if( 1 == x )
{
mImageViews[x].SetProperty(Toolkit::Control::Property::PADDING, Extents( 10.0f,10.0f,5.0f, 5.0f));
}
// Set margin for first ImageView
if( 0 == x )
{
mImageViews[x].SetProperty(Toolkit::Control::Property::MARGIN, Extents( 10.0f,10.0f,0.0f, 0.0f));
}
mHorizontalBox.Add( mImageViews[x] );
mImageViewToggleStatus[ x ] = true;
}
}
void PaddingExample::Remove()
{
UnparentAndReset( mToggleButton );
UnparentAndReset( mHorizontalBox );
}
bool PaddingExample::ChangePaddingClicked( Toolkit::Button button )
{
if ( true == mImageViewToggleStatus[ 1 ] )
{
mImageViews[1].SetProperty(Toolkit::Control::Property::PADDING, Extents( .0f, .0f, .0f, .0f));
mImageViews[1].SetProperty(Actor::Property::COLOR_ALPHA, 0.5f);
mImageViewToggleStatus[ 1 ] = false;
}
else
{
mImageViews[1].SetProperty(Toolkit::Control::Property::PADDING, Extents( 10.0f, 10.0f, 5.0f, 5.0f));
mImageViews[1].SetProperty(Actor::Property::COLOR_ALPHA, 1.0f);
mImageViewToggleStatus[ 1 ] = true;
}
return true;
}
} // namespace Demo