Supply stylesheet using Application constructor
[platform/core/uifw/dali-demo.git] / examples / builder / examples.cpp
index 90bb1b6..79f50a1 100644 (file)
 //
 //------------------------------------------------------------------------------
 
-#include "dali.h"
+#include <dali/dali.h>
 #include <dali-toolkit/dali-toolkit.h>
-#include <dali-toolkit/public-api/builder/builder.h>
-#include <dali-toolkit/public-api/builder/tree-node.h>
-#include <dali-toolkit/public-api/builder/json-parser.h>
+#include <dali-toolkit/devel-api/builder/builder.h>
+#include <dali-toolkit/devel-api/builder/tree-node.h>
+#include <dali-toolkit/devel-api/builder/json-parser.h>
+#include <dali-toolkit/devel-api/controls/popup/popup.h>
 #include <map>
 #include <string>
 #include <fstream>
 #include <streambuf>
 #include <sstream>
-#include <boost/scoped_ptr.hpp>
 #include <dirent.h>
 #include <stdio.h>
 #include <iostream>
 
-//#include <boost/regex.hpp>
 #include "sys/stat.h"
 #include <ctime>
+#include <cstring>
 
 #include <dali/integration-api/debug.h>
-#include "../shared/view.h"
+#include "shared/view.h"
 
 #define TOKEN_STRING(x) #x
 
@@ -61,7 +61,7 @@ std::string JSON_BROKEN("                                      \
   'stage':                                                     \
   [                                                            \
     {                                                          \
-      'type':'TextView',                                       \
+      'type':'TextLabel',                                      \
       'size': [50,50,1],                                       \
       'parent-origin': 'CENTER',                               \
       'text':'COULD NOT LOAD JSON FILE'                        \
@@ -143,11 +143,6 @@ const std::string ShortName( const std::string& name )
   }
 }
 
-static Vector3 SetItemSize(unsigned int numberOfColumns, float layoutWidth, float sideMargin, float columnSpacing)
-{
-  return Vector3(layoutWidth, 50, 1);
-}
-
 //------------------------------------------------------------------------------
 //
 //
@@ -243,7 +238,14 @@ public:
 
   void SetTitle(const std::string& title)
   {
-    // TODO
+    if(!mTitleActor)
+    {
+      mTitleActor = DemoHelper::CreateToolBarLabel( "" );
+      // Add title to the tool bar.
+      mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
+    }
+
+    mTitleActor.SetProperty( TextLabel::Property::TEXT, title );
   }
 
   bool OnToolSelectLayout( Toolkit::Button button )
@@ -270,6 +272,7 @@ public:
   void EnterSelection()
   {
     Stage stage = Stage::GetCurrent();
+    stage.SetBackgroundColor( Color::WHITE );
 
     mTapDetector = TapGestureDetector::New();
     mTapDetector.DetectedSignal().Connect( this, &ExampleApp::OnTap );
@@ -285,17 +288,12 @@ public:
     stage.Add( mItemView );
     mItemView.SetParentOrigin(ParentOrigin::CENTER);
     mItemView.SetAnchorPoint(AnchorPoint::CENTER);
-    mGridLayout = GridLayout::New();
-    mGridLayout->SetNumberOfColumns(1);
+    mLayout = DefaultItemLayout::New( DefaultItemLayout::LIST );
 
-    mGridLayout->SetItemSizeFunction(SetItemSize);
+    mLayout->SetItemSize( Vector3( stage.GetSize().width, 50, 1 ) );
 
-    mGridLayout->SetTopMargin(DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight);
+    mItemView.AddLayout( *mLayout );
 
-    mItemView.AddLayout(*mGridLayout);
-
-    Vector3 size(stage.GetSize());
-    mItemView.ActivateLayout(0, size, 0.0f/*immediate*/);
     mItemView.SetKeyboardFocusable( true );
 
     mFiles.clear();
@@ -363,9 +361,9 @@ public:
 
     SetTitle("Select");
 
-    // Itemview renderes the previous items unless its scrolled. Not sure why at the moment so we force a scroll
-    mItemView.ScrollToItem(0, 0);
-
+    // Activate the layout
+    Vector3 size(stage.GetSize());
+    mItemView.ActivateLayout(0, size, 0.0f/*immediate*/);
   }
 
   void ExitSelection()
@@ -387,7 +385,14 @@ public:
 
   Actor MenuItem(const std::string& text)
   {
-    return Actor();
+    TextLabel label = TextLabel::New( ShortName( text ) );
+    label.SetProperty( Dali::Toolkit::Control::Property::STYLE_NAME, "builderlabel" );
+    label.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+
+    // Hook up tap detector
+    mTapDetector.Attach( label );
+
+    return label;
   }
 
   bool OnTimer()
@@ -456,7 +461,6 @@ public:
     }
 
     builder.AddActors( layer );
-
   }
 
 
@@ -571,13 +575,14 @@ public:
 private:
   Application& mApp;
 
-  GridLayoutPtr mGridLayout;
+  ItemLayoutPtr mLayout;
   ItemView mItemView;
 
-  Toolkit::View mView;
+  Toolkit::Control mView;
   unsigned int mOrientation;
 
   Toolkit::ToolBar mToolBar;
+  TextLabel mTitleActor;             ///< The Toolbar's Title.
 
   Layer mBuilderLayer;
 
@@ -611,7 +616,7 @@ int main(int argc, char **argv)
     }
   }
 
-  Application app = Application::New(&argc, &argv);
+  Application app = Application::New(&argc, &argv, DALI_DEMO_THEME_PATH);
 
   ExampleApp dali_app(app);