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 "absolute-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>
27 using namespace Dali::Toolkit;
32 const char* const TITLE = "Absolute Example";
41 ImageDetails IMAGES[] =
43 { DEMO_IMAGE_DIR "gallery-small-23.jpg", Vector2( 0.0f, 0.0f ), Size( 100.0f, 100.0f ) },
44 { DEMO_IMAGE_DIR "gallery-small-23.jpg", Vector2( 100.0f, 0.0f ), Size( 100.0f, 100.0f ) },
45 { DEMO_IMAGE_DIR "gallery-small-23.jpg", Vector2( 0.0f, 100.0f ), Size( 100.0f, 100.0f ) },
46 { DEMO_IMAGE_DIR "gallery-small-23.jpg", Vector2( 200.0f, 200.0f ), Size( 100.0f, 100.0f ) },
48 unsigned int IMAGE_COUNT=sizeof(IMAGES)/sizeof(IMAGES[0]);
50 // Helper function to create ImageViews with given filename and size.
51 void CreateChildImageView( ImageView& imageView, unsigned imageIndex )
53 imageView = ImageView::New();
54 Property::Map imagePropertyMap;
55 imagePropertyMap[ Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
56 imagePropertyMap[ ImageVisual::Property::URL ] = IMAGES[imageIndex].name;
57 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = IMAGES[imageIndex].size.width ;
58 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = IMAGES[imageIndex].size.height;
59 imageView.SetProperty( ImageView::Property::IMAGE , imagePropertyMap );
60 imageView.SetName("ImageView");
61 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
62 imageView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
63 imageView.SetProperty( Dali::Actor::Property::POSITION, Vector3( IMAGES[imageIndex].position ) );
71 AbsoluteExample::AbsoluteExample()
74 mAbsoluteLayoutContainer(),
75 mLayoutSizeToggleStatus( true ),
81 void AbsoluteExample::Create()
83 auto stage = Stage::GetCurrent();
84 // This layout will be the size of the stage but allows subsequent layouts to be any size.
85 mRootLayoutControl = LayoutUtilities::CreateRootContainer();
86 stage.Add( mRootLayoutControl );
88 // Create an Absolute Layout to show ImageViews at explictly provided positions.
89 mAbsoluteLayoutContainer = Control::New();
90 mAbsoluteLayoutContainer.SetBackgroundColor( Color::WHITE );
91 auto absoluteLayout = AbsoluteLayout::New();
92 DevelControl::SetLayout( mAbsoluteLayoutContainer, absoluteLayout );
93 mAbsoluteLayoutContainer.SetName("AbsoluteLayout");
95 mAbsoluteLayoutContainer.SetAnchorPoint( AnchorPoint::CENTER );
96 mAbsoluteLayoutContainer.SetParentOrigin( ParentOrigin::CENTER );
98 // Initially absolute layout to use these specifications, toggle button will alter them.
99 mAbsoluteLayoutContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
100 mAbsoluteLayoutContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
102 mRootLayoutControl.Add( mAbsoluteLayoutContainer );
104 for( unsigned int x = 0; x < NUMBER_OF_IMAGE_VIEWS; x++ )
106 CreateChildImageView( mImageViews[x], x%IMAGE_COUNT );
107 mAbsoluteLayoutContainer.Add( mImageViews[x] );
110 // Button toggles the size of the layout
111 mToggleButton = PushButton::New();
112 mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Change layout size" );
113 mToggleButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
114 mToggleButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
115 mToggleButton.ClickedSignal().Connect( this, &Demo::AbsoluteExample::ChangeSizeClicked );
116 mToggleButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
117 mToggleButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
119 stage.Add( mToggleButton );
123 void AbsoluteExample::Remove()
125 UnparentAndReset( mAbsoluteLayoutContainer );
126 UnparentAndReset( mToggleButton );
127 UnparentAndReset( mRootLayoutControl );
130 bool AbsoluteExample::ChangeSizeClicked( Toolkit::Button button )
132 if ( true == mLayoutSizeToggleStatus )
134 mAbsoluteLayoutContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, 480 );
135 mAbsoluteLayoutContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, 700 );
136 mLayoutSizeToggleStatus = false;
140 mAbsoluteLayoutContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
141 mAbsoluteLayoutContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
142 mLayoutSizeToggleStatus = true;