Supply stylesheet using Application constructor
[platform/core/uifw/dali-demo.git] / examples / builder / examples.cpp
index fdebce4..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
 
@@ -60,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'                        \
@@ -142,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);
-}
-
 //------------------------------------------------------------------------------
 //
 //
@@ -244,15 +240,12 @@ public:
   {
     if(!mTitleActor)
     {
-      mTitleActor = TextView::New();
+      mTitleActor = DemoHelper::CreateToolBarLabel( "" );
       // Add title to the tool bar.
       mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
     }
 
-    Font font = Font::New();
-    mTitleActor.SetText( title );
-    mTitleActor.SetSize( font.MeasureText( title ) );
-    mTitleActor.SetStyleToCurrentText(DemoHelper::GetDefaultTextStyle());
+    mTitleActor.SetProperty( TextLabel::Property::TEXT, title );
   }
 
   bool OnToolSelectLayout( Toolkit::Button button )
@@ -279,6 +272,7 @@ public:
   void EnterSelection()
   {
     Stage stage = Stage::GetCurrent();
+    stage.SetBackgroundColor( Color::WHITE );
 
     mTapDetector = TapGestureDetector::New();
     mTapDetector.DetectedSignal().Connect( this, &ExampleApp::OnTap );
@@ -294,17 +288,12 @@ public:
     stage.Add( mItemView );
     mItemView.SetParentOrigin(ParentOrigin::CENTER);
     mItemView.SetAnchorPoint(AnchorPoint::CENTER);
-    mGridLayout = GridLayout::New();
-    mGridLayout->SetNumberOfColumns(1);
-
-    mGridLayout->SetItemSizeFunction(SetItemSize);
+    mLayout = DefaultItemLayout::New( DefaultItemLayout::LIST );
 
-    mGridLayout->SetTopMargin(DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight);
+    mLayout->SetItemSize( Vector3( stage.GetSize().width, 50, 1 ) );
 
-    mItemView.AddLayout(*mGridLayout);
+    mItemView.AddLayout( *mLayout );
 
-    Vector3 size(stage.GetSize());
-    mItemView.ActivateLayout(0, size, 0.0f/*immediate*/);
     mItemView.SetKeyboardFocusable( true );
 
     mFiles.clear();
@@ -372,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()
@@ -396,22 +385,14 @@ public:
 
   Actor MenuItem(const std::string& text)
   {
-    TextView t = TextView::New();
-    t.SetMarkupProcessingEnabled(true);
-
-    int size = static_cast<int>(DemoHelper::ScalePointSize(6));
-
-    std::ostringstream fontString;
-    fontString << "<font size="<< size <<">"<<  ShortName( text ) << "</font>";
-
-    t.SetText( fontString.str() );
-
-    t.SetTextAlignment( Alignment::HorizontalLeft );
+    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( t );
+    mTapDetector.Attach( label );
 
-    return t;
+    return label;
   }
 
   bool OnTimer()
@@ -480,7 +461,6 @@ public:
     }
 
     builder.AddActors( layer );
-
   }
 
 
@@ -595,14 +575,14 @@ public:
 private:
   Application& mApp;
 
-  GridLayoutPtr mGridLayout;
+  ItemLayoutPtr mLayout;
   ItemView mItemView;
 
-  Toolkit::View mView;
+  Toolkit::Control mView;
   unsigned int mOrientation;
 
   Toolkit::ToolBar mToolBar;
-  TextView mTitleActor;             ///< The Toolbar's Title.
+  TextLabel mTitleActor;             ///< The Toolbar's Title.
 
   Layer mBuilderLayer;
 
@@ -636,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);