GridLayout example 57/183757/13
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Tue, 10 Jul 2018 15:18:57 +0000 (16:18 +0100)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Wed, 8 Aug 2018 17:18:08 +0000 (18:18 +0100)
Added new GridLayout
Added Titles to all examples

Change-Id: I6c81838ed5bf9f9ee8faafe5bafc247562f0f7b9

13 files changed:
examples/layouting/absolute-example.cpp
examples/layouting/absolute-example.h
examples/layouting/example.h
examples/layouting/flex-example.cpp
examples/layouting/flex-example.h
examples/layouting/grid-example.cpp [new file with mode: 0644]
examples/layouting/grid-example.h [new file with mode: 0644]
examples/layouting/layout-utilities.cpp [new file with mode: 0644]
examples/layouting/layout-utilities.h [new file with mode: 0644]
examples/layouting/layouting-examples.cpp
examples/layouting/linear-example.cpp
examples/layouting/padding-example.cpp
examples/layouting/padding-example.h

index 6088878..460fff1 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <string>
 #include "absolute-example.h"
+#include "layout-utilities.h"
 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
 #include <dali-toolkit/devel-api/controls/control-devel.h>
@@ -28,6 +29,7 @@ using namespace Dali::Toolkit;
 
 namespace
 {
+const char* const TITLE = "Absolute Example";
 
 struct ImageDetails
 {
@@ -67,7 +69,8 @@ namespace Demo
 {
 
 AbsoluteExample::AbsoluteExample()
-: mRootLayoutControl(),
+: Example( TITLE ),
+  mRootLayoutControl(),
   mAbsoluteLayoutContainer(),
   mLayoutSizeToggleStatus( true ),
   mToggleButton()
@@ -77,16 +80,9 @@ AbsoluteExample::AbsoluteExample()
 
 void AbsoluteExample::Create()
 {
-  // Create a root layout, ideally Dali would have a default layout in the root layer.
-  // Without this root layer the mAbsoluteLayout (or any other layout) will not
-  // honour WIDTH_SPECIFICATION or HEIGHT_SPECIFICATION settings.
-  // It uses the default stage size and ideally should have a layout added to it.
   auto stage = Stage::GetCurrent();
-  mRootLayoutControl = Control::New();
-  auto rootLayout = AbsoluteLayout::New();
-  DevelControl::SetLayout( mRootLayoutControl, rootLayout );
-  mRootLayoutControl.SetAnchorPoint( AnchorPoint::CENTER );
-  mRootLayoutControl.SetParentOrigin( ParentOrigin::CENTER );
+  // This layout will be the size of the stage but allows subsequent layouts to be any size.
+  mRootLayoutControl = LayoutUtilities::CreateRootContainer();
   stage.Add( mRootLayoutControl );
 
   // Create an Absolute Layout to show ImageViews at explictly provided positions.
index a46ca99..ef247f8 100644 (file)
@@ -34,11 +34,12 @@ namespace Demo
  * @brief Example of a Linear Layout with padding applied, enables updating of padding values for
  * one of the children.
  */
-class AbsoluteExample: public ConnectionTracker, public Example
+class AbsoluteExample final: public ConnectionTracker, public Example
 {
 public:
   static const unsigned int NUMBER_OF_IMAGE_VIEWS = 4;
 
+  // Constructor
   AbsoluteExample();
 
   // Creates a Absolute Layout Example and displays it.
@@ -49,7 +50,6 @@ public:
 
 private:
 
-
   // Callback when change size button is pressed
   bool ChangeSizeClicked( Toolkit::Button button );
 
index d0a15f0..33065c4 100644 (file)
@@ -18,6 +18,9 @@
  *
  */
 
+// EXTERNAL INCLUDES
+#include <string>
+
 namespace Demo
 {
 
@@ -35,6 +38,28 @@ public:
 
   /// Virtual destructor
   virtual ~Example() = default;
+
+  /**
+   * Gets the title set for this example
+   * @return title
+   */
+  const std::string& GetExampleTitle() const
+  {
+    return mTitle;
+  }
+
+protected:
+  /**
+   * Constructor for Example
+   * @param[in] title Title to be used for the example
+   */
+  Example( const std::string& title )
+  : mTitle( title )
+  {
+  }
+
+private:
+  const std::string mTitle;
 };
 
 } // namespace Demo
index 5778cf0..19dc778 100644 (file)
@@ -26,6 +26,7 @@ using namespace Dali::Toolkit;
 
 namespace
 {
+const char* const TITLE = "Flex Example";
 
 // Button file names
 const char* LTR_IMAGE( DEMO_IMAGE_DIR "icon-play.png" );
@@ -81,7 +82,8 @@ namespace Demo
 {
 
 FlexExample::FlexExample()
-: mLTRDirection(true)
+: Example( TITLE ),
+  mLTRDirection(true)
 {
 
 }
index 0049404..0ddd187 100644 (file)
@@ -37,6 +37,8 @@ namespace Demo
 class FlexExample final: public ConnectionTracker, public Example
 {
 public:
+
+  // Constructor
   FlexExample();
 
   // Creates a Flex Layout Example and displays it.
diff --git a/examples/layouting/grid-example.cpp b/examples/layouting/grid-example.cpp
new file mode 100644 (file)
index 0000000..60f5d05
--- /dev/null
@@ -0,0 +1,245 @@
+/*
+ * 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.
+ *
+ */
+
+#include <string>
+#include "grid-example.h"
+#include "layout-utilities.h"
+#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/layouting/absolute-layout.h>
+#include <dali-toolkit/devel-api/layouting/grid.h>
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+
+namespace
+{
+const char* const TITLE = "Grid Example";
+
+// Helper function to create ImageViews with given filename and size.
+void CreateChildImageView( ImageView& imageView, const char* filename, Size size )
+{
+  imageView = ImageView::New();
+  Property::Map imagePropertyMap;
+  imagePropertyMap[ Toolkit::Visual::Property::TYPE ] = Toolkit::Visual::IMAGE;
+  imagePropertyMap[ Toolkit::ImageVisual::Property::URL ] = filename;
+  imagePropertyMap[ ImageVisual::Property::DESIRED_WIDTH ] = size.width;
+  imagePropertyMap[ ImageVisual::Property::DESIRED_HEIGHT ] = size.height;
+  imageView.SetProperty(Toolkit::ImageView::Property::IMAGE , imagePropertyMap );
+  imageView.SetName("ImageView");
+  imageView.SetAnchorPoint( AnchorPoint::TOP_LEFT );
+  imageView.SetResizePolicy( ResizePolicy::FIXED, Dimension::ALL_DIMENSIONS );
+}
+
+enum CurrentExample
+{
+  GRID_EXACT_WIDTH = 0,
+  ITEMS_WITH_MARGINS,
+  GRID_MATCH_PARENT,
+  GRID_WRAP_CONTENT,
+  ADD_ITEMS,
+  CHANGE_TO_3_COLUMNS
+};
+
+}
+
+namespace Demo
+{
+
+GridExample::GridExample()
+: Example( TITLE )
+{
+}
+
+void GridExample::Create()
+{
+  // The Init signal is received once (only) during the Application lifetime
+  mToggleStatus = 0;
+  auto stage = Stage::GetCurrent();
+
+  // This layout will be the size of the stage but allow the Grid layout to be any size.
+  mRootLayoutControl = LayoutUtilities::CreateRootContainer();
+  stage.Add( mRootLayoutControl );
+
+  // Create a table view to show a pair of buttons above each image.
+  mGridContainer = Control::New();
+
+  // Create LinearLayout for this control.
+  auto gridLayout = Grid::New();
+  gridLayout.SetAnimateLayout(true);
+  gridLayout.SetNumberOfColumns( 2 );
+  DevelControl::SetLayout( mGridContainer, gridLayout );
+  mGridContainer.SetName("GridContainer");
+  mGridContainer.SetBackgroundColor( Color::WHITE );
+  mGridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION, ChildLayoutData::WRAP_CONTENT );
+  mGridContainer.SetProperty( LayoutItem::ChildProperty::HEIGHT_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
+  mGridContainer.SetProperty( Toolkit::Control::Property::PADDING, Extents( 20,20,20,20 ) );
+  mGridContainer.SetParentOrigin( ParentOrigin::CENTER );
+
+  mRootLayoutControl.Add( mGridContainer );
+
+  for( unsigned int x = 0; x < INITIAL_NUMBER_OF_IMAGE_VIEWS; x++ )
+  {
+    ImageView imageView;
+    CreateChildImageView( imageView, DEMO_IMAGE_DIR "gallery-small-23.jpg" , Size(100.0f, 100.0f) );
+    mImageViews.push_back( imageView );
+    mGridContainer.Add( mImageViews[x] );
+  }
+
+  // Button toggles the size of the layout
+  mToggleButton = PushButton::New();
+  mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Set Width 300" );
+  mToggleButton.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
+  mToggleButton.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER );
+  mToggleButton.ClickedSignal().Connect( this, &Demo::GridExample::ToggleButtonClicked );
+  mToggleButton.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+  mToggleButton.SetResizePolicy( ResizePolicy::USE_NATURAL_SIZE, Dimension::HEIGHT );
+
+  stage.Add( mToggleButton );
+}
+
+void GridExample::Remove()
+{
+  mImageViews.clear();
+  UnparentAndReset( mGridContainer );
+  UnparentAndReset( mRootLayoutControl );
+  UnparentAndReset( mToggleButton );
+}
+
+void GridExample::ChangeTo3Columns()
+{
+  Grid gridLayout = Grid::DownCast( DevelControl::GetLayout(mGridContainer) );
+  if ( gridLayout )
+  {
+    gridLayout.SetNumberOfColumns( 3 );
+  }
+}
+
+void GridExample::AddItemsInteractively()
+{
+  if( mImageViews.size() < MAX_NUMBER_OF_IMAGE_VIEWS )
+  {
+    ImageView imageView;
+    CreateChildImageView( imageView, DEMO_IMAGE_DIR "gallery-small-23.jpg" , Size(100.0f, 100.0f) );
+    mImageViews.push_back( imageView );
+    mGridContainer.Add( imageView);
+
+    // Add item button shows how many items left to add.
+    unsigned int numberOfAdditonalImageViews = MAX_NUMBER_OF_IMAGE_VIEWS-INITIAL_NUMBER_OF_IMAGE_VIEWS;
+    unsigned int remainingImageViews = numberOfAdditonalImageViews - ( ( mImageViews.size() - INITIAL_NUMBER_OF_IMAGE_VIEWS) );
+    std::string buttonLabel( "Add item["+ std::to_string( numberOfAdditonalImageViews-remainingImageViews ) +"/"+
+                                          std::to_string( numberOfAdditonalImageViews)+"]" );
+    mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, buttonLabel );
+  }
+}
+
+void GridExample::AddMarginToItems()
+{
+  for( unsigned int x = 0; x < INITIAL_NUMBER_OF_IMAGE_VIEWS; x++ )
+  {
+    mImageViews[x].SetProperty(Toolkit::Control::Property::MARGIN, Extents( 20,20,20,10));
+  }
+}
+
+void GridExample::RemoveMarginsFromItems()
+{
+  for( unsigned int x = 0; x < INITIAL_NUMBER_OF_IMAGE_VIEWS; x++ )
+  {
+    mImageViews[x].SetProperty(Toolkit::Control::Property::MARGIN, Extents());
+  }
+}
+
+void GridExample::MatchParentOnWidth()
+{
+  mGridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION,ChildLayoutData::MATCH_PARENT );
+}
+
+void GridExample::WrapContentOnWidth()
+{
+  mGridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION,  ChildLayoutData::WRAP_CONTENT );
+}
+
+void GridExample::SetExactWidth()
+{
+  mGridContainer.SetProperty( LayoutItem::ChildProperty::WIDTH_SPECIFICATION,  300 );
+}
+
+bool GridExample::ToggleButtonClicked( Toolkit::Button button )
+{
+  switch( mToggleStatus )
+  {
+    case GRID_EXACT_WIDTH :
+    {
+      SetExactWidth();
+      mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Set Child Margin" );
+      mToggleStatus = ITEMS_WITH_MARGINS;
+      break;
+    }
+    case ITEMS_WITH_MARGINS :
+    {
+      AddMarginToItems();
+      mToggleStatus = GRID_MATCH_PARENT;
+      mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Set width MATCH_PARENT" );
+      break;
+    }
+    case GRID_MATCH_PARENT :
+    {
+      RemoveMarginsFromItems();
+      MatchParentOnWidth();
+      mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Set width WRAP_CONTENT" );
+      mToggleStatus = GRID_WRAP_CONTENT;
+      break;
+    }
+    case GRID_WRAP_CONTENT :
+    {
+      WrapContentOnWidth();
+      mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Add item" );
+      mToggleStatus = ADD_ITEMS;
+      break;
+    }
+    case ADD_ITEMS :
+    {
+      if( mGridContainer.GetChildCount() < MAX_NUMBER_OF_IMAGE_VIEWS )
+      {
+        AddItemsInteractively();
+      }
+
+      if( mGridContainer.GetChildCount() == MAX_NUMBER_OF_IMAGE_VIEWS )
+      {
+        // Remove button when no more items to add
+        mToggleStatus= CHANGE_TO_3_COLUMNS;
+        mToggleButton.SetProperty( Toolkit::Button::Property::LABEL, "Change Columns" );
+      }
+      break;
+    }
+    case CHANGE_TO_3_COLUMNS :
+    {
+      ChangeTo3Columns();
+      mToggleStatus = GRID_EXACT_WIDTH;
+      UnparentAndReset( mToggleButton );
+      break;
+    }
+    default :
+    {
+      mToggleStatus = GRID_EXACT_WIDTH;
+    }
+  }
+  return true;
+}
+
+} // namespace Demo
diff --git a/examples/layouting/grid-example.h b/examples/layouting/grid-example.h
new file mode 100644 (file)
index 0000000..7de67f3
--- /dev/null
@@ -0,0 +1,78 @@
+#ifndef DALI_DEMO_GRID_EXAMPLE_H
+#define DALI_DEMO_GRID_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.
+ *
+ */
+
+#include <string>
+#include <dali/dali.h>
+#include <dali-toolkit/dali-toolkit.h>
+
+#include "example.h"
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+
+namespace Demo
+{
+
+/**
+ * @file grid-example.hcpp
+ * @brief Example of a Grid Layout
+ */
+class GridExample final: public ConnectionTracker, public Example
+{
+public:
+
+  // Constructor
+  GridExample();
+
+  static const unsigned int MAX_NUMBER_OF_IMAGE_VIEWS = 9;
+  static const unsigned int INITIAL_NUMBER_OF_IMAGE_VIEWS = 5;
+
+  // Create a Grid layout of ImagesViews
+  void Create() override;
+
+  // Remove created Layout
+  void Remove() override;
+
+private:
+
+  // Callback for button pressed
+  bool ToggleButtonClicked( Toolkit::Button button );
+
+  // Actions to perform in this example
+  void ChangeTo3Columns();
+  void AddItemsInteractively();
+  void AddMarginToItems();
+  void RemoveMarginsFromItems();
+  void MatchParentOnWidth();
+  void WrapContentOnWidth();
+  void SetExactWidth();
+
+private:
+
+  Toolkit::Control                mRootLayoutControl;
+  Toolkit::Control                mGridContainer;
+  std::vector<Toolkit::ImageView> mImageViews;
+  Toolkit::PushButton             mToggleButton;
+  unsigned int                    mToggleStatus;
+};
+
+} // namespace Demo
+
+#endif // DALI_DEMO_GRID_EXAMPLE_H
diff --git a/examples/layouting/layout-utilities.cpp b/examples/layouting/layout-utilities.cpp
new file mode 100644 (file)
index 0000000..9f24611
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ *
+ */
+
+#include <dali-toolkit/devel-api/controls/control-devel.h>
+#include <dali-toolkit/devel-api/layouting/absolute-layout.h>
+
+using namespace Dali;
+using namespace Dali::Toolkit;
+
+namespace LayoutUtilities
+{
+Toolkit::Control CreateRootContainer()
+{
+  Control rootLayoutControl = Control::New();
+  rootLayoutControl.SetName( "AbsoluteLayout");
+  auto rootLayout = AbsoluteLayout::New();
+  DevelControl::SetLayout( rootLayoutControl, rootLayout );
+  rootLayoutControl.SetAnchorPoint( AnchorPoint::CENTER );
+  rootLayoutControl.SetParentOrigin( ParentOrigin::CENTER );
+
+  return rootLayoutControl;
+}
+
+} // namespace LayoutUtilities
\ No newline at end of file
diff --git a/examples/layouting/layout-utilities.h b/examples/layouting/layout-utilities.h
new file mode 100644 (file)
index 0000000..fadf536
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ *
+ */
+
+#ifndef DALI_DEMO_LAYOUT_UTILITIES_H
+#define DALI_DEMO_LAYOUT_UTILITIES_H
+
+#include <dali-toolkit/public-api/controls/control.h>
+
+namespace LayoutUtilities
+{
+/**
+ * @brief
+ * Create a root layout, ideally Dali would have a default layout in the root layer.
+ * Without this root layer the mAbsoluteLayout (or any other layout) will not
+ * honour WIDTH_SPECIFICATION or HEIGHT_SPECIFICATION settings.
+ * It uses the default stage size and ideally should have a layout added to it.
+ * @return resulting root layout
+ */
+Dali::Toolkit::Control CreateRootContainer();
+} // namespace LayoutUtilities
+
+#endif // DALI_DEMO_LAYOUT_UTILITIES_H
\ No newline at end of file
index a1f342e..fde22de 100644 (file)
@@ -27,6 +27,7 @@
 #include "linear-example.h"
 #include "padding-example.h"
 #include "flex-example.h"
+#include "grid-example.h"
 #include "example.h"
 #include "absolute-example.h"
 
@@ -39,18 +40,18 @@ namespace
 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" );
-
 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 ) );
-  container.push_back( ExamplePointer( new Demo::AbsoluteExample ) );
-  container.push_back( ExamplePointer( new Demo::FlexExample ) );
+  container.push_back( ExamplePointer(new Demo::LinearExample) );
+  container.push_back( ExamplePointer(new Demo::PaddingExample) );
+  container.push_back( ExamplePointer(new Demo::AbsoluteExample) );
+  container.push_back( ExamplePointer(new Demo::FlexExample) ) ;
+  container.push_back( ExamplePointer(new Demo::GridExample) ) ;
 }
 
 } // anonymous namespace
@@ -86,12 +87,12 @@ private:
 
     stage.Add( toolbar );
 
-    auto title = TextLabel::New( APPLICATION_TITLE );
-    title.SetParentOrigin( ParentOrigin::CENTER );
-    title.SetAnchorPoint( AnchorPoint::CENTER );
-    title.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
-    title.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::LEFT );
-    toolbar.Add( title );
+    mToolbarTitle = TextLabel::New( "");
+    mToolbarTitle.SetParentOrigin( ParentOrigin::CENTER );
+    mToolbarTitle.SetAnchorPoint( AnchorPoint::CENTER );
+    mToolbarTitle.SetProperty( TextLabel::Property::TEXT_COLOR, Color::BLUE );
+    mToolbarTitle.SetProperty( TextLabel::Property::HORIZONTAL_ALIGNMENT, HorizontalAlignment::LEFT );
+    toolbar.Add( mToolbarTitle );
 
     mNextLayout = PushButton::New();
     mNextLayout.SetProperty( Toolkit::Button::Property::LABEL, "change layout");
@@ -105,6 +106,7 @@ private:
     if( ! mLayoutingExamples.empty() )
     {
       mLayoutingExamples[ mLayoutIndex ]->Create();
+      mToolbarTitle.SetProperty(Toolkit::TextLabel::Property::TEXT, mLayoutingExamples[ mLayoutIndex ]->GetExampleTitle() );
     }
   }
 
@@ -115,6 +117,7 @@ private:
       mLayoutingExamples[ mLayoutIndex ]->Remove();
       mLayoutIndex = ( mLayoutIndex + 1 ) % mLayoutingExamples.size();
       mLayoutingExamples[ mLayoutIndex ]->Create();
+      mToolbarTitle.SetProperty(Toolkit::TextLabel::Property::TEXT, mLayoutingExamples[ mLayoutIndex ]->Example::GetExampleTitle() );
     }
     return true;
   }
@@ -139,6 +142,7 @@ private:
   ExampleContainer mLayoutingExamples;
   PushButton mNextLayout;
   unsigned int mLayoutIndex;
+  TextLabel mToolbarTitle;
 };
 
 int DALI_EXPORT_API main( int argc, char **argv )
index 9f56222..156baeb 100644 (file)
@@ -27,6 +27,7 @@ using namespace Dali::Toolkit;
 
 namespace
 {
+const char* const TITLE = "Linear Example";
 
 // Button file names
 const char* LTR_IMAGE( DEMO_IMAGE_DIR "icon-play.png" );
@@ -69,7 +70,8 @@ namespace Demo
 {
 
 LinearExample::LinearExample()
-: mLTRDirection(true)
+: Example( TITLE ),
+  mLTRDirection(true)
 {
 }
 
index 70457dc..811046e 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <string>
 #include "padding-example.h"
+#include "layout-utilities.h"
 #include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
 #include <dali-toolkit/devel-api/controls/control-devel.h>
@@ -29,6 +30,7 @@ using namespace Dali::Toolkit;
 
 namespace
 {
+const char* const TITLE = "Padding Example";
 
 // Helper function to create ImageViews with given filename and size.
 void CreateChildImageView( ImageView& imageView, const char* filename, Size size )
@@ -50,21 +52,17 @@ void CreateChildImageView( ImageView& imageView, const char* filename, Size size
 namespace Demo
 {
 
+PaddingExample::PaddingExample()
+: Example( TITLE )
+{}
+
 void PaddingExample::Create()
 {
   // The Init signal is received once (only) during the Application lifetime
 
-  // Create a root layout, ideally Dali would have a default layout in the root layer.
-  // Without this root layer the mAbsoluteLayout (or any other layout) will not
-  // honour WIDTH_SPECIFICATION or HEIGHT_SPECIFICATION settings.
-  // It uses the default stage size and ideally should have a layout added to it.
   auto stage = Stage::GetCurrent();
-  auto rootLayoutControl = Control::New();
-  rootLayoutControl.SetName( "AbsoluteLayout");
-  auto rootLayout = AbsoluteLayout::New();
-  DevelControl::SetLayout( rootLayoutControl, rootLayout );
-  rootLayoutControl.SetAnchorPoint( AnchorPoint::CENTER );
-  rootLayoutControl.SetParentOrigin( ParentOrigin::CENTER );
+
+  Control rootLayoutControl = LayoutUtilities::CreateRootContainer();
   stage.Add( rootLayoutControl );
 
   // Create a table view to show a pair of buttons above each image.
index 23a200a..ef4da16 100644 (file)
@@ -41,6 +41,9 @@ public:
 
   static const unsigned int NUMBER_OF_IMAGE_VIEWS = 3;
 
+  // Constructor
+  PaddingExample();
+
   // Create a Linear layout of ImagesViews, one with a Margin, One with padding.
   void Create() override;