/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 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.
//
//------------------------------------------------------------------------------
-#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/buttons/button-devel.h>
+#include <dali-toolkit/devel-api/controls/popup/popup.h>
+#include <dali-toolkit/devel-api/controls/navigation-view/navigation-view.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 <dali/devel-api/adaptor-framework/file-loader.h>
+#include "shared/view.h"
#define TOKEN_STRING(x) #x
{
const char* BACKGROUND_IMAGE( "" );
-const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
-const char* EDIT_IMAGE( DALI_IMAGE_DIR "icon-change.png" );
+const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
+const char* EDIT_IMAGE( DEMO_IMAGE_DIR "icon-change.png" );
+const char* EDIT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-change-selected.png" );
std::string USER_DIRECTORY;
'stage': \
[ \
{ \
- 'type':'TextView', \
+ 'type':'TextLabel', \
'size': [50,50,1], \
- 'parent-origin': 'CENTER', \
+ 'parentOrigin': 'CENTER', \
'text':'COULD NOT LOAD JSON FILE' \
} \
] \
std::string GetFileContents(const std::string &fn)
{
- std::ifstream t(fn.c_str());
- return std::string((std::istreambuf_iterator<char>(t)),
- std::istreambuf_iterator<char>());
+ std::streampos bufferSize = 0;
+ Dali::Vector<char> fileBuffer;
+ if( !Dali::FileLoader::ReadFile( fn, bufferSize, fileBuffer, FileLoader::FileType::BINARY ) )
+ {
+ return std::string();
+ }
+
+ return std::string( &fileBuffer[0], bufferSize );
};
typedef std::vector<std::string> FileList;
if( pos != std::string::npos )
{
+ pos++;
return name.substr( pos );
}
else
}
}
-static Vector3 SetItemSize(unsigned int numberOfColumns, float layoutWidth, float sideMargin, float columnSpacing)
-{
- return Vector3(layoutWidth, 50, 1);
-}
-
//------------------------------------------------------------------------------
//
//
{
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 )
+ bool OnBackButtonPressed( Toolkit::Button button )
{
- bool on = mItemView.IsVisible();
-
- if( on )
- {
- LeaveSelection();
- }
- else
- {
- EnterSelection();
- }
-
+ OnQuitOrBack();
return true;
}
- void LeaveSelection()
- {
-
- }
-
- void EnterSelection()
+ void SetUpItemView()
{
Stage stage = Stage::GetCurrent();
- if( mItemView )
- {
- stage.Remove( mItemView );
- }
+ mTapDetector = TapGestureDetector::New();
+ mTapDetector.DetectedSignal().Connect( this, &ExampleApp::OnTap );
mFiles.clear();
mItemView = ItemView::New(*this);
- 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();
}
else
{
- DirectoryFilesByType( DALI_SCRIPT_DIR, "json", files );
+ DirectoryFilesByType( DEMO_SCRIPT_DIR, "json", files );
}
std::sort(files.begin(), files.end());
}
}
- mTapDetector = TapGestureDetector::New();
-
- for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
- {
- mTapDetector.Attach( mItemView.GetChildAt(i) );
- }
-
- mTapDetector.DetectedSignal().Connect( this, &ExampleApp::OnTap );
-
- // Display item view on the stage
- stage.Add( mItemView );
-
- mItemView.SetVisible( true );
- mBuilderLayer.SetVisible( false );
-
- 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()
- {
- mTapDetector.Reset();
-
- mItemView.SetVisible( false );
- mBuilderLayer.SetVisible( true );
-
- SetTitle("View");
- }
- void OnTap( Actor actor, TapGesture tap )
+ void OnTap( Actor actor, const TapGesture& tap )
{
ItemId id = mItemView.GetItemId( actor );
Actor MenuItem(const std::string& text)
{
- TextView t = TextView::New();
- t.SetMarkupProcessingEnabled(true);
- t.SetText( std::string("<font size=6>") + ShortName( text ) + std::string("</font>") );
- t.SetTextAlignment( Alignment::HorizontalLeft );
- return t;
+ TextLabel label = TextLabel::New( ShortName( text ) );
+ label.SetStyleName( "BuilderLabel" );
+ label.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::WIDTH );
+
+ // Hook up tap detector
+ mTapDetector.Attach( label );
+
+ return label;
}
bool OnTimer()
Stage stage = Stage::GetCurrent();
builder = Builder::New();
+ builder.QuitSignal().Connect( this, &ExampleApp::OnQuitOrBack );
- PropertyValueMap defaultDirs;
- defaultDirs[ TOKEN_STRING(DALI_IMAGE_DIR) ] = DALI_IMAGE_DIR;
- defaultDirs[ TOKEN_STRING(DALI_MODEL_DIR) ] = DALI_MODEL_DIR;
- defaultDirs[ TOKEN_STRING(DALI_SCRIPT_DIR) ] = DALI_SCRIPT_DIR;
+ Property::Map defaultDirs;
+ defaultDirs[ TOKEN_STRING(DEMO_IMAGE_DIR) ] = DEMO_IMAGE_DIR;
+ defaultDirs[ TOKEN_STRING(DEMO_MODEL_DIR) ] = DEMO_MODEL_DIR;
+ defaultDirs[ TOKEN_STRING(DEMO_SCRIPT_DIR) ] = DEMO_SCRIPT_DIR;
builder.AddConstants( defaultDirs );
}
builder.AddActors( layer );
-
}
{
ReloadJsonFile( name, mBuilder, mBuilderLayer );
- // do this here as GetCurrentSize()
- mBuilderLayer.SetParentOrigin(ParentOrigin::CENTER);
- mBuilderLayer.SetAnchorPoint(AnchorPoint::CENTER);
+ mBuilderLayer.SetParentOrigin(ParentOrigin::BOTTOM_CENTER);
+ mBuilderLayer.SetAnchorPoint(AnchorPoint::BOTTOM_CENTER);
Dali::Vector3 size = Stage::GetCurrent().GetRootLayer().GetCurrentSize();
size.y -= DemoHelper::DEFAULT_VIEW_STYLE.mToolBarHeight;
mBuilderLayer.SetSize( size );
- mBuilderLayer.LowerToBottom();
- Stage::GetCurrent().GetRootLayer().RaiseToTop();
-
- ExitSelection();
+ mNavigationView.Push( mBuilderLayer );
}
void Create(Application& app)
TOOLBAR_IMAGE,
"" );
- SetTitle("Builder");
+ SetTitle("Select Example");
mBuilderLayer = Layer::New();
- stage.GetRootLayer().Add(mBuilderLayer);
-
// Create an edit mode button. (left of toolbar)
- Toolkit::PushButton editButton = Toolkit::PushButton::New();
- editButton.SetBackgroundImage( Image::New( EDIT_IMAGE ) );
- editButton.ClickedSignal().Connect( this, &ExampleApp::OnToolSelectLayout);
- editButton.SetLeaveRequired( true );
- mToolBar.AddControl( editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
-
- EnterSelection();
+ Toolkit::PushButton backButton = Toolkit::PushButton::New();
+ backButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, EDIT_IMAGE );
+ backButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, EDIT_IMAGE_SELECTED );
+ backButton.ClickedSignal().Connect( this, &ExampleApp::OnBackButtonPressed);
+ backButton.SetLeaveRequired( true );
+ mToolBar.AddControl( backButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
+
+ mNavigationView = Toolkit::NavigationView::New();
+ mNavigationView.SetResizePolicy( ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS );
+ mNavigationView.SetAnchorPoint( AnchorPoint::TOP_LEFT);
+
+ stage.Add( mNavigationView );
+
+ // Set up the background gradient.
+ Property::Array stopOffsets;
+ stopOffsets.PushBack( 0.0f );
+ stopOffsets.PushBack( 1.0f );
+ Property::Array stopColors;
+ stopColors.PushBack( Color::WHITE );
+ stopColors.PushBack( Vector4( 0.45f, 0.70f, 0.80f, 1.0f ) ); // Medium bright, pastel blue
+ const float percentageStageHeight = stage.GetSize().height * 0.6f;
+
+ mNavigationView.SetProperty( Toolkit::Control::Property::BACKGROUND, Dali::Property::Map()
+ .Add( Toolkit::Visual::Property::TYPE, Dali::Toolkit::Visual::GRADIENT )
+ .Add( Toolkit::GradientVisual::Property::STOP_OFFSET, stopOffsets )
+ .Add( Toolkit::GradientVisual::Property::STOP_COLOR, stopColors )
+ .Add( Toolkit::GradientVisual::Property::START_POSITION, Vector2( 0.0f, -percentageStageHeight ) )
+ .Add( Toolkit::GradientVisual::Property::END_POSITION, Vector2( 0.0f, percentageStageHeight ) )
+ .Add( Toolkit::GradientVisual::Property::UNITS, Toolkit::GradientVisual::Units::USER_SPACE ) );
+
+ SetUpItemView();
+ mNavigationView.Push( mItemView );
mTimer = Timer::New( 500 ); // ms
mTimer.TickSignal().Connect( this, &ExampleApp::OnTimer);
{
if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) )
{
- mApp.Quit();
+ OnQuitOrBack();
}
}
}
+ /**
+ * Event handler when Builder wants to quit (we only want to close the shown json unless we're at the top-level)
+ */
+ void OnQuitOrBack()
+ {
+ if ( mItemView.OnStage() )
+ {
+ mApp.Quit();
+ }
+ else
+ {
+ mNavigationView.Pop();
+ }
+ }
+
private:
Application& mApp;
- GridLayoutPtr mGridLayout;
+ ItemLayoutPtr mLayout;
ItemView mItemView;
+ Toolkit::NavigationView mNavigationView;
- Toolkit::View mView;
- unsigned int mOrientation;
+ Toolkit::Control mView;
Toolkit::ToolBar mToolBar;
- TextView mTitleActor; ///< The Toolbar's Title.
+ TextLabel mTitleActor;
Layer mBuilderLayer;
- Toolkit::Popup mMenu;
-
TapGestureDetector mTapDetector;
// builder
FileWatcher mFileWatcher;
Timer mTimer;
-
-
};
//------------------------------------------------------------------------------
//
//
//------------------------------------------------------------------------------
-int main(int argc, char **argv)
+int DALI_EXPORT_API main(int argc, char **argv)
{
- if(argc > 1)
+ if(argc > 2)
{
- USER_DIRECTORY = argv[1];
+ if(strcmp(argv[1], "-f") == 0)
+ {
+ USER_DIRECTORY = argv[2];
+ }
}
- Application app = Application::New(&argc, &argv);
+ Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);
ExampleApp dali_app(app);