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.
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;
41 const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "lake_front.jpg" );
42 const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
44 typedef std::unique_ptr< Demo::Example > ExamplePointer;
46 typedef std::vector< ExamplePointer > ExampleContainer;
48 /// All layouting examples to be shown should be added to this method
49 void CreateExamples( ExampleContainer& container )
51 container.push_back( ExamplePointer(new Demo::AnimationExample) );
52 container.push_back( ExamplePointer(new Demo::LinearExample) );
53 container.push_back( ExamplePointer(new Demo::PaddingExample) );
54 container.push_back( ExamplePointer(new Demo::AbsoluteExample) );
55 container.push_back( ExamplePointer(new Demo::FlexExample) ) ;
56 container.push_back( ExamplePointer(new Demo::GridExample) ) ;
59 } // anonymous namespace
61 class LayoutingExample: public ConnectionTracker
65 LayoutingExample( Application& application )
66 : mApplication( application ),
70 // Connect to the Application's Init signal
71 mApplication.InitSignal().Connect( this, &LayoutingExample::Create );
76 void Create( Application& application )
78 auto stage = Stage::GetCurrent();
79 stage.KeyEventSignal().Connect( this, &LayoutingExample::OnKeyEvent );
81 auto bg = ImageView::New( BACKGROUND_IMAGE );
82 bg.SetParentOrigin( ParentOrigin::CENTER );
84 auto toolbar = ImageView::New( TOOLBAR_IMAGE );
85 toolbar.SetParentOrigin( ParentOrigin::TOP_CENTER );
86 toolbar.SetAnchorPoint( AnchorPoint::TOP_CENTER );
87 toolbar.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
88 toolbar.SetProperty( Actor::Property::SIZE_HEIGHT, 50.0f);
92 mToolbarTitle = TextLabel::New( "");
93 mToolbarTitle.SetParentOrigin( ParentOrigin::CENTER );
94 mToolbarTitle.SetAnchorPoint( AnchorPoint::CENTER );
95 mToolbarTitle.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
96 mToolbarTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::LEFT );
97 toolbar.Add( mToolbarTitle );
99 mNextLayout = PushButton::New();
100 mNextLayout.SetProperty( Toolkit::Button::Property::LABEL, "change layout");
101 mNextLayout.ClickedSignal().Connect( this, &LayoutingExample::ChangeLayout );
102 mNextLayout.SetParentOrigin( ParentOrigin::TOP_RIGHT );
103 mNextLayout.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
104 mNextLayout.SetSize(175, 50);
105 toolbar.Add( mNextLayout );
107 CreateExamples( mLayoutingExamples );
108 if( ! mLayoutingExamples.empty() )
110 mLayoutingExamples[ mLayoutIndex ]->Create();
111 mToolbarTitle.SetProperty(Toolkit::TextLabel::Property::TEXT, mLayoutingExamples[ mLayoutIndex ]->GetExampleTitle() );
115 bool ChangeLayout( Button button )
117 if( ! mLayoutingExamples.empty() )
119 mLayoutingExamples[ mLayoutIndex ]->Remove();
120 mLayoutIndex = ( mLayoutIndex + 1 ) % mLayoutingExamples.size();
121 mLayoutingExamples[ mLayoutIndex ]->Create();
122 mToolbarTitle.SetProperty(Toolkit::TextLabel::Property::TEXT, mLayoutingExamples[ mLayoutIndex ]->Example::GetExampleTitle() );
128 * Main key event handler
130 void OnKeyEvent(const KeyEvent& event)
132 if(event.state == KeyEvent::Down)
134 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
143 Application& mApplication;
144 ExampleContainer mLayoutingExamples;
145 PushButton mNextLayout;
146 unsigned int mLayoutIndex;
147 TextLabel mToolbarTitle;
150 int DALI_EXPORT_API main( int argc, char **argv )
152 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
153 LayoutingExample test( application );
154 application.MainLoop();