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();
63 stage.KeyEventSignal().Connect( this, &LayoutingExample::OnKeyEvent );
65 auto bg = ImageView::New( BACKGROUND_IMAGE );
66 bg.SetParentOrigin( ParentOrigin::CENTER );
68 auto toolbar = ImageView::New( TOOLBAR_IMAGE );
69 toolbar.SetParentOrigin( ParentOrigin::TOP_CENTER );
70 toolbar.SetAnchorPoint( AnchorPoint::TOP_CENTER );
71 toolbar.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
72 toolbar.SetProperty( Actor::Property::SIZE_HEIGHT, 50.0f);
76 auto title = TextLabel::New( APPLICATION_TITLE );
77 title.SetParentOrigin( ParentOrigin::CENTER );
78 title.SetAnchorPoint( AnchorPoint::CENTER );
79 title.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
80 title.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::LEFT );
83 mNextLayout = PushButton::New();
84 mNextLayout.SetProperty( Toolkit::Button::Property::LABEL, "change layout");
85 mNextLayout.ClickedSignal().Connect( this, &LayoutingExample::ChangeLayout );
86 mNextLayout.SetParentOrigin( ParentOrigin::TOP_RIGHT );
87 mNextLayout.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
88 mNextLayout.SetSize(175, 50);
89 toolbar.Add( mNextLayout );
91 mLinearExample.Demo::LinearExample::Create();
94 bool ChangeLayout( Button button )
98 switch( mLayoutIndex )
102 mLinearExample.Remove();
103 mPaddedExample.Create();
108 mPaddedExample.Remove();
109 mNextLayout.SetProperty( Toolkit::Button::Property::LABEL, "end of test");
110 mNextLayout.SetProperty( Toolkit::Button::Property::DISABLED, true );
124 * Main key event handler
126 void OnKeyEvent(const KeyEvent& event)
128 if(event.state == KeyEvent::Down)
130 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
139 Application& mApplication;
140 Demo::LinearExample mLinearExample;
141 Demo::PaddingExample mPaddedExample;
142 PushButton mNextLayout;
143 unsigned int mLayoutIndex;
146 int DALI_EXPORT_API main( int argc, char **argv )
148 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
149 LayoutingExample test( application );
150 application.MainLoop();