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 "linear-example.h"
28 #include "padding-example.h"
32 using namespace Dali::Toolkit;
37 const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "lake_front.jpg" );
38 const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
40 const char* APPLICATION_TITLE( "Layout Tester" );
42 typedef std::unique_ptr< Demo::Example > ExamplePointer;
43 typedef std::vector< ExamplePointer > ExampleContainer;
45 /// All layouting examples to be shown should be added to this method
46 void CreateExamples( ExampleContainer& container )
48 container.push_back( ExamplePointer( new Demo::LinearExample ) );
49 container.push_back( ExamplePointer( new Demo::PaddingExample ) );
52 } // anonymous namespace
54 class LayoutingExample: public ConnectionTracker
58 LayoutingExample( Application& application )
59 : mApplication( application ),
63 // Connect to the Application's Init signal
64 mApplication.InitSignal().Connect( this, &LayoutingExample::Create );
69 void Create( Application& application )
71 auto stage = Stage::GetCurrent();
72 stage.KeyEventSignal().Connect( this, &LayoutingExample::OnKeyEvent );
74 auto bg = ImageView::New( BACKGROUND_IMAGE );
75 bg.SetParentOrigin( ParentOrigin::CENTER );
77 auto toolbar = ImageView::New( TOOLBAR_IMAGE );
78 toolbar.SetParentOrigin( ParentOrigin::TOP_CENTER );
79 toolbar.SetAnchorPoint( AnchorPoint::TOP_CENTER );
80 toolbar.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
81 toolbar.SetProperty( Actor::Property::SIZE_HEIGHT, 50.0f);
85 auto title = TextLabel::New( APPLICATION_TITLE );
86 title.SetParentOrigin( ParentOrigin::CENTER );
87 title.SetAnchorPoint( AnchorPoint::CENTER );
88 title.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
89 title.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::LEFT );
92 mNextLayout = PushButton::New();
93 mNextLayout.SetProperty( Toolkit::Button::Property::LABEL, "change layout");
94 mNextLayout.ClickedSignal().Connect( this, &LayoutingExample::ChangeLayout );
95 mNextLayout.SetParentOrigin( ParentOrigin::TOP_RIGHT );
96 mNextLayout.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
97 mNextLayout.SetSize(175, 50);
98 toolbar.Add( mNextLayout );
100 CreateExamples( mLayoutingExamples );
101 if( ! mLayoutingExamples.empty() )
103 mLayoutingExamples[ mLayoutIndex ]->Create();
107 bool ChangeLayout( Button button )
109 if( ! mLayoutingExamples.empty() )
111 mLayoutingExamples[ mLayoutIndex ]->Remove();
112 mLayoutIndex = ( mLayoutIndex + 1 ) % mLayoutingExamples.size();
113 mLayoutingExamples[ mLayoutIndex ]->Create();
119 * Main key event handler
121 void OnKeyEvent(const KeyEvent& event)
123 if(event.state == KeyEvent::Down)
125 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
134 Application& mApplication;
135 ExampleContainer mLayoutingExamples;
136 PushButton mNextLayout;
137 unsigned int mLayoutIndex;
140 int DALI_EXPORT_API main( int argc, char **argv )
142 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
143 LayoutingExample test( application );
144 application.MainLoop();