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 "linear-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/hbox-layout.h>
24 #include <dali-toolkit/devel-api/layouting/vbox-layout.h>
27 using namespace Dali::Toolkit;
33 const char* LTR_IMAGE( DEMO_IMAGE_DIR "icon-play.png" );
34 const char* LTR_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-play-selected.png" );
36 const char* RTL_IMAGE( DEMO_IMAGE_DIR "icon-reverse.png" );
37 const char* RTL_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-reverse-selected.png" );
39 const char* ROTATE_CLOCKWISE_IMAGE( DEMO_IMAGE_DIR "icon-reset.png" );
40 const char* ROTATE_CLOCKWISE_SELECTED_IMAGE( DEMO_IMAGE_DIR "icon-reset-selected.png" );
42 // Child image filenames
43 const char* IMAGE_PATH[] = {
44 DEMO_IMAGE_DIR "application-icon-101.png",
45 DEMO_IMAGE_DIR "application-icon-102.png",
46 DEMO_IMAGE_DIR "application-icon-103.png",
47 DEMO_IMAGE_DIR "application-icon-104.png"
50 const unsigned int NUMBER_OF_RESOURCES = sizeof(IMAGE_PATH) / sizeof(char*);
52 // Helper function to create ImageViews with given filename and size.
53 void CreateChildImageView( ImageView& imageView, const char* filename, Size size )
55 imageView = ImageView::New();
56 Property::Map imagePropertyMap;
57 imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
58 imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = filename;
59 imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = size.width;
60 imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = size.height;
61 imageView.SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
62 imageView.SetName("ImageView");
63 imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
64 imageView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
72 void LinearExample::Create()
74 // The Init signal is received once (only) during the Application lifetime
75 auto stage = Stage::GetCurrent();
77 mDirectionButton = PushButton::New();
78 mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, RTL_IMAGE );
79 mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, RTL_SELECTED_IMAGE );
80 mDirectionButton.ClickedSignal().Connect( this, &LinearExample::OnDirectionClicked );
81 mDirectionButton.SetParentOrigin( Vector3(0.33f, 1.0f, 0.5f ) );
82 mDirectionButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
83 mDirectionButton.SetSize(75, 75);
84 stage.Add( mDirectionButton );
86 mRotateButton = PushButton::New();
87 mRotateButton.SetProperty( PushButton::Property::UNSELECTED_ICON, ROTATE_CLOCKWISE_IMAGE );
88 mRotateButton.SetProperty( PushButton::Property::SELECTED_ICON, ROTATE_CLOCKWISE_SELECTED_IMAGE );
89 mRotateButton.ClickedSignal().Connect( this, &LinearExample::OnRotateClicked );
90 mRotateButton.SetParentOrigin( Vector3(0.66f, 1.0f, 0.5f ));
91 mRotateButton.SetAnchorPoint( Vector3(0.5f, 1.0f, 0.5f));
92 mRotateButton.SetSize(75, 75);
93 stage.Add( mRotateButton );
95 // Create a linear layout
96 mLinearContainer = Control::New();
97 mIsHorizontal = false;
99 auto layout = VboxLayout::New();
100 layout.SetAnimateLayout(true);
101 DevelControl::SetLayout( mLinearContainer, layout );
103 mLinearContainer.SetParentOrigin( ParentOrigin::CENTER );
104 mLinearContainer.SetAnchorPoint( AnchorPoint::CENTER );
105 mLinearContainer.SetName( "LinearExample" );
106 stage.Add( mLinearContainer );
107 mLinearContainer.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
108 mLinearContainer.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
109 mLinearContainer.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::LEFT_TO_RIGHT );
111 for( unsigned int x = 0; x < NUMBER_OF_RESOURCES; ++x )
113 Toolkit::ImageView imageView;
114 CreateChildImageView( imageView, IMAGE_PATH[ x ], Size(100.0f, 100.0f) );
115 mLinearContainer.Add( imageView );
119 // Remove controls added by this example from stage
120 void LinearExample::Remove()
122 if ( mLinearContainer )
124 UnparentAndReset( mDirectionButton );
125 UnparentAndReset( mRotateButton );
126 UnparentAndReset( mLinearContainer);
130 // Mirror items in layout
131 bool LinearExample::OnDirectionClicked( Button button )
135 mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, LTR_IMAGE );
136 mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, LTR_SELECTED_IMAGE );
137 mLinearContainer.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::LEFT_TO_RIGHT );
141 mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, RTL_IMAGE );
142 mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, RTL_SELECTED_IMAGE );
143 mLinearContainer.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
145 mDirection = !mDirection;
149 // Rotate layout by changing layout
150 bool LinearExample::OnRotateClicked( Button button )
152 mIsHorizontal = !mIsHorizontal;
155 auto hboxLayout = HboxLayout::New();
156 hboxLayout.SetAnimateLayout(true);
157 DevelControl::SetLayout( mLinearContainer, hboxLayout );
161 auto vboxLayout = VboxLayout::New();
162 vboxLayout.SetAnimateLayout(true);
163 DevelControl::SetLayout( mLinearContainer, vboxLayout );