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"
29 #include "flex-example.h"
30 #include "grid-example.h"
32 #include "absolute-example.h"
35 using namespace Dali::Toolkit;
40 const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "lake_front.jpg" );
41 const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
43 typedef std::unique_ptr< Demo::Example > ExamplePointer;
45 typedef std::vector< ExamplePointer > ExampleContainer;
47 /// All layouting examples to be shown should be added to this method
48 void CreateExamples( ExampleContainer& container )
50 container.push_back( ExamplePointer(new Demo::LinearExample) );
51 container.push_back( ExamplePointer(new Demo::PaddingExample) );
52 container.push_back( ExamplePointer(new Demo::AbsoluteExample) );
53 container.push_back( ExamplePointer(new Demo::FlexExample) ) ;
54 container.push_back( ExamplePointer(new Demo::GridExample) ) ;
57 } // anonymous namespace
59 class LayoutingExample: public ConnectionTracker
63 LayoutingExample( Application& application )
64 : mApplication( application ),
68 // Connect to the Application's Init signal
69 mApplication.InitSignal().Connect( this, &LayoutingExample::Create );
74 void Create( Application& application )
76 auto stage = Stage::GetCurrent();
77 stage.KeyEventSignal().Connect( this, &LayoutingExample::OnKeyEvent );
79 auto bg = ImageView::New( BACKGROUND_IMAGE );
80 bg.SetParentOrigin( ParentOrigin::CENTER );
82 auto toolbar = ImageView::New( TOOLBAR_IMAGE );
83 toolbar.SetParentOrigin( ParentOrigin::TOP_CENTER );
84 toolbar.SetAnchorPoint( AnchorPoint::TOP_CENTER );
85 toolbar.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
86 toolbar.SetProperty( Actor::Property::SIZE_HEIGHT, 50.0f);
90 mToolbarTitle = TextLabel::New( "");
91 mToolbarTitle.SetParentOrigin( ParentOrigin::CENTER );
92 mToolbarTitle.SetAnchorPoint( AnchorPoint::CENTER );
93 mToolbarTitle.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
94 mToolbarTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::LEFT );
95 toolbar.Add( mToolbarTitle );
97 mNextLayout = PushButton::New();
98 mNextLayout.SetProperty( Toolkit::Button::Property::LABEL, "change layout");
99 mNextLayout.ClickedSignal().Connect( this, &LayoutingExample::ChangeLayout );
100 mNextLayout.SetParentOrigin( ParentOrigin::TOP_RIGHT );
101 mNextLayout.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
102 mNextLayout.SetSize(175, 50);
103 toolbar.Add( mNextLayout );
105 CreateExamples( mLayoutingExamples );
106 if( ! mLayoutingExamples.empty() )
108 mLayoutingExamples[ mLayoutIndex ]->Create();
109 mToolbarTitle.SetProperty(Toolkit::TextLabel::Property::TEXT, mLayoutingExamples[ mLayoutIndex ]->GetExampleTitle() );
113 bool ChangeLayout( Button button )
115 if( ! mLayoutingExamples.empty() )
117 mLayoutingExamples[ mLayoutIndex ]->Remove();
118 mLayoutIndex = ( mLayoutIndex + 1 ) % mLayoutingExamples.size();
119 mLayoutingExamples[ mLayoutIndex ]->Create();
120 mToolbarTitle.SetProperty(Toolkit::TextLabel::Property::TEXT, mLayoutingExamples[ mLayoutIndex ]->Example::GetExampleTitle() );
126 * Main key event handler
128 void OnKeyEvent(const KeyEvent& event)
130 if(event.state == KeyEvent::Down)
132 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
141 Application& mApplication;
142 ExampleContainer mLayoutingExamples;
143 PushButton mNextLayout;
144 unsigned int mLayoutIndex;
145 TextLabel mToolbarTitle;
148 int DALI_EXPORT_API main( int argc, char **argv )
150 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
151 LayoutingExample test( application );
152 application.MainLoop();