(Layouting) Made it easier to add new layouting examples & toggle between all 17/181417/1
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 13 Jun 2018 13:44:19 +0000 (14:44 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Wed, 13 Jun 2018 13:44:19 +0000 (14:44 +0100)
Change-Id: I18c43c68c43b5c29dda121d7c2ea55af562304cf

examples/layouting/example.h [new file with mode: 0644]
examples/layouting/layouting-examples.cpp
examples/layouting/linear-example.h
examples/layouting/padding-example.cpp
examples/layouting/padding-example.h

diff --git a/examples/layouting/example.h b/examples/layouting/example.h
new file mode 100644 (file)
index 0000000..d0a15f0
--- /dev/null
@@ -0,0 +1,42 @@
+#ifndef DALI_DEMO_LAYOUTING_EXAMPLE_H
+#define DALI_DEMO_LAYOUTING_EXAMPLE_H
+
+/*
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+namespace Demo
+{
+
+/**
+ * @brief Abstract base class for layouting examples.
+ */
+class Example
+{
+public:
+  /// Should be overridden by deriving classes to create the required Layouting example
+  virtual void Create() = 0;
+
+  /// Should be overridden by deriving classes to remove their layouting example from stage
+  virtual void Remove() = 0;
+
+  /// Virtual destructor
+  virtual ~Example() = default;
+};
+
+} // namespace Demo
+
+#endif // DALI_DEMO_LAYOUTING_EXAMPLE_H
index df94e65..745f92d 100644 (file)
  *
  */
 
  *
  */
 
+// EXTERNAL INCLUDES
+#include <memory>
 #include <string>
 #include <string>
-#include "shared/view.h"
-#include "linear-example.h"
-#include "padding-example.h"
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/controls/control-devel.h>
 
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
 #include <dali-toolkit/devel-api/controls/control-devel.h>
 
+// INTERNAL INCLUDES
+#include "shared/view.h"
+#include "linear-example.h"
+#include "padding-example.h"
+#include "example.h"
+
 using namespace Dali;
 using namespace Dali::Toolkit;
 
 using namespace Dali;
 using namespace Dali::Toolkit;
 
@@ -32,9 +37,19 @@ namespace
 const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "lake_front.jpg" );
 const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
 
 const char* BACKGROUND_IMAGE( DEMO_IMAGE_DIR "lake_front.jpg" );
 const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
 
-const char* APPLICATION_TITLE( "Layout tester" );
+const char* APPLICATION_TITLE( "Layout Tester" );
 
 
-}  // namespace
+typedef std::unique_ptr< Demo::Example > ExamplePointer;
+typedef std::vector< ExamplePointer > ExampleContainer;
+
+/// All layouting examples to be shown should be added to this method
+void CreateExamples( ExampleContainer& container )
+{
+  container.push_back( ExamplePointer( new Demo::LinearExample ) );
+  container.push_back( ExamplePointer( new Demo::PaddingExample ) );
+}
+
+} // anonymous namespace
 
 class LayoutingExample: public ConnectionTracker
 {
 
 class LayoutingExample: public ConnectionTracker
 {
@@ -42,23 +57,17 @@ class LayoutingExample: public ConnectionTracker
 
   LayoutingExample( Application& application )
   : mApplication( application ),
 
   LayoutingExample( Application& application )
   : mApplication( application ),
-    mLinearExample(),
-    mPaddedExample(),
+    mLayoutingExamples(),
     mLayoutIndex( 0 )
   {
     // Connect to the Application's Init signal
     mApplication.InitSignal().Connect( this, &LayoutingExample::Create );
   }
 
     mLayoutIndex( 0 )
   {
     // Connect to the Application's Init signal
     mApplication.InitSignal().Connect( this, &LayoutingExample::Create );
   }
 
-  ~LayoutingExample()
-  {
-    // Nothing to do here
-  }
+private:
 
   void Create( Application& application )
   {
 
   void Create( Application& application )
   {
-    // The Init signal is received once (only) during the Application lifetime
-
     auto stage = Stage::GetCurrent();
     stage.KeyEventSignal().Connect( this, &LayoutingExample::OnKeyEvent );
 
     auto stage = Stage::GetCurrent();
     stage.KeyEventSignal().Connect( this, &LayoutingExample::OnKeyEvent );
 
@@ -88,38 +97,24 @@ class LayoutingExample: public ConnectionTracker
     mNextLayout.SetSize(175, 50);
     toolbar.Add( mNextLayout );
 
     mNextLayout.SetSize(175, 50);
     toolbar.Add( mNextLayout );
 
-    mLinearExample.Demo::LinearExample::Create();
+    CreateExamples( mLayoutingExamples );
+    if( ! mLayoutingExamples.empty() )
+    {
+      mLayoutingExamples[ mLayoutIndex ]->Create();
+    }
   }
 
   bool ChangeLayout( Button button )
   {
   }
 
   bool ChangeLayout( Button button )
   {
-    mLayoutIndex++;
-
-    switch( mLayoutIndex )
+    if( ! mLayoutingExamples.empty() )
     {
     {
-      case 1 :
-      {
-        mLinearExample.Remove();
-        mPaddedExample.Create();
-        break;
-      }
-      case 2 :
-      {
-        mPaddedExample.Remove();
-        mNextLayout.SetProperty( Toolkit::Button::Property::LABEL, "end of test");
-        mNextLayout.SetProperty( Toolkit::Button::Property::DISABLED, true );
-        break;
-      }
-      default :
-      {
-        break;
-      }
+      mLayoutingExamples[ mLayoutIndex ]->Remove();
+      mLayoutIndex = ( mLayoutIndex + 1 ) % mLayoutingExamples.size();
+      mLayoutingExamples[ mLayoutIndex ]->Create();
     }
     }
-
     return true;
   }
 
     return true;
   }
 
-private:
   /**
    * Main key event handler
    */
   /**
    * Main key event handler
    */
@@ -137,8 +132,7 @@ private:
 
 private:
   Application& mApplication;
 
 private:
   Application& mApplication;
-  Demo::LinearExample mLinearExample;
-  Demo::PaddingExample mPaddedExample;
+  ExampleContainer mLayoutingExamples;
   PushButton mNextLayout;
   unsigned int mLayoutIndex;
 };
   PushButton mNextLayout;
   unsigned int mLayoutIndex;
 };
index 5779379..a1496bb 100644 (file)
@@ -21,6 +21,8 @@
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
 
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
 
+#include "example.h"
+
 using namespace Dali;
 using namespace Dali::Toolkit;
 
 using namespace Dali;
 using namespace Dali::Toolkit;
 
@@ -32,16 +34,15 @@ namespace Demo
  * @brief Example of a Linear Layout with mirror feature and
  * tranisition from horizontal to vertical.
  */
  * @brief Example of a Linear Layout with mirror feature and
  * tranisition from horizontal to vertical.
  */
-class LinearExample: public ConnectionTracker
+class LinearExample final: public ConnectionTracker, public Example
 {
 {
-
 public:
 
   // Creates a Linear Layout Example and displays it.
 public:
 
   // Creates a Linear Layout Example and displays it.
-  void Create();
+  virtual void Create() override;
 
   // Remove and destroy this layout
 
   // Remove and destroy this layout
-  void Remove();
+  virtual void Remove() override;
 
 private:
 
 
 private:
 
@@ -55,10 +56,10 @@ private:
   PushButton mDirectionButton;
   PushButton mRotateButton;
   Control mLinearContainer;
   PushButton mDirectionButton;
   PushButton mRotateButton;
   Control mLinearContainer;
-  bool mDirection;
+  bool mDirection = false;
   bool mIsHorizontal = true;
 }; // class LinearContainer
 
 } // namespace Demo
 
   bool mIsHorizontal = true;
 }; // class LinearContainer
 
 } // namespace Demo
 
-#endif //DALI_DEMO_LINEAR_CONTAINER_H
\ No newline at end of file
+#endif //DALI_DEMO_LINEAR_CONTAINER_H
index 3c1cc45..9941ce9 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -69,18 +69,18 @@ void PaddingExample::Create()
 
   stage.Add( mHorizontalBox );
 
 
   stage.Add( mHorizontalBox );
 
-  for( unsigned int x = 0; x < NUMBER_OF_IMAGE_VIEWS; x++ )
-  {
-    mToggleButton = Toolkit::PushButton::New();
-    mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Toggle Padding on #2" );
-    mToggleButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
-    mToggleButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
-    mToggleButton.ClickedSignal().Connect( this, &Demo::PaddingExample::ChangePaddingClicked );
-    mToggleButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
-    mToggleButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
+  mToggleButton = Toolkit::PushButton::New();
+  mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Toggle Padding on #2" );
+  mToggleButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
+  mToggleButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
+  mToggleButton.ClickedSignal().Connect( this, &Demo::PaddingExample::ChangePaddingClicked );
+  mToggleButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+  mToggleButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
 
 
-    stage.Add( mToggleButton );
+  stage.Add( mToggleButton );
 
 
+  for( unsigned int x = 0; x < NUMBER_OF_IMAGE_VIEWS; x++ )
+  {
     CreateChildImageView( mImageViews[x], DEMO_IMAGE_DIR "gallery-small-23.jpg" , Size(100.0f, 100.0f) );
 
     // Set Padding for second ImageView
     CreateChildImageView( mImageViews[x], DEMO_IMAGE_DIR "gallery-small-23.jpg" , Size(100.0f, 100.0f) );
 
     // Set Padding for second ImageView
@@ -125,4 +125,4 @@ bool PaddingExample::ChangePaddingClicked( Toolkit::Button button )
   return true;
 }
 
   return true;
 }
 
-} // namespace Demo
\ No newline at end of file
+} // namespace Demo
index ce13eed..23a200a 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_DEMO_PADDING_EXAMPLE_H
 
 /*
 #define DALI_DEMO_PADDING_EXAMPLE_H
 
 /*
- * Copyright (c) 2017 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2018 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,6 +22,8 @@
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
 
 #include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
 
+#include "example.h"
+
 using namespace Dali;
 using namespace Dali::Toolkit;
 
 using namespace Dali;
 using namespace Dali::Toolkit;
 
@@ -33,17 +35,17 @@ namespace Demo
  * @brief Example of a Linear Layout with padding applied, enables updating of padding values for
  * one of the children.
  */
  * @brief Example of a Linear Layout with padding applied, enables updating of padding values for
  * one of the children.
  */
-class PaddingExample: public ConnectionTracker
+class PaddingExample final: public ConnectionTracker, public Example
 {
 public:
 
   static const unsigned int NUMBER_OF_IMAGE_VIEWS = 3;
 
   // Create a Linear layout of ImagesViews, one with a Margin, One with padding.
 {
 public:
 
   static const unsigned int NUMBER_OF_IMAGE_VIEWS = 3;
 
   // Create a Linear layout of ImagesViews, one with a Margin, One with padding.
-  void Create();
+  void Create() override;
 
   // Remove created Layout
 
   // Remove created Layout
-  void Remove();
+  void Remove() override;
 
 private:
 
 
 private: