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 auto stage = Stage::GetCurrent();
76 mDirectionButton = PushButton::New();
77 mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, RTL_IMAGE );
78 mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, RTL_SELECTED_IMAGE );
79 mDirectionButton.ClickedSignal().Connect( this, &LinearExample::OnDirectionClicked );
80 mDirectionButton.SetParentOrigin( Vector3(0.33f, 1.0f, 0.5f ) );
81 mDirectionButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
82 mDirectionButton.SetSize(75, 75);
83 stage.Add( mDirectionButton );
85 mRotateButton = PushButton::New();
86 mRotateButton.SetProperty( PushButton::Property::UNSELECTED_ICON, ROTATE_CLOCKWISE_IMAGE );
87 mRotateButton.SetProperty( PushButton::Property::SELECTED_ICON, ROTATE_CLOCKWISE_SELECTED_IMAGE );
88 mRotateButton.ClickedSignal().Connect( this, &LinearExample::OnRotateClicked );
89 mRotateButton.SetParentOrigin( Vector3(0.66f, 1.0f, 0.5f ));
90 mRotateButton.SetAnchorPoint( Vector3(0.5f, 1.0f, 0.5f));
91 mRotateButton.SetSize(75, 75);
92 stage.Add( mRotateButton );
94 // Create a linear layout
95 mLinearContainer = Control::New();
96 mIsHorizontal = false;
98 auto layout = VboxLayout::New();
99 layout.SetAnimateLayout(true);
100 DevelControl::SetLayout( mLinearContainer, layout );
102 mLinearContainer.SetParentOrigin( ParentOrigin::CENTER );
103 mLinearContainer.SetAnchorPoint( AnchorPoint::CENTER );
104 mLinearContainer.SetName( "LinearExample" );
105 stage.Add( mLinearContainer );
106 mLinearContainer.SetProperty( Toolkit::LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
107 mLinearContainer.SetProperty( Toolkit::LayoutItem::ChildProperty::HEIGHT_SPECIFICATION, ChildLayoutData::MATCH_PARENT );
108 mLinearContainer.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::LEFT_TO_RIGHT );
110 for( unsigned int x = 0; x < NUMBER_OF_RESOURCES; ++x )
112 Toolkit::ImageView imageView;
113 CreateChildImageView( imageView, IMAGE_PATH[ x ], Size(100.0f, 100.0f) );
114 mLinearContainer.Add( imageView );
118 // Remove controls added by this example from stage
119 void LinearExample::Remove()
121 if ( mLinearContainer )
123 UnparentAndReset( mDirectionButton );
124 UnparentAndReset( mRotateButton );
125 UnparentAndReset( mLinearContainer);
129 // Mirror items in layout
130 bool LinearExample::OnDirectionClicked( Button button )
134 mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, LTR_IMAGE );
135 mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, LTR_SELECTED_IMAGE );
136 mLinearContainer.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::LEFT_TO_RIGHT );
140 mDirectionButton.SetProperty( PushButton::Property::UNSELECTED_ICON, RTL_IMAGE );
141 mDirectionButton.SetProperty( PushButton::Property::SELECTED_ICON, RTL_SELECTED_IMAGE );
142 mLinearContainer.SetProperty( Actor::Property::LAYOUT_DIRECTION, LayoutDirection::RIGHT_TO_LEFT );
144 mDirection = !mDirection;
148 // Rotate layout by changing layout
149 bool LinearExample::OnRotateClicked( Button button )
151 mIsHorizontal = !mIsHorizontal;
154 auto hboxLayout = HboxLayout::New();
155 hboxLayout.SetAnimateLayout(true);
156 DevelControl::SetLayout( mLinearContainer, hboxLayout );
160 auto vboxLayout = VboxLayout::New();
161 vboxLayout.SetAnimateLayout(true);
162 DevelControl::SetLayout( mLinearContainer, vboxLayout );