absolute-example.cpp
5.35 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
140
141
142
143
144
145
146
147
148
/*
* Copyright (c) 2017 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 "absolute-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>
using namespace Dali;
using namespace Dali::Toolkit;
namespace
{
const char* const TITLE = "Absolute Example";
struct ImageDetails
{
const char * name;
Vector2 position;
Size size;
};
ImageDetails IMAGES[] =
{
{ DEMO_IMAGE_DIR "gallery-small-23.jpg", Vector2( 0.0f, 0.0f ), Size( 100.0f, 100.0f ) },
{ DEMO_IMAGE_DIR "gallery-small-23.jpg", Vector2( 100.0f, 0.0f ), Size( 100.0f, 100.0f ) },
{ DEMO_IMAGE_DIR "gallery-small-23.jpg", Vector2( 0.0f, 100.0f ), Size( 100.0f, 100.0f ) },
{ DEMO_IMAGE_DIR "gallery-small-23.jpg", Vector2( 200.0f, 200.0f ), Size( 100.0f, 100.0f ) },
};
unsigned int IMAGE_COUNT=sizeof(IMAGES)/sizeof(IMAGES[0]);
// Helper function to create ImageViews with given filename and size.
void CreateChildImageView( ImageView& imageView, unsigned imageIndex )
{
imageView = ImageView::New();
Property::Map imagePropertyMap;
imagePropertyMap[ Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
imagePropertyMap[ ImageVisual::Property::URL ] = IMAGES[imageIndex].name;
imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = IMAGES[imageIndex].size.width ;
imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = IMAGES[imageIndex].size.height;
imageView.SetProperty( ImageView::Property::IMAGE , imagePropertyMap );
imageView.SetName("ImageView");
imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
imageView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
imageView.SetProperty( Dali::Actor::Property::POSITION, Vector3( IMAGES[imageIndex].position ) );
}
} // namespace
namespace Demo
{
AbsoluteExample::AbsoluteExample()
: Example( TITLE ),
mRootLayoutControl(),
mAbsoluteLayoutContainer(),
mLayoutSizeToggleStatus( true ),
mToggleButton()
{
}
void AbsoluteExample::Create()
{
auto stage = Stage::GetCurrent();
// This layout will be the size of the stage but allows subsequent layouts to be any size.
mRootLayoutControl = LayoutUtilities::CreateRootContainer();
stage.Add( mRootLayoutControl );
// Create an Absolute Layout to show ImageViews at explictly provided positions.
mAbsoluteLayoutContainer = Control::New();
mAbsoluteLayoutContainer.SetBackgroundColor( Color::WHITE );
auto absoluteLayout = AbsoluteLayout::New();
DevelControl::SetLayout( mAbsoluteLayoutContainer, absoluteLayout );
mAbsoluteLayoutContainer.SetName("AbsoluteLayout");
mAbsoluteLayoutContainer.SetAnchorPoint( AnchorPoint::CENTER );
mAbsoluteLayoutContainer.SetParentOrigin( ParentOrigin::CENTER );
// Initially absolute layout to use these specifications, toggle button will alter them.
mAbsoluteLayoutContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
mAbsoluteLayoutContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
mRootLayoutControl.Add( mAbsoluteLayoutContainer );
for( unsigned int x = 0; x < NUMBER_OF_IMAGE_VIEWS; x++ )
{
CreateChildImageView( mImageViews[x], x%IMAGE_COUNT );
mAbsoluteLayoutContainer.Add( mImageViews[x] );
}
// Button toggles the size of the layout
mToggleButton = PushButton::New();
mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Change layout size" );
mToggleButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
mToggleButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
mToggleButton.ClickedSignal().Connect( this, &Demo::AbsoluteExample::ChangeSizeClicked );
mToggleButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
mToggleButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
stage.Add( mToggleButton );
}
void AbsoluteExample::Remove()
{
UnparentAndReset( mAbsoluteLayoutContainer );
UnparentAndReset( mToggleButton );
UnparentAndReset( mRootLayoutControl );
}
bool AbsoluteExample::ChangeSizeClicked( Toolkit::Button button )
{
if ( true == mLayoutSizeToggleStatus )
{
mAbsoluteLayoutContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 480 );
mAbsoluteLayoutContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 700 );
mLayoutSizeToggleStatus = false;
}
else
{
mAbsoluteLayoutContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
mAbsoluteLayoutContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
mLayoutSizeToggleStatus = true;
}
return true;
}
} // namespace Demo