2 * Copyright (c) 2019 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.
21 #include <dali/dali.h>
22 #include <dali-toolkit/dali-toolkit.h>
23 #include <dali-toolkit/devel-api/controls/control-devel.h>
26 #include "shared/view.h"
27 #include "animation-example.h"
28 #include "linear-example.h"
29 #include "padding-example.h"
30 #include "flex-example.h"
31 #include "grid-example.h"
33 #include "absolute-example.h"
36 using namespace Dali::Toolkit;
40 const Property::Value BACKGROUND
42 { Toolkit::Visual::Property::TYPE, Visual::GRADIENT },
43 { GradientVisual::Property::STOP_COLOR, Property::Array{ Vector4( 0.0f, 0.352941176f, 0.654901961f, 1.0f ),
44 Vector4( 1.0f, 0.992156863f, 0.894117647f, 1.0f ) } },
45 { GradientVisual::Property::START_POSITION, Vector2( 0.0f, -0.5f ) },
46 { GradientVisual::Property::END_POSITION, Vector2( 0.0f, 0.5f ) }
49 const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
51 typedef std::unique_ptr< Demo::Example > ExamplePointer;
53 typedef std::vector< ExamplePointer > ExampleContainer;
55 /// All layouting examples to be shown should be added to this method
56 void CreateExamples( ExampleContainer& container )
58 container.push_back( ExamplePointer(new Demo::AnimationExample) );
59 container.push_back( ExamplePointer(new Demo::LinearExample) );
60 container.push_back( ExamplePointer(new Demo::PaddingExample) );
61 container.push_back( ExamplePointer(new Demo::AbsoluteExample) );
62 container.push_back( ExamplePointer(new Demo::FlexExample) ) ;
63 container.push_back( ExamplePointer(new Demo::GridExample) ) ;
66 } // anonymous namespace
68 class LayoutingExample: public ConnectionTracker
72 LayoutingExample( Application& application )
73 : mApplication( application ),
77 // Connect to the Application's Init signal
78 mApplication.InitSignal().Connect( this, &LayoutingExample::Create );
83 void Create( Application& application )
85 auto stage = Stage::GetCurrent();
86 stage.KeyEventSignal().Connect( this, &LayoutingExample::OnKeyEvent );
88 auto bg = Control::New();
89 bg.SetParentOrigin( ParentOrigin::CENTER );
90 bg.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
91 bg.SetProperty( Control::Property::BACKGROUND, BACKGROUND );
93 auto toolbar = ImageView::New( TOOLBAR_IMAGE );
94 toolbar.SetParentOrigin( ParentOrigin::TOP_CENTER );
95 toolbar.SetAnchorPoint( AnchorPoint::TOP_CENTER );
96 toolbar.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
97 toolbar.SetProperty( Actor::Property::SIZE_HEIGHT, 50.0f);
101 mToolbarTitle = TextLabel::New( "");
102 mToolbarTitle.SetParentOrigin( ParentOrigin::CENTER );
103 mToolbarTitle.SetAnchorPoint( AnchorPoint::CENTER );
104 mToolbarTitle.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
105 mToolbarTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::LEFT );
106 toolbar.Add( mToolbarTitle );
108 mNextLayout = PushButton::New();
109 mNextLayout.SetStyleName( "ChangeLayoutButton" );
110 mNextLayout.SetProperty( Toolkit::Button::Property::LABEL, "Change Layout" );
111 mNextLayout.ClickedSignal().Connect( this, &LayoutingExample::ChangeLayout );
112 mNextLayout.SetParentOrigin( ParentOrigin::TOP_RIGHT );
113 mNextLayout.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
114 mNextLayout.SetSize(175, 50);
115 toolbar.Add( mNextLayout );
117 CreateExamples( mLayoutingExamples );
118 if( ! mLayoutingExamples.empty() )
120 mLayoutingExamples[ mLayoutIndex ]->Create();
121 mToolbarTitle.SetProperty(Toolkit::TextLabel::Property::TEXT, mLayoutingExamples[ mLayoutIndex ]->GetExampleTitle() );
125 bool ChangeLayout( Button button )
127 if( ! mLayoutingExamples.empty() )
129 mLayoutingExamples[ mLayoutIndex ]->Remove();
130 mLayoutIndex = ( mLayoutIndex + 1 ) % mLayoutingExamples.size();
131 mLayoutingExamples[ mLayoutIndex ]->Create();
132 mToolbarTitle.SetProperty(Toolkit::TextLabel::Property::TEXT, mLayoutingExamples[ mLayoutIndex ]->Example::GetExampleTitle() );
138 * Main key event handler
140 void OnKeyEvent(const KeyEvent& event)
142 if(event.state == KeyEvent::Down)
144 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
153 Application& mApplication;
154 ExampleContainer mLayoutingExamples;
155 PushButton mNextLayout;
156 unsigned int mLayoutIndex;
157 TextLabel mToolbarTitle;
160 int DALI_EXPORT_API main( int argc, char **argv )
162 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
163 LayoutingExample test( application );
164 application.MainLoop();