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"
30 #include "absolute-example.h"
33 using namespace Dali::Toolkit;
38 const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "lake_front.jpg" );
39 const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
41 const char* APPLICATION_TITLE( "Layout Tester" );
43 typedef std::unique_ptr< Demo::Example > ExamplePointer;
44 typedef std::vector< ExamplePointer > ExampleContainer;
46 /// All layouting examples to be shown should be added to this method
47 void CreateExamples( ExampleContainer& container )
49 container.push_back( ExamplePointer( new Demo::LinearExample ) );
50 container.push_back( ExamplePointer( new Demo::PaddingExample ) );
51 container.push_back( ExamplePointer( new Demo::AbsoluteExample ) );
54 } // anonymous namespace
56 class LayoutingExample: public ConnectionTracker
60 LayoutingExample( Application& application )
61 : mApplication( application ),
65 // Connect to the Application's Init signal
66 mApplication.InitSignal().Connect( this, &LayoutingExample::Create );
71 void Create( Application& application )
73 auto stage = Stage::GetCurrent();
74 stage.KeyEventSignal().Connect( this, &LayoutingExample::OnKeyEvent );
76 auto bg = ImageView::New( BACKGROUND_IMAGE );
77 bg.SetParentOrigin( ParentOrigin::CENTER );
79 auto toolbar = ImageView::New( TOOLBAR_IMAGE );
80 toolbar.SetParentOrigin( ParentOrigin::TOP_CENTER );
81 toolbar.SetAnchorPoint( AnchorPoint::TOP_CENTER );
82 toolbar.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
83 toolbar.SetProperty( Actor::Property::SIZE_HEIGHT, 50.0f);
87 auto title = TextLabel::New( APPLICATION_TITLE );
88 title.SetParentOrigin( ParentOrigin::CENTER );
89 title.SetAnchorPoint( AnchorPoint::CENTER );
90 title.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
91 title.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::LEFT );
94 mNextLayout = PushButton::New();
95 mNextLayout.SetProperty( Toolkit::Button::Property::LABEL, "change layout");
96 mNextLayout.ClickedSignal().Connect( this, &LayoutingExample::ChangeLayout );
97 mNextLayout.SetParentOrigin( ParentOrigin::TOP_RIGHT );
98 mNextLayout.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
99 mNextLayout.SetSize(175, 50);
100 toolbar.Add( mNextLayout );
102 CreateExamples( mLayoutingExamples );
103 if( ! mLayoutingExamples.empty() )
105 mLayoutingExamples[ mLayoutIndex ]->Create();
109 bool ChangeLayout( Button button )
111 if( ! mLayoutingExamples.empty() )
113 mLayoutingExamples[ mLayoutIndex ]->Remove();
114 mLayoutIndex = ( mLayoutIndex + 1 ) % mLayoutingExamples.size();
115 mLayoutingExamples[ mLayoutIndex ]->Create();
121 * Main key event handler
123 void OnKeyEvent(const KeyEvent& event)
125 if(event.state == KeyEvent::Down)
127 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
136 Application& mApplication;
137 ExampleContainer mLayoutingExamples;
138 PushButton mNextLayout;
139 unsigned int mLayoutIndex;
142 int DALI_EXPORT_API main( int argc, char **argv )
144 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
145 LayoutingExample test( application );
146 application.MainLoop();