Updated demos to use DALi clang-format
[platform/core/uifw/dali-demo.git] / examples / transitions / transition-application.cpp
index 1a3c291..d8e2ae2 100644 (file)
@@ -26,9 +26,9 @@
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/controls/control-devel.h>
 #include <dali-toolkit/devel-api/controls/table-view/table-view.h>
-#include "shadow-button.h"
 #include <cstdio>
 #include <sstream>
+#include "shadow-button.h"
 
 // Internal includes
 
@@ -37,147 +37,144 @@ using namespace Dali::Toolkit;
 
 namespace
 {
-
-void SetLabelText( Button button, const char* label )
+void SetLabelText(Button button, const char* label)
 {
-  button.SetProperty( Toolkit::Button::Property::LABEL, label );
+  button.SetProperty(Toolkit::Button::Property::LABEL, label);
 }
 
-}
+} // namespace
 
 namespace Demo
 {
+const char* TransitionApplication::DEMO_THEME_ONE_PATH(DEMO_STYLE_DIR "style-example-theme-one.json");
+const char* TransitionApplication::DEMO_THEME_TWO_PATH(DEMO_STYLE_DIR "style-example-theme-two.json");
 
-const char* TransitionApplication::DEMO_THEME_ONE_PATH( DEMO_STYLE_DIR "style-example-theme-one.json" );
-const char* TransitionApplication::DEMO_THEME_TWO_PATH( DEMO_STYLE_DIR "style-example-theme-two.json" );
-
-
-TransitionApplication::TransitionApplication( Application& application )
-: mApplication( application ),
+TransitionApplication::TransitionApplication(Application& application)
+: mApplication(application),
   mTitle(),
   mShadowButton(),
   mActionButtons(),
-  mVisualIndex( Property::INVALID_INDEX ),
-  mActionIndex( Property::INVALID_INDEX )
+  mVisualIndex(Property::INVALID_INDEX),
+  mActionIndex(Property::INVALID_INDEX)
 {
-  application.InitSignal().Connect( this, &TransitionApplication::Create );
+  application.InitSignal().Connect(this, &TransitionApplication::Create);
 }
 
 TransitionApplication::~TransitionApplication()
 {
 }
 
-void TransitionApplication::Create( Application& application )
+void TransitionApplication::Create(Application& application)
 {
   Window window = application.GetWindow();
   window.KeyEventSignal().Connect(this, &TransitionApplication::OnKeyEvent);
-  window.SetBackgroundColor( Vector4( 0.1f, 0.1f, 0.1f, 1.0f ) );
+  window.SetBackgroundColor(Vector4(0.1f, 0.1f, 0.1f, 1.0f));
 
   // Content panes:
-  TableView contentLayout = TableView::New( 3, 1 );
-  contentLayout.SetProperty( Dali::Actor::Property::NAME,"ContentLayout");
-  contentLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-  contentLayout.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
-  contentLayout.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
-  contentLayout.SetCellPadding( Vector2( 0.0f, 5.0f ) );
-  contentLayout.SetBackgroundColor( Vector4(0.949, 0.949, 0.949, 1.0) );
+  TableView contentLayout = TableView::New(3, 1);
+  contentLayout.SetProperty(Dali::Actor::Property::NAME, "ContentLayout");
+  contentLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
+  contentLayout.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
+  contentLayout.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT);
+  contentLayout.SetCellPadding(Vector2(0.0f, 5.0f));
+  contentLayout.SetBackgroundColor(Vector4(0.949, 0.949, 0.949, 1.0));
   // Assign all rows the size negotiation property of fitting to children
 
-  window.Add( contentLayout );
+  window.Add(contentLayout);
 
-  mTitle = TextLabel::New( "Custom Control Transition Example" );
-  mTitle.SetProperty( Dali::Actor::Property::NAME, "Title" );
+  mTitle = TextLabel::New("Custom Control Transition Example");
+  mTitle.SetProperty(Dali::Actor::Property::NAME, "Title");
   mTitle.SetStyleName("Title");
-  mTitle.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
-  mTitle.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
-  mTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER" );
-  contentLayout.Add( mTitle );
+  mTitle.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
+  mTitle.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
+  mTitle.SetProperty(TextLabel::Property::HORIZONTAL_ALIGNMENT, "CENTER");
+  contentLayout.Add(mTitle);
   contentLayout.SetFitHeight(0); // Fill width
 
   // Provide some padding around the center cell
-  TableView buttonLayout = TableView::New( 3, 3 );
-  buttonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-  buttonLayout.SetFixedHeight(1, 100 );
-  buttonLayout.SetFixedWidth(1, 350 );
-  contentLayout.Add( buttonLayout );
+  TableView buttonLayout = TableView::New(3, 3);
+  buttonLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
+  buttonLayout.SetFixedHeight(1, 100);
+  buttonLayout.SetFixedWidth(1, 350);
+  contentLayout.Add(buttonLayout);
 
   mShadowButton = ShadowButton::New();
-  mShadowButton.SetProperty( Dali::Actor::Property::NAME,"ShadowButton");
-  mShadowButton.SetActiveState( false );
-  mShadowButton.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER );
-  mShadowButton.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
-  mShadowButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
-  mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::DISABLED );
-  mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "UNCHECKED" );
-
-  buttonLayout.AddChild( mShadowButton, TableView::CellPosition(1, 1) );
-
-  TableView actionButtonLayout = TableView::New( 1, NUMBER_OF_ACTION_BUTTONS+1 );
-  actionButtonLayout.SetProperty( Dali::Actor::Property::NAME,"ThemeButtonsLayout");
-  actionButtonLayout.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
-  actionButtonLayout.SetResizePolicy( ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT );
-  actionButtonLayout.SetFitHeight( 0 );
-
-  TextLabel label = TextLabel::New( "Action: ");
-  label.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS );
+  mShadowButton.SetProperty(Dali::Actor::Property::NAME, "ShadowButton");
+  mShadowButton.SetActiveState(false);
+  mShadowButton.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+  mShadowButton.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
+  mShadowButton.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
+  mShadowButton.SetProperty(DevelControl::Property::STATE, DevelControl::DISABLED);
+  mShadowButton.SetProperty(DevelControl::Property::SUB_STATE, "UNCHECKED");
+
+  buttonLayout.AddChild(mShadowButton, TableView::CellPosition(1, 1));
+
+  TableView actionButtonLayout = TableView::New(1, NUMBER_OF_ACTION_BUTTONS + 1);
+  actionButtonLayout.SetProperty(Dali::Actor::Property::NAME, "ThemeButtonsLayout");
+  actionButtonLayout.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
+  actionButtonLayout.SetResizePolicy(ResizePolicy::FIT_TO_CHILDREN, Dimension::HEIGHT);
+  actionButtonLayout.SetFitHeight(0);
+
+  TextLabel label = TextLabel::New("Action: ");
+  label.SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::ALL_DIMENSIONS);
   label.SetStyleName("ActionLabel");
-  actionButtonLayout.AddChild( label, TableView::CellPosition( 0, 0 ) );
-  actionButtonLayout.SetCellAlignment( TableView::CellPosition( 0, 0 ), HorizontalAlignment::LEFT, VerticalAlignment::CENTER );
+  actionButtonLayout.AddChild(label, TableView::CellPosition(0, 0));
+  actionButtonLayout.SetCellAlignment(TableView::CellPosition(0, 0), HorizontalAlignment::LEFT, VerticalAlignment::CENTER);
 
-  for( int i=0; i<NUMBER_OF_ACTION_BUTTONS; ++i )
+  for(int i = 0; i < NUMBER_OF_ACTION_BUTTONS; ++i)
   {
     mActionButtons[i] = PushButton::New();
-    mActionButtons[i].SetProperty( Dali::Actor::Property::NAME,"ActionButton");
+    mActionButtons[i].SetProperty(Dali::Actor::Property::NAME, "ActionButton");
     mActionButtons[i].SetStyleName("ActionButton");
-    mActionButtons[i].SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
-    mActionButtons[i].SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
-    mActionIndex = mActionButtons[i].RegisterProperty( "actionId", i, Property::READ_WRITE );
-    mActionButtons[i].ClickedSignal().Connect( this, &TransitionApplication::OnActionButtonClicked );
-    actionButtonLayout.AddChild( mActionButtons[i], TableView::CellPosition( 0, 1+i ) );
+    mActionButtons[i].SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH);
+    mActionButtons[i].SetResizePolicy(ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT);
+    mActionIndex = mActionButtons[i].RegisterProperty("actionId", i, Property::READ_WRITE);
+    mActionButtons[i].ClickedSignal().Connect(this, &TransitionApplication::OnActionButtonClicked);
+    actionButtonLayout.AddChild(mActionButtons[i], TableView::CellPosition(0, 1 + i));
   }
-  SetLabelText( mActionButtons[0], "Enable" );
-  SetLabelText( mActionButtons[1], "Check" );
-  mActionButtons[1].SetProperty( Button::Property::DISABLED, true );
+  SetLabelText(mActionButtons[0], "Enable");
+  SetLabelText(mActionButtons[1], "Check");
+  mActionButtons[1].SetProperty(Button::Property::DISABLED, true);
 
-  contentLayout.Add( actionButtonLayout );
+  contentLayout.Add(actionButtonLayout);
   contentLayout.SetFitHeight(2);
 }
 
-bool TransitionApplication::OnActionButtonClicked( Button button )
+bool TransitionApplication::OnActionButtonClicked(Button button)
 {
-  int action = button.GetProperty<int>( mActionIndex );
-  switch( action )
+  int action = button.GetProperty<int>(mActionIndex);
+  switch(action)
   {
     case 0:
     {
       bool activeState = mShadowButton.GetActiveState();
-      mShadowButton.SetActiveState( ! activeState );
-      if( activeState )
+      mShadowButton.SetActiveState(!activeState);
+      if(activeState)
       {
-        SetLabelText( button, "Enable" );
-        mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::DISABLED );
+        SetLabelText(button, "Enable");
+        mShadowButton.SetProperty(DevelControl::Property::STATE, DevelControl::DISABLED);
       }
       else
       {
-        SetLabelText( button, "Disable" );
-        mShadowButton.SetProperty( DevelControl::Property::STATE, DevelControl::NORMAL );
+        SetLabelText(button, "Disable");
+        mShadowButton.SetProperty(DevelControl::Property::STATE, DevelControl::NORMAL);
       }
-      mActionButtons[1].SetProperty( Button::Property::DISABLED, activeState );
+      mActionButtons[1].SetProperty(Button::Property::DISABLED, activeState);
       break;
     }
     case 1:
     {
       bool checkState = mShadowButton.GetCheckState();
-      mShadowButton.SetCheckState( ! checkState );
-      if( checkState )
+      mShadowButton.SetCheckState(!checkState);
+      if(checkState)
       {
-        SetLabelText( button, "Check" );
-        mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "UNCHECKED" );
+        SetLabelText(button, "Check");
+        mShadowButton.SetProperty(DevelControl::Property::SUB_STATE, "UNCHECKED");
       }
       else
       {
-        SetLabelText( button, "Uncheck" );
-        mShadowButton.SetProperty( DevelControl::Property::SUB_STATE, "CHECKED" );
+        SetLabelText(button, "Uncheck");
+        mShadowButton.SetProperty(DevelControl::Property::SUB_STATE, "CHECKED");
       }
       break;
     }
@@ -194,27 +191,27 @@ bool TransitionApplication::OnActionButtonClicked( Button button )
   return true;
 }
 
-void TransitionApplication::OnKeyEvent( const KeyEvent& keyEvent )
+void TransitionApplication::OnKeyEvent(const KeyEvent& keyEvent)
 {
   static int keyPressed = 0;
 
-  if( keyEvent.GetState() == KeyEvent::DOWN)
+  if(keyEvent.GetState() == KeyEvent::DOWN)
   {
-    if( keyPressed == 0 ) // Is this the first down event?
+    if(keyPressed == 0) // Is this the first down event?
     {
-      printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode() );
+      printf("Key pressed: %s %d\n", keyEvent.GetKeyName().c_str(), keyEvent.GetKeyCode());
 
-      if( IsKey( keyEvent, DALI_KEY_ESCAPE) || IsKey( keyEvent, DALI_KEY_BACK ) )
+      if(IsKey(keyEvent, DALI_KEY_ESCAPE) || IsKey(keyEvent, DALI_KEY_BACK))
       {
         mApplication.Quit();
       }
-      else if( keyEvent.GetKeyName().compare("Return") == 0 )
+      else if(keyEvent.GetKeyName().compare("Return") == 0)
       {
       }
     }
     keyPressed = 1;
   }
-  else if( keyEvent.GetState() == KeyEvent::UP )
+  else if(keyEvent.GetState() == KeyEvent::UP)
   {
     keyPressed = 0;
   }