Updated demos to use DALi clang-format
[platform/core/uifw/dali-demo.git] / examples / progress-bar / progress-bar-example.cpp
index 30864e5..e45478a 100644 (file)
  *
  */
 
-#include "shared/view.h"
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/controls/progress-bar/progress-bar-devel.h>
 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
+#include "shared/view.h"
 
 using namespace Dali;
 using namespace Dali::Toolkit;
@@ -26,145 +26,143 @@ using Dali::Toolkit::ProgressBar;
 
 namespace
 {
-const char * const THEME_PATH( DEMO_STYLE_DIR "progress-bar-example-theme.json" ); ///< The theme used for this example
+const char* const THEME_PATH(DEMO_STYLE_DIR "progress-bar-example-theme.json"); ///< The theme used for this example
 const char* const BACKGROUND_IMAGE = DEMO_IMAGE_DIR "background-gradient.jpg";
-const char* const TOOLBAR_IMAGE = DEMO_IMAGE_DIR "top-bar.png";
-const char* const TOOLBAR_TITLE = "Progress Bar";
+const char* const TOOLBAR_IMAGE    = DEMO_IMAGE_DIR "top-bar.png";
+const char* const TOOLBAR_TITLE    = "Progress Bar";
 
-const Vector4 BACKGROUND_COLOUR( 1.0f, 1.0f, 1.0f, 0.15f );
+const Vector4 BACKGROUND_COLOUR(1.0f, 1.0f, 1.0f, 0.15f);
 
 // Layout sizes
-const int MARGIN_SIZE = 10;
-const int TOP_MARGIN = 85;
+const int MARGIN_SIZE                = 10;
+const int TOP_MARGIN                 = 85;
 const int CIRCULAR_PROGRESS_BAR_SIZE = 64;
 
-const unsigned int TIMER_TIMEOUT_TIME = 50;
-const float PROGRESS_INCREMENT_VALUE = 0.01f;
+const unsigned int TIMER_TIMEOUT_TIME       = 50;
+const float        PROGRESS_INCREMENT_VALUE = 0.01f;
 
-}  // namespace
+} // namespace
 
 /**
  * @brief Shows how to create a default progress bar and custom styled progress bars.
  */
-class ProgressBarExample: public ConnectionTracker
+class ProgressBarExample : public ConnectionTracker
 {
 public:
-
-  ProgressBarExample( Application& application )
-    : mApplication( application )
+  ProgressBarExample(Application& application)
+  : mApplication(application)
   {
     // Connect to the Application's Init signal
-    mProgressValue = 0.0f;
+    mProgressValue          = 0.0f;
     mSecondaryProgressValue = 0.1f;
-    isDefaultTheme = true;
-    mApplication.InitSignal().Connect( this, &ProgressBarExample::Create );
+    isDefaultTheme          = true;
+    mApplication.InitSignal().Connect(this, &ProgressBarExample::Create);
   }
 
 private:
-
-  void Create( Application& application )
+  void Create(Application& application)
   {
     // The Init signal is received once (only) during the Application lifetime
 
     // Respond to key events
-    application.GetWindow().KeyEventSignal().Connect( this, &ProgressBarExample::OnKeyEvent );
+    application.GetWindow().KeyEventSignal().Connect(this, &ProgressBarExample::OnKeyEvent);
 
     // Creates a default view with a default tool bar.
     // The view is added to the window.
 
-    mContentLayer = DemoHelper::CreateView( application,
-                                            mView,
-                                            mToolBar,
-                                            BACKGROUND_IMAGE,
-                                            TOOLBAR_IMAGE,
-                                            TOOLBAR_TITLE );
+    mContentLayer = DemoHelper::CreateView(application,
+                                           mView,
+                                           mToolBar,
+                                           BACKGROUND_IMAGE,
+                                           TOOLBAR_IMAGE,
+                                           TOOLBAR_TITLE);
 
     mProgressBarDefault = ProgressBar::New();
-    mProgressBarDefault.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_CENTER);
-    mProgressBarDefault.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_CENTER);
+    mProgressBarDefault.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER);
+    mProgressBarDefault.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
     mProgressBarDefault.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
     mProgressBarDefault.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
-    mProgressBarDefault.ValueChangedSignal().Connect( this, &ProgressBarExample::OnValueChanged );
+    mProgressBarDefault.ValueChangedSignal().Connect(this, &ProgressBarExample::OnValueChanged);
 
     // Creates a progress bar in circular style
-    mProgressBarCircular = DevelProgressBar::New( DevelProgressBar::Style::CIRCULAR );
-    mProgressBarCircular.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER );
-    mProgressBarCircular.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER );
-    mProgressBarCircular.SetProperty( Actor::Property::SIZE, Vector2( CIRCULAR_PROGRESS_BAR_SIZE, CIRCULAR_PROGRESS_BAR_SIZE ) );
+    mProgressBarCircular = DevelProgressBar::New(DevelProgressBar::Style::CIRCULAR);
+    mProgressBarCircular.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_CENTER);
+    mProgressBarCircular.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_CENTER);
+    mProgressBarCircular.SetProperty(Actor::Property::SIZE, Vector2(CIRCULAR_PROGRESS_BAR_SIZE, CIRCULAR_PROGRESS_BAR_SIZE));
 
     Toolkit::TableView contentTable = Toolkit::TableView::New(2, 1);
     contentTable.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
     contentTable.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
-    contentTable.SetProperty( Actor::Property::ANCHOR_POINT,AnchorPoint::TOP_LEFT);
-    contentTable.SetProperty( Actor::Property::PARENT_ORIGIN,ParentOrigin::TOP_LEFT);
+    contentTable.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+    contentTable.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
     contentTable.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE * 0.5f));
 
-    for( unsigned int i = 0; i < contentTable.GetRows(); ++i )
+    for(unsigned int i = 0; i < contentTable.GetRows(); ++i)
     {
-      contentTable.SetFitHeight( i );
+      contentTable.SetFitHeight(i);
     }
 
-    contentTable.SetProperty( Actor::Property::POSITION, Vector2( 0.0f, TOP_MARGIN ));
-    mContentLayer.Add( contentTable );
+    contentTable.SetProperty(Actor::Property::POSITION, Vector2(0.0f, TOP_MARGIN));
+    mContentLayer.Add(contentTable);
 
     // Image selector for progress bar
-    Toolkit::TableView progressBackground = Toolkit::TableView::New( 2, 1 );
-    progressBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
-    progressBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
-    progressBackground.SetBackgroundColor( BACKGROUND_COLOUR );
-    progressBackground.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) );
-    progressBackground.SetRelativeWidth( 0, 1.0f );
-
-    for( unsigned int i = 0; i < progressBackground.GetRows(); ++i )
+    Toolkit::TableView progressBackground = Toolkit::TableView::New(2, 1);
+    progressBackground.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
+    progressBackground.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
+    progressBackground.SetBackgroundColor(BACKGROUND_COLOUR);
+    progressBackground.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE));
+    progressBackground.SetRelativeWidth(0, 1.0f);
+
+    for(unsigned int i = 0; i < progressBackground.GetRows(); ++i)
     {
-      progressBackground.SetFitHeight( i );
+      progressBackground.SetFitHeight(i);
     }
 
-    contentTable.Add( progressBackground );
-    progressBackground.Add( mProgressBarDefault );
-    progressBackground.Add( mProgressBarCircular );
+    contentTable.Add(progressBackground);
+    progressBackground.Add(mProgressBarDefault);
+    progressBackground.Add(mProgressBarCircular);
 
     // Create buttons
-    Toolkit::TableView buttonBackground = Toolkit::TableView::New( 3, 1 );
-    buttonBackground.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
-    buttonBackground.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
-    buttonBackground.SetBackgroundColor( BACKGROUND_COLOUR );
-    buttonBackground.SetCellPadding( Size( MARGIN_SIZE, MARGIN_SIZE ) );
+    Toolkit::TableView buttonBackground = Toolkit::TableView::New(3, 1);
+    buttonBackground.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
+    buttonBackground.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
+    buttonBackground.SetBackgroundColor(BACKGROUND_COLOUR);
+    buttonBackground.SetCellPadding(Size(MARGIN_SIZE, MARGIN_SIZE));
 
-    for( unsigned int i = 0; i < buttonBackground.GetRows(); ++i )
+    for(unsigned int i = 0; i < buttonBackground.GetRows(); ++i)
     {
-      buttonBackground.SetFitHeight( i );
+      buttonBackground.SetFitHeight(i);
     }
 
-    contentTable.Add( buttonBackground );
+    contentTable.Add(buttonBackground);
 
     mResetProgressButton = Toolkit::PushButton::New();
-    mResetProgressButton.SetProperty( Toolkit::Button::Property::LABEL, "Reset" );
-    mResetProgressButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
-    mResetProgressButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
-    mResetProgressButton.ClickedSignal().Connect( this, &ProgressBarExample::OnResetProgressButtonSelected );
+    mResetProgressButton.SetProperty(Toolkit::Button::Property::LABEL, "Reset");
+    mResetProgressButton.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
+    mResetProgressButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
+    mResetProgressButton.ClickedSignal().Connect(this, &ProgressBarExample::OnResetProgressButtonSelected);
 
-    buttonBackground.Add( mResetProgressButton );
+    buttonBackground.Add(mResetProgressButton);
 
     mSetIndeterminateButton = Toolkit::PushButton::New();
-    mSetIndeterminateButton.SetProperty( Toolkit::Button::Property::LABEL, "Toggle Indeterminate" );
-    mSetIndeterminateButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
-    mSetIndeterminateButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
-    mSetIndeterminateButton.ClickedSignal().Connect( this, &ProgressBarExample::OnSetIndeterminateButtonSelected );
+    mSetIndeterminateButton.SetProperty(Toolkit::Button::Property::LABEL, "Toggle Indeterminate");
+    mSetIndeterminateButton.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
+    mSetIndeterminateButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
+    mSetIndeterminateButton.ClickedSignal().Connect(this, &ProgressBarExample::OnSetIndeterminateButtonSelected);
 
-    buttonBackground.Add( mSetIndeterminateButton );
+    buttonBackground.Add(mSetIndeterminateButton);
 
     mChangeThemeButton = Toolkit::PushButton::New();
-    mChangeThemeButton.SetProperty( Toolkit::Button::Property::LABEL, "Change Theme" );
-    mChangeThemeButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
-    mChangeThemeButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
-    mChangeThemeButton.ClickedSignal().Connect( this, &ProgressBarExample::OnChangeThemeButtonSelected );
+    mChangeThemeButton.SetProperty(Toolkit::Button::Property::LABEL, "Change Theme");
+    mChangeThemeButton.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
+    mChangeThemeButton.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
+    mChangeThemeButton.ClickedSignal().Connect(this, &ProgressBarExample::OnChangeThemeButtonSelected);
 
-    buttonBackground.Add( mChangeThemeButton );
+    buttonBackground.Add(mChangeThemeButton);
 
     // Create a timer to update the progress of all progress bars
-    mTimer = Timer::New( TIMER_TIMEOUT_TIME );
-    mTimer.TickSignal().Connect( this, &ProgressBarExample::OnTimerTick );
+    mTimer = Timer::New(TIMER_TIMEOUT_TIME);
+    mTimer.TickSignal().Connect(this, &ProgressBarExample::OnTimerTick);
     mTimer.Start();
   }
 
@@ -174,55 +172,55 @@ private:
     mSecondaryProgressValue = mProgressValue + 0.1f;
     mProgressBarDefault.SetProperty(ProgressBar::Property::PROGRESS_VALUE, mProgressValue);
     mProgressBarDefault.SetProperty(ProgressBar::Property::SECONDARY_PROGRESS_VALUE, mSecondaryProgressValue);
-    mProgressBarCircular.SetProperty( ProgressBar::Property::PROGRESS_VALUE, mProgressValue );
-    mProgressBarCircular.SetProperty( ProgressBar::Property::SECONDARY_PROGRESS_VALUE, mSecondaryProgressValue );
+    mProgressBarCircular.SetProperty(ProgressBar::Property::PROGRESS_VALUE, mProgressValue);
+    mProgressBarCircular.SetProperty(ProgressBar::Property::SECONDARY_PROGRESS_VALUE, mSecondaryProgressValue);
 
-    return ( mProgressValue < 1.0f ); // Only call again if progress has NOT got to the end
+    return (mProgressValue < 1.0f); // Only call again if progress has NOT got to the end
   }
 
-  bool OnResetProgressButtonSelected( Toolkit::Button button )
+  bool OnResetProgressButtonSelected(Toolkit::Button button)
   {
-    mProgressValue = 0.0f;
+    mProgressValue          = 0.0f;
     mSecondaryProgressValue = 0.1f;
     mProgressBarDefault.SetProperty(ProgressBar::Property::PROGRESS_VALUE, 0.0f);
     mProgressBarDefault.SetProperty(ProgressBar::Property::SECONDARY_PROGRESS_VALUE, 0.1f);
-    mProgressBarCircular.SetProperty( ProgressBar::Property::PROGRESS_VALUE, 0.0f );
-    mProgressBarCircular.SetProperty( ProgressBar::Property::SECONDARY_PROGRESS_VALUE, 0.1f );
+    mProgressBarCircular.SetProperty(ProgressBar::Property::PROGRESS_VALUE, 0.0f);
+    mProgressBarCircular.SetProperty(ProgressBar::Property::SECONDARY_PROGRESS_VALUE, 0.1f);
     mTimer.Start();
     return true;
   }
 
-  void OnValueChanged( ProgressBar progressBar, float value, float secondaryValue )
+  void OnValueChanged(ProgressBar progressBar, float value, float secondaryValue)
   {
     std::stringstream newLabel;
-    newLabel.precision( 2 );
-    newLabel << std::fixed << "current : " << value << " / loaded : "  << secondaryValue;
+    newLabel.precision(2);
+    newLabel << std::fixed << "current : " << value << " / loaded : " << secondaryValue;
 
-    mProgressBarDefault.SetProperty(ProgressBar::Property::LABEL_VISUAL, newLabel.str() );
+    mProgressBarDefault.SetProperty(ProgressBar::Property::LABEL_VISUAL, newLabel.str());
   }
 
-  bool OnSetIndeterminateButtonSelected( Toolkit::Button button )
+  bool OnSetIndeterminateButtonSelected(Toolkit::Button button)
   {
-    if( mProgressBarDefault.GetProperty<bool>(ProgressBar::Property::INDETERMINATE))
+    if(mProgressBarDefault.GetProperty<bool>(ProgressBar::Property::INDETERMINATE))
     {
       mProgressBarDefault.SetProperty(ProgressBar::Property::INDETERMINATE, false);
-      mProgressBarCircular.SetProperty( ProgressBar::Property::INDETERMINATE, false );
+      mProgressBarCircular.SetProperty(ProgressBar::Property::INDETERMINATE, false);
     }
     else
     {
       mProgressBarDefault.SetProperty(ProgressBar::Property::INDETERMINATE, true);
-      mProgressBarCircular.SetProperty( ProgressBar::Property::INDETERMINATE, true );
+      mProgressBarCircular.SetProperty(ProgressBar::Property::INDETERMINATE, true);
     }
     return true;
   }
 
-  bool OnChangeThemeButtonSelected( Toolkit::Button button )
+  bool OnChangeThemeButtonSelected(Toolkit::Button button)
   {
     StyleManager styleManager = StyleManager::Get();
 
-    if( isDefaultTheme )
+    if(isDefaultTheme)
     {
-      styleManager.ApplyTheme( THEME_PATH );
+      styleManager.ApplyTheme(THEME_PATH);
       isDefaultTheme = false;
     }
     else
@@ -232,11 +230,11 @@ private:
     }
     return true;
   }
-  void OnKeyEvent( const KeyEvent& event )
+  void OnKeyEvent(const KeyEvent& event)
   {
-    if( event.GetState() == KeyEvent::DOWN )
+    if(event.GetState() == KeyEvent::DOWN)
     {
-      if( IsKey( event, Dali::DALI_KEY_ESCAPE ) || IsKey( event, Dali::DALI_KEY_BACK ) )
+      if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
       {
         // Exit application when click back or escape.
         mApplication.Quit();
@@ -246,25 +244,25 @@ private:
 
   // Data
 
-  Application&      mApplication;
-  Timer             mTimer;
-  Toolkit::Control  mView;                              ///< The View instance.
-  Toolkit::ToolBar  mToolBar;                           ///< The View's Toolbar.
-  Layer             mContentLayer;                      ///< Content layer.
-  ProgressBar       mProgressBarDefault;
-  ProgressBar       mProgressBarCircular;
+  Application&        mApplication;
+  Timer               mTimer;
+  Toolkit::Control    mView;         ///< The View instance.
+  Toolkit::ToolBar    mToolBar;      ///< The View's Toolbar.
+  Layer               mContentLayer; ///< Content layer.
+  ProgressBar         mProgressBarDefault;
+  ProgressBar         mProgressBarCircular;
   Toolkit::PushButton mResetProgressButton;
   Toolkit::PushButton mSetIndeterminateButton;
   Toolkit::PushButton mChangeThemeButton;
-  float mProgressValue;
-  float mSecondaryProgressValue;
-  bool isDefaultTheme;
+  float               mProgressValue;
+  float               mSecondaryProgressValue;
+  bool                isDefaultTheme;
 };
 
-int DALI_EXPORT_API main( int argc, char **argv )
+int DALI_EXPORT_API main(int argc, char** argv)
 {
-  Application application = Application::New( &argc, &argv );
-  ProgressBarExample test( application );
+  Application        application = Application::New(&argc, &argv);
+  ProgressBarExample test(application);
   application.MainLoop();
   return 0;
 }