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.
19 #include "shared/view.h"
20 #include "linear-example.h"
21 #include "padding-example.h"
22 #include <dali/dali.h>
23 #include <dali-toolkit/dali-toolkit.h>
24 #include <dali-toolkit/devel-api/controls/control-devel.h>
27 using namespace Dali::Toolkit;
32 const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "lake_front.jpg" );
33 const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
35 const char* APPLICATION_TITLE( "Layout tester" );
39 class LayoutingExample: public ConnectionTracker
43 LayoutingExample( Application& application )
44 : mApplication( application ),
49 // Connect to the Application's Init signal
50 mApplication.InitSignal().Connect( this, &LayoutingExample::Create );
58 void Create( Application& application )
60 // The Init signal is received once (only) during the Application lifetime
62 auto stage = Stage::GetCurrent();
64 auto bg = ImageView::New( BACKGROUND_IMAGE );
65 bg.SetParentOrigin( ParentOrigin::CENTER );
67 auto toolbar = ImageView::New( TOOLBAR_IMAGE );
68 toolbar.SetParentOrigin( ParentOrigin::TOP_CENTER );
69 toolbar.SetAnchorPoint( AnchorPoint::TOP_CENTER );
70 toolbar.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
71 toolbar.SetProperty( Actor::Property::SIZE_HEIGHT, 50.0f);
75 auto title = TextLabel::New( APPLICATION_TITLE );
76 title.SetParentOrigin( ParentOrigin::CENTER );
77 title.SetAnchorPoint( AnchorPoint::CENTER );
78 title.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
79 title.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::LEFT );
82 mNextLayout = PushButton::New();
83 mNextLayout.SetProperty( Toolkit::Button::Property::LABEL, "change layout");
84 mNextLayout.ClickedSignal().Connect( this, &LayoutingExample::ChangeLayout );
85 mNextLayout.SetParentOrigin( ParentOrigin::TOP_RIGHT );
86 mNextLayout.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
87 mNextLayout.SetSize(175, 50);
88 toolbar.Add( mNextLayout );
90 mLinearExample.Demo::LinearExample::Create();
93 bool ChangeLayout( Button button )
97 switch( mLayoutIndex )
101 mLinearExample.Remove();
102 mPaddedExample.Create();
107 mPaddedExample.Remove();
108 mNextLayout.SetProperty( Toolkit::Button::Property::LABEL, "end of test");
109 mNextLayout.SetProperty( Toolkit::Button::Property::DISABLED, true );
123 * Main key event handler
125 void OnKeyEvent(const KeyEvent& event)
127 if(event.state == KeyEvent::Down)
129 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
138 Application& mApplication;
139 Demo::LinearExample mLinearExample;
140 Demo::PaddingExample mPaddedExample;
141 PushButton mNextLayout;
142 unsigned int mLayoutIndex;
145 int DALI_EXPORT_API main( int argc, char **argv )
147 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
148 LayoutingExample test( application );
149 application.MainLoop();