2 * Copyright (c) 2016 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.
18 #include "shared/view.h"
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali-toolkit/devel-api/controls/progress-bar/progress-bar.h>
23 using namespace Dali::Toolkit;
24 using Dali::Toolkit::ProgressBar;
29 const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg";
30 const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png";
31 const char* const TOOLBAR_TITLE = "Progress Bar";
33 const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f );
36 const int MARGIN_SIZE = 10;
37 const int TOP_MARGIN = 85;
41 /** This example shows how to create and use PROGRESS BAR.
44 class ProgressBarExample: public ConnectionTracker
48 ProgressBarExample( Application& application )
49 : mApplication( application )
51 // Connect to the Application's Init signal
52 mProgressValue = 0.0f;
53 mApplication.InitSignal().Connect( this, &ProgressBarExample::Create );
61 void Create( Application& application )
63 // The Init signal is received once (only) during the Application lifetime
65 // Respond to key events
66 Stage::GetCurrent().KeyEventSignal().Connect( this, &ProgressBarExample::OnKeyEvent );
68 // Creates a default view with a default tool bar.
69 // The view is added to the stage.
71 mContentLayer = DemoHelper::CreateView( application,
78 mProgressBar = ProgressBar::New();
79 mProgressBar.SetParentOrigin(ParentOrigin::TOP_CENTER);
80 mProgressBar.SetAnchorPoint(AnchorPoint::TOP_CENTER);
81 mProgressBar.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
82 mProgressBar.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
84 Toolkit::TableView contentTable = Toolkit::TableView::New(2, 1);
85 contentTable.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
86 contentTable.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
87 contentTable.SetAnchorPoint(AnchorPoint::TOP_LEFT);
88 contentTable.SetParentOrigin(ParentOrigin::TOP_LEFT);
89 contentTable.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE * 0.5f));
91 for( unsigned int i = 0; i < contentTable.GetRows(); ++i )
93 contentTable.SetFitHeight( i );
96 contentTable.SetPosition( 0.0f, TOP_MARGIN );
97 mContentLayer.Add( contentTable );
99 // Image selector for progress bar
100 Toolkit::TableView progressBackground = Toolkit::TableView::New( 1, 1 );
101 progressBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
102 progressBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
103 progressBackground.SetBackgroundColor( BACKGROUND_COLOUR );
104 progressBackground.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) );
105 progressBackground.SetRelativeWidth( 0, 1.0f );
106 progressBackground.SetFitHeight( 0 );
107 contentTable.Add( progressBackground );
108 progressBackground.Add( mProgressBar );
111 Toolkit::TableView buttonBackground = Toolkit::TableView::New( 2, 1 );
112 buttonBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
113 buttonBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
114 buttonBackground.SetBackgroundColor( BACKGROUND_COLOUR );
115 buttonBackground.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) );
117 for( unsigned int i = 0; i < buttonBackground.GetRows(); ++i )
119 buttonBackground.SetFitHeight( i );
122 contentTable.Add( buttonBackground );
124 mSetProgressButton = Toolkit::PushButton::New();
125 mSetProgressButton.SetLabelText( "Set Progress" );
126 mSetProgressButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
127 mSetProgressButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
128 mSetProgressButton.ClickedSignal().Connect( this, &ProgressBarExample::OnSetProgressButtonSelected );
130 buttonBackground.Add( mSetProgressButton );
132 mResetProgressButton = Toolkit::PushButton::New();
133 mResetProgressButton.SetLabelText( "Reset Progress" );
134 mResetProgressButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
135 mResetProgressButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
136 mResetProgressButton.ClickedSignal().Connect( this, &ProgressBarExample::OnResetProgressButtonSelected );
138 buttonBackground.Add( mResetProgressButton );
141 bool OnResetProgressButtonSelected( Toolkit::Button button )
143 mProgressValue = 0.0f;
144 mProgressBar.SetProperty(ProgressBar::Property::PROGRESS_VALUE, 0.0f);
148 bool OnSetProgressButtonSelected( Toolkit::Button button )
150 mProgressValue += 0.1f;
151 mProgressBar.SetProperty(ProgressBar::Property::PROGRESS_VALUE, mProgressValue);
155 void OnKeyEvent( const KeyEvent& event )
157 if( event.state == KeyEvent::Down )
159 if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
161 // Exit application when click back or escape.
169 Application& mApplication;
170 Toolkit::Control mView; ///< The View instance.
171 Toolkit::ToolBar mToolBar; ///< The View's Toolbar.
172 Layer mContentLayer; ///< Content layer.
173 ProgressBar mProgressBar;
174 Toolkit::PushButton mSetProgressButton;
175 Toolkit::PushButton mResetProgressButton;
176 float mProgressValue;
179 void RunTest( Application& application )
181 ProgressBarExample test( application );
182 application.MainLoop();
185 // Entry point for Linux & Tizen applications
186 int DALI_EXPORT_API main( int argc, char **argv )
188 Application application = Application::New( &argc, &argv, DEMO_THEME_PATH );
190 RunTest( application );