/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 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 <sstream>
-#include <iostream>
-#include <vector>
-#include <string>
-#include <algorithm>
-#include <cstdlib> // rand
#include "shared/view.h"
#include <dali/dali.h>
#include <dali-toolkit/dali-toolkit.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
using namespace Dali;
using namespace Dali::Toolkit;
};
const char* IMAGE_PATHS[] = {
- DALI_IMAGE_DIR "gallery-medium-1.jpg",
- DALI_IMAGE_DIR "gallery-medium-2.jpg",
- DALI_IMAGE_DIR "gallery-medium-3.jpg",
- DALI_IMAGE_DIR "gallery-medium-4.jpg",
- DALI_IMAGE_DIR "gallery-medium-5.jpg",
- DALI_IMAGE_DIR "gallery-medium-6.jpg",
- DALI_IMAGE_DIR "gallery-medium-7.jpg",
- DALI_IMAGE_DIR "gallery-medium-8.jpg",
- DALI_IMAGE_DIR "gallery-medium-9.jpg",
- DALI_IMAGE_DIR "gallery-medium-10.jpg",
- DALI_IMAGE_DIR "gallery-medium-11.jpg",
- DALI_IMAGE_DIR "gallery-medium-12.jpg",
- DALI_IMAGE_DIR "gallery-medium-13.jpg",
- DALI_IMAGE_DIR "gallery-medium-14.jpg",
- DALI_IMAGE_DIR "gallery-medium-15.jpg",
- DALI_IMAGE_DIR "gallery-medium-16.jpg",
- DALI_IMAGE_DIR "gallery-medium-17.jpg",
- DALI_IMAGE_DIR "gallery-medium-18.jpg",
- DALI_IMAGE_DIR "gallery-medium-19.jpg",
- DALI_IMAGE_DIR "gallery-medium-20.jpg",
- DALI_IMAGE_DIR "gallery-medium-21.jpg",
- DALI_IMAGE_DIR "gallery-medium-22.jpg",
- DALI_IMAGE_DIR "gallery-medium-23.jpg",
- DALI_IMAGE_DIR "gallery-medium-24.jpg",
- DALI_IMAGE_DIR "gallery-medium-25.jpg",
- DALI_IMAGE_DIR "gallery-medium-26.jpg",
- DALI_IMAGE_DIR "gallery-medium-27.jpg",
- DALI_IMAGE_DIR "gallery-medium-28.jpg",
- DALI_IMAGE_DIR "gallery-medium-29.jpg",
- DALI_IMAGE_DIR "gallery-medium-30.jpg",
- DALI_IMAGE_DIR "gallery-medium-31.jpg",
- DALI_IMAGE_DIR "gallery-medium-32.jpg",
- DALI_IMAGE_DIR "gallery-medium-33.jpg",
- DALI_IMAGE_DIR "gallery-medium-34.jpg",
- DALI_IMAGE_DIR "gallery-medium-35.jpg",
- DALI_IMAGE_DIR "gallery-medium-36.jpg",
- DALI_IMAGE_DIR "gallery-medium-37.jpg",
- DALI_IMAGE_DIR "gallery-medium-38.jpg",
- DALI_IMAGE_DIR "gallery-medium-39.jpg",
- DALI_IMAGE_DIR "gallery-medium-40.jpg",
- DALI_IMAGE_DIR "gallery-medium-41.jpg",
- DALI_IMAGE_DIR "gallery-medium-42.jpg",
- DALI_IMAGE_DIR "gallery-medium-43.jpg",
- DALI_IMAGE_DIR "gallery-medium-44.jpg",
- DALI_IMAGE_DIR "gallery-medium-45.jpg",
- DALI_IMAGE_DIR "gallery-medium-46.jpg",
- DALI_IMAGE_DIR "gallery-medium-47.jpg",
- DALI_IMAGE_DIR "gallery-medium-48.jpg",
- DALI_IMAGE_DIR "gallery-medium-49.jpg",
- DALI_IMAGE_DIR "gallery-medium-50.jpg",
- DALI_IMAGE_DIR "gallery-medium-51.jpg",
- DALI_IMAGE_DIR "gallery-medium-52.jpg",
- DALI_IMAGE_DIR "gallery-medium-53.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-1.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-2.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-3.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-4.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-5.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-6.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-7.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-8.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-9.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-10.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-11.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-12.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-13.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-14.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-15.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-16.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-17.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-18.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-19.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-20.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-21.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-22.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-23.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-24.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-25.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-26.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-27.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-28.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-29.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-30.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-31.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-32.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-33.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-34.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-35.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-36.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-37.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-38.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-39.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-40.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-41.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-42.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-43.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-44.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-45.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-46.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-47.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-48.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-49.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-50.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-51.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-52.jpg",
+ DEMO_IMAGE_DIR "gallery-medium-53.jpg",
};
const unsigned int NUM_IMAGES = sizeof(IMAGE_PATHS) / sizeof(char*);
-AlphaFunction ALPHA_FUNCTIONS[] = { AlphaFunctions::Linear,
- AlphaFunctions::EaseIn,
- AlphaFunctions::EaseOut };
-
-const unsigned int NUM_ALPHA_FUNCTIONS = sizeof(ALPHA_FUNCTIONS) / sizeof(AlphaFunction);
-
-//const char* ALPHA_FUNCTIONS_TEXT[] = { "Linear",
-// "EaseIn",
-// "EaseOut" };
-
const char* BACKGROUND_IMAGE( "" );
-const char* TOOLBAR_IMAGE( DALI_IMAGE_DIR "top-bar.png" );
-const char* EDIT_IMAGE( DALI_IMAGE_DIR "icon-edit.png" );
-const char* SPIRAL_LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-item-view-layout-spiral.png" );
-const char* GRID_LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-item-view-layout-grid.png" );
-const char* DEPTH_LAYOUT_IMAGE( DALI_IMAGE_DIR "icon-item-view-layout-depth.png" );
-const char* DELETE_IMAGE( DALI_IMAGE_DIR "icon-delete.png" );
-const char* REPLACE_IMAGE( DALI_IMAGE_DIR "icon-replace.png" );
-const char* INSERT_IMAGE( DALI_IMAGE_DIR "icon-insert.png" );
-const char* SELECTED_IMAGE( DALI_IMAGE_DIR "item-select-check.png" );
+const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
+const char* EDIT_IMAGE( DEMO_IMAGE_DIR "icon-edit.png" );
+const char* EDIT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-edit-selected.png" );
+const char* SPIRAL_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-spiral.png" );
+const char* SPIRAL_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-spiral-selected.png" );
+const char* GRID_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-grid.png" );
+const char* GRID_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-grid-selected.png" );
+const char* DEPTH_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-depth.png" );
+const char* DEPTH_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-depth-selected.png" );
+const char* DELETE_IMAGE( DEMO_IMAGE_DIR "icon-delete.png" );
+const char* DELETE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-delete-selected.png" );
+const char* REPLACE_IMAGE( DEMO_IMAGE_DIR "icon-replace.png" );
+const char* REPLACE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" );
+const char* INSERT_IMAGE( DEMO_IMAGE_DIR "icon-insert.png" );
+const char* INSERT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-insert-selected.png" );
+const char* SELECTED_IMAGE( DEMO_IMAGE_DIR "item-select-check.png" );
const char* APPLICATION_TITLE( "ItemView" );
const char* SPIRAL_LABEL("Spiral");
const char* GRID_LABEL("Grid");
const char* DEPTH_LABEL("Depth");
-const char* ITEM_BORDER_IMAGE_PATH( DALI_IMAGE_DIR "frame-128x128.png" );
-const Vector3 ITEM_BORDER_MARGIN_SIZE(24, 24, 0);
-
-// These values depend on the border image
-const float ITEM_IMAGE_BORDER_LEFT = 13.0f;
-const float ITEM_IMAGE_BORDER_RIGHT = 13.0f;
-const float ITEM_IMAGE_BORDER_TOP = 13.0f;
-const float ITEM_IMAGE_BORDER_BOTTOM = 13.0f;
+const float ITEM_BORDER_SIZE = 2.0f;
-const unsigned int DEPTH_LAYOUT_ROWS_PORTRAIT = 26;
-const unsigned int DEPTH_LAYOUT_ROWS_LANDSCAPE = 16;
-const float DEPTH_LAYOUT_TILT_ANGLE_PORTRAIT = 25.0f;
-const float DEPTH_LAYOUT_TILT_ANGLE_LANDSCAPE = 21.0f;
-const float DEPTH_LAYOUT_ROW_SPACING_FACTOR = 0.1f;
const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT = 1.0f;
const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE = 0.8f;
-const float DEPTH_LAYOUT_BOTTOM_MARGIN_FACTOR_PORTRAIT = 0.2f;
-const float DEPTH_LAYOUT_BOTTOM_MARGIN_FACTOR_LANDSCAPE = 0.1f;
+const float DEPTH_LAYOUT_COLUMNS = 3.0f;
-const float SPIRAL_LAYOUT_REVOLUTION_NUMBER_PORTRAIT = 4.5f;
-const float SPIRAL_LAYOUT_REVOLUTION_NUMBER_LANDSCAPE = 2.5f;
-
-const float DEPTH_LAYOUT_HEIGHT_SCALE = 20.0f;
const float MIN_SWIPE_DISTANCE = 15.0f;
const float MIN_SWIPE_SPEED = 5.0f;
const float MENU_OPTION_HEIGHT(140.0f);
const float LABEL_TEXT_SIZE_Y = 20.0f;
-//const char* DEFAULT_TEXT_STYLE_FONT_FAMILY("HelveticaNue");
-//const char* DEFAULT_TEXT_STYLE_FONT_STYLE("Regular");
-//const Vector4 DEFAULT_TEXT_STYLE_COLOR(1.0f, 1.0f, 1.0f, 1.0f);
-
const Vector3 INITIAL_OFFSCREEN_POSITION( 1000.0f, 0, -1000.0f );
-static Vector3 DepthLayoutItemSizeFunctionPortrait(unsigned int numberOfColumns, float layoutWidth)
+const float SCROLL_TO_ITEM_ANIMATION_TIME = 5.f;
+
+static Vector3 DepthLayoutItemSizeFunctionPortrait( float layoutWidth )
{
- float width = (layoutWidth / static_cast<float>(numberOfColumns + 1)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT;
+ float width = ( layoutWidth / ( DEPTH_LAYOUT_COLUMNS + 1.0f ) ) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT;
// 1x1 aspect ratio
return Vector3(width, width, width);
}
-static Vector3 DepthLayoutItemSizeFunctionLandscape(unsigned int numberOfColumns, float layoutWidth)
+static Vector3 DepthLayoutItemSizeFunctionLandscape( float layoutWidth )
{
- float width = (layoutWidth / static_cast<float>(numberOfColumns + 1)) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE;
+ float width = ( layoutWidth / ( DEPTH_LAYOUT_COLUMNS + 1.0f ) ) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE;
// 1x1 aspect ratio
return Vector3(width, width, width);
}
-static float DepthLayoutBottomMarginFunctionPortrait(float layoutHeight)
-{
- return layoutHeight * DEPTH_LAYOUT_BOTTOM_MARGIN_FACTOR_PORTRAIT;
-}
-
-static float DepthLayoutBottomMarginFunctionLandscape(float layoutHeight)
-{
- return layoutHeight * DEPTH_LAYOUT_BOTTOM_MARGIN_FACTOR_LANDSCAPE;
-}
-
-}
+} // unnamed namespace
/**
* This example shows how to use ItemView UI control.
ItemViewExample( Application& application )
: mApplication( application ),
mMode( MODE_NORMAL ),
- mMenuShown( false ),
mOrientation( 0 ),
mCurrentLayout( SPIRAL_LAYOUT ),
- mDurationSeconds( 1.0f ),
- mAlphaFuncIndex( 0u )
+ mDurationSeconds( 0.25f )
{
// Connect to the Application's Init signal
mApplication.InitSignal().Connect(this, &ItemViewExample::OnInit);
{
Stage stage = Dali::Stage::GetCurrent();
stage.KeyEventSignal().Connect(this, &ItemViewExample::OnKeyEvent);
+ stage.GetRootLayer().SetBehavior(Layer::LAYER_3D);
Vector2 stageSize = Stage::GetCurrent().GetSize();
- // Create a border image shared by all the item actors
- mBorderImage = ResourceImage::New(ITEM_BORDER_IMAGE_PATH);
-
// Creates a default view with a default tool bar.
// The view is added to the stage.
+
Layer contents = DemoHelper::CreateView( mApplication,
mView,
mToolBar,
TOOLBAR_IMAGE,
"" );
- mView.OrientationAnimationStartedSignal().Connect( this, &ItemViewExample::OnOrientationChanged );
-
// Create an edit mode button. (left of toolbar)
Toolkit::PushButton editButton = Toolkit::PushButton::New();
- editButton.SetBackgroundImage( ResourceImage::New( EDIT_IMAGE ) );
+ editButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, EDIT_IMAGE );
+ editButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, EDIT_IMAGE_SELECTED );
editButton.ClickedSignal().Connect( this, &ItemViewExample::OnModeButtonClicked);
editButton.SetLeaveRequired( true );
mToolBar.AddControl( editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
// Create a layout toggle button. (right of toolbar)
mLayoutButton = Toolkit::PushButton::New();
- mLayoutButton.SetBackgroundImage( ResourceImage::New( SPIRAL_LAYOUT_IMAGE ) );
+ mLayoutButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE );
+ mLayoutButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE_SELECTED );
mLayoutButton.ClickedSignal().Connect( this, &ItemViewExample::OnLayoutButtonClicked);
mLayoutButton.SetLeaveRequired( true );
mToolBar.AddControl( mLayoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
mDeleteButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
mDeleteButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
mDeleteButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
- mDeleteButton.SetDrawMode( DrawMode::OVERLAY );
- mDeleteButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
- mDeleteButton.SetButtonImage( ResourceImage::New( DELETE_IMAGE ) );
- mDeleteButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
+ mDeleteButton.SetDrawMode( DrawMode::OVERLAY_2D );
+ mDeleteButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DELETE_IMAGE );
+ mDeleteButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DELETE_IMAGE_SELECTED );
+ mDeleteButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE );
+ mDeleteButton.SetSize( Vector2( stageSize.width * 0.15f, stageSize.width * 0.15f ) );
mDeleteButton.ClickedSignal().Connect( this, &ItemViewExample::OnDeleteButtonClicked);
mDeleteButton.SetLeaveRequired( true );
mDeleteButton.SetVisible( false );
mInsertButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
mInsertButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
mInsertButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
- mInsertButton.SetDrawMode( DrawMode::OVERLAY );
- mInsertButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
- mInsertButton.SetButtonImage( ResourceImage::New( INSERT_IMAGE ) );
+ mInsertButton.SetDrawMode( DrawMode::OVERLAY_2D );
+ mInsertButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, INSERT_IMAGE );
+ mInsertButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, INSERT_IMAGE_SELECTED );
+ mInsertButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE );
mInsertButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
mInsertButton.ClickedSignal().Connect( this, &ItemViewExample::OnInsertButtonClicked);
mInsertButton.SetLeaveRequired( true );
mReplaceButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
mReplaceButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
mReplaceButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
- mReplaceButton.SetDrawMode( DrawMode::OVERLAY );
- mReplaceButton.SetBackgroundImage( ResourceImage::New( TOOLBAR_IMAGE ) );
- mReplaceButton.SetButtonImage( ResourceImage::New( REPLACE_IMAGE ) );
+ mReplaceButton.SetDrawMode( DrawMode::OVERLAY_2D );
+ mReplaceButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, REPLACE_IMAGE );
+ mReplaceButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, REPLACE_IMAGE_SELECTED );
+ mReplaceButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE );
mReplaceButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
mReplaceButton.ClickedSignal().Connect( this, &ItemViewExample::OnReplaceButtonClicked);
mReplaceButton.SetLeaveRequired( true );
// Display item view on the stage
stage.Add( mItemView );
+ stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
// Create the layouts
- mSpiralLayout = SpiralLayout::New();
- mDepthLayout = DepthLayout::New();
- mGridLayout = GridLayout::New();
+ mSpiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
+ mDepthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
+ mGridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
// Add the layouts to item view
mItemView.AddLayout(*mSpiralLayout);
mItemView.SetMinimumSwipeSpeed(MIN_SWIPE_SPEED);
// Activate the spiral layout
- UseLayout(mCurrentLayout, 0.0f);
+ SetLayout( mCurrentLayout );
mItemView.SetKeyboardFocusable( true );
KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &ItemViewExample::OnKeyboardPreFocusChange );
SetLayoutTitle();
SetLayoutImage();
- // Store one 1x1 white image for multiple items to share for backgrounds:
- mWhiteImage = BufferImage::WHITE();
+ mLongPressDetector = LongPressGestureDetector::New();
+ mLongPressDetector.Attach( mItemView );
+ mLongPressDetector.DetectedSignal().Connect( this, &ItemViewExample::OnLongPress );
}
- Actor OnKeyboardPreFocusChange( Actor current, Actor proposed, Control::KeyboardFocusNavigationDirection direction )
+ Actor OnKeyboardPreFocusChange( Actor current, Actor proposed, Control::KeyboardFocus::Direction direction )
{
if ( !current && !proposed )
{
}
/**
- * Switch to a different item view layout
+ * Animate to a different layout
*/
- void UseLayout(int layoutId, float duration)
+ void ChangeLayout()
{
- // Set the new orientation to the layout
- mItemView.GetLayout(layoutId)->SetOrientation(static_cast<ControlOrientation::Type>(mOrientation / 90));
+ Animation animation = Animation::New( mDurationSeconds );
+ animation.FinishedSignal().Connect( this, &ItemViewExample::AnimationFinished );
+ animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 0.0f );
+ animation.Play();
+ }
- Vector2 stageSize = Stage::GetCurrent().GetSize();
+ void AnimationFinished( Animation& )
+ {
+ SetLayout( mCurrentLayout );
+
+ Animation animation = Animation::New( mDurationSeconds );
+ animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 1.0f );
+ animation.Play();
+ }
- if(layoutId == SPIRAL_LAYOUT)
+ /**
+ * Switch to a different item view layout
+ */
+ void SetLayout( int layoutId )
+ {
+ Stage stage = Dali::Stage::GetCurrent();
+ switch( mCurrentLayout )
{
- mSpiralLayout->SetRevolutionDistance(stageSize.height / Stage::GetCurrent().GetDpi().y * 45.0f);
+ case SPIRAL_LAYOUT:
+ case DEPTH_LAYOUT:
+ {
+ stage.GetRootLayer().SetBehavior(Layer::LAYER_3D);
+ break;
+ }
+ case GRID_LAYOUT:
+ {
+ stage.GetRootLayer().SetBehavior(Layer::LAYER_UI);
+ break;
+ }
}
- if(layoutId == GRID_LAYOUT)
- {
- // Set up the grid layout according to the new orientation
- float layoutWidth = Toolkit::IsHorizontal(mGridLayout->GetOrientation()) ? stageSize.height : stageSize.width;
- float gridItemSize = (layoutWidth / mGridLayout->GetNumberOfColumns()) * 0.5f;
- mGridLayout->SetScrollSpeedFactor(mGridLayout->GetNumberOfColumns() / gridItemSize);
+ // Set the new orientation to the layout
+ mItemView.GetLayout(layoutId)->SetOrientation(static_cast<ControlOrientation::Type>(mOrientation / 90));
- float toolbarHeight = mToolBar.GetCurrentSize().y;
- mGridLayout->SetTopMargin(toolbarHeight + mGridLayout->GetRowSpacing());
- }
+ Vector2 stageSize = Stage::GetCurrent().GetSize();
if(layoutId == DEPTH_LAYOUT)
{
// Set up the depth layout according to the new orientation
if(Toolkit::IsVertical(mDepthLayout->GetOrientation()))
{
- mDepthLayout->SetRowSpacing(stageSize.height * DEPTH_LAYOUT_ROW_SPACING_FACTOR);
- mDepthLayout->SetNumberOfRows(DEPTH_LAYOUT_ROWS_PORTRAIT);
- mDepthLayout->SetTiltAngle( Degree( DEPTH_LAYOUT_TILT_ANGLE_PORTRAIT - mDepthLayout->GetNumberOfColumns() ) );
- mDepthLayout->SetItemSizeFunction(DepthLayoutItemSizeFunctionPortrait);
- mDepthLayout->SetBottomMarginFunction(DepthLayoutBottomMarginFunctionPortrait);
+ mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionPortrait( stageSize.width ) );
}
else
{
- mDepthLayout->SetRowSpacing(stageSize.width * DEPTH_LAYOUT_ROW_SPACING_FACTOR);
- mDepthLayout->SetNumberOfRows(DEPTH_LAYOUT_ROWS_LANDSCAPE);
- mDepthLayout->SetTiltAngle( Degree( DEPTH_LAYOUT_TILT_ANGLE_LANDSCAPE - mDepthLayout->GetNumberOfColumns() ) );
- mDepthLayout->SetItemSizeFunction(DepthLayoutItemSizeFunctionLandscape);
- mDepthLayout->SetBottomMarginFunction(DepthLayoutBottomMarginFunctionLandscape);
+ mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionLandscape( stageSize.height ) );
}
}
mItemView.SetAnchoring(layoutId == DEPTH_LAYOUT);
// Activate the layout
- mItemView.ActivateLayout(layoutId, Vector3(stageSize.x, stageSize.y, stageSize.x), duration);
- }
-
- /**
- * Orientation changed signal callback
- * @param orientation
- */
- void OnOrientationChanged( View view, Animation& animation, const Orientation& orientation )
- {
- const unsigned int angle = orientation.GetDegrees();
-
- // If orientation really changed
- if( mOrientation != angle )
- {
- // Remember orientation
- mOrientation = angle;
-
- UseLayout(mCurrentLayout, mDurationSeconds);
- }
+ mItemView.ActivateLayout( layoutId, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
}
bool OnLayoutButtonClicked( Toolkit::Button button )
// Switch to the next layout
mCurrentLayout = (mCurrentLayout + 1) % mItemView.GetLayoutCount();
- UseLayout(mCurrentLayout, mDurationSeconds);
+ ChangeLayout();
SetLayoutTitle();
SetLayoutImage();
}
}
+ void OnLongPress( Actor actor, const LongPressGesture& gesture )
+ {
+ switch( gesture.state )
+ {
+ case Gesture::Started:
+ {
+ const Size& size = Stage::GetCurrent().GetSize();
+
+ ItemRange range( 0u, 0u );
+ mItemView.GetItemsRange( range );
+
+ const unsigned int item = ( gesture.screenPoint.y < 0.5f * size.height ) ? range.begin : range.end;
+ mItemView.ScrollToItem( item, SCROLL_TO_ITEM_ANIMATION_TIME );
+
+ break;
+ }
+ case Gesture::Finished:
+ {
+ Property::Map attributes;
+ mItemView.DoAction( "stopScrolling", attributes );
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+ }
+
bool OnDeleteButtonClicked( Toolkit::Button button )
{
ItemIdContainer removeList;
{
case SPIRAL_LAYOUT:
{
- mLayoutButton.SetBackgroundImage( ResourceImage::New( SPIRAL_LAYOUT_IMAGE ) );
+ mLayoutButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE );
+ mLayoutButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE_SELECTED );
break;
}
case GRID_LAYOUT:
{
- mLayoutButton.SetBackgroundImage( ResourceImage::New( GRID_LAYOUT_IMAGE ) );
+ mLayoutButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, GRID_LAYOUT_IMAGE );
+ mLayoutButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, GRID_LAYOUT_IMAGE_SELECTED );
break;
}
case DEPTH_LAYOUT:
{
- mLayoutButton.SetBackgroundImage( ResourceImage::New( DEPTH_LAYOUT_IMAGE ) );
+ mLayoutButton.SetProperty( Toolkit::Button::Property::UNSELECTED_BACKGROUND_VISUAL, DEPTH_LAYOUT_IMAGE );
+ mLayoutButton.SetProperty( Toolkit::Button::Property::SELECTED_BACKGROUND_VISUAL, DEPTH_LAYOUT_IMAGE_SELECTED );
break;
}
*/
virtual Actor NewItem(unsigned int itemId)
{
- // Create an image actor for this item
- Image image = ResourceImage::New( IMAGE_PATHS[itemId % NUM_IMAGES] );
- Actor actor = ImageActor::New(image);
+ // Create an image view for this item
+ Property::Map propertyMap;
+ propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
+ propertyMap.Insert(ImageVisual::Property::URL, IMAGE_PATHS[ itemId % NUM_IMAGES ] );
+ propertyMap.Insert(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FILL);
+ ImageView actor = ImageView::New();
+ actor.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
+ actor.SetZ( 0.0f );
actor.SetPosition( INITIAL_OFFSCREEN_POSITION );
// Add a border image child actor
- ImageActor borderActor = ImageActor::New(mBorderImage);
+ ImageView borderActor = ImageView::New();
borderActor.SetParentOrigin( ParentOrigin::CENTER );
borderActor.SetAnchorPoint( AnchorPoint::CENTER );
- borderActor.SetPosition( 0.f, 0.f, 1.f );
- borderActor.SetStyle( ImageActor::STYLE_NINE_PATCH );
- borderActor.SetNinePatchBorder( Vector4( ITEM_IMAGE_BORDER_LEFT, ITEM_IMAGE_BORDER_TOP, ITEM_IMAGE_BORDER_RIGHT, ITEM_IMAGE_BORDER_BOTTOM ) );
- borderActor.SetColorMode( USE_OWN_MULTIPLY_PARENT_COLOR ); // darken with parent image-actor
- borderActor.SetSizeMode( SIZE_FIXED_OFFSET_FROM_PARENT );
- borderActor.SetSizeModeFactor( ITEM_BORDER_MARGIN_SIZE );
+ borderActor.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
+ borderActor.SetSizeModeFactor( Vector3( 2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f ) );
+ borderActor.SetColorMode( USE_PARENT_COLOR );
+
+ Property::Map borderProperty;
+ borderProperty.Insert( Toolkit::Visual::Property::TYPE, Visual::BORDER );
+ borderProperty.Insert( BorderVisual::Property::COLOR, Color::WHITE );
+ borderProperty.Insert( BorderVisual::Property::SIZE, ITEM_BORDER_SIZE );
+ borderProperty.Insert( BorderVisual::Property::ANTI_ALIASING, true );
+ borderActor.SetProperty( ImageView::Property::IMAGE, borderProperty );
+
actor.Add(borderActor);
+
actor.SetKeyboardFocusable( true );
Vector3 spiralItemSize;
static_cast<ItemLayout&>(*mSpiralLayout).GetItemSize( 0u, Vector3( Stage::GetCurrent().GetSize() ), spiralItemSize );
// Add a checkbox child actor; invisible until edit-mode is enabled
-
- ImageActor checkbox = ImageActor::New( mWhiteImage );
+ ImageView checkbox = ImageView::New();
checkbox.SetName( "CheckBox" );
- checkbox.SetColor( Vector4(0.0f,0.0f,0.0f,0.6f) );
+ checkbox.SetColorMode( USE_PARENT_COLOR );
checkbox.SetParentOrigin( ParentOrigin::TOP_RIGHT );
checkbox.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
checkbox.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
checkbox.SetPosition( -SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH );
- checkbox.SetZ( 1.0f );
+ checkbox.SetZ( 0.1f );
+
+ Property::Map solidColorProperty;
+ solidColorProperty.Insert( Toolkit::Visual::Property::TYPE, Visual::COLOR );
+ solidColorProperty.Insert( ColorVisual::Property::MIX_COLOR, Vector4(0.f, 0.f, 0.f, 0.6f) );
+ checkbox.SetProperty( ImageView::Property::IMAGE, solidColorProperty );
+
if( MODE_REMOVE_MANY != mMode &&
MODE_INSERT_MANY != mMode &&
MODE_REPLACE_MANY != mMode )
{
checkbox.SetVisible( false );
}
- actor.Add( checkbox );
+ borderActor.Add( checkbox );
- ImageActor tick = ImageActor::New( ResourceImage::New(SELECTED_IMAGE) );
- tick.SetColorMode( USE_OWN_COLOR );
+ ImageView tick = ImageView::New( SELECTED_IMAGE );
tick.SetName( "Tick" );
+ tick.SetColorMode( USE_PARENT_COLOR );
tick.SetParentOrigin( ParentOrigin::TOP_RIGHT );
tick.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
tick.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
- tick.SetZ( 1.0f );
+ tick.SetZ( 0.2f );
tick.SetVisible( false );
checkbox.Add( tick );
*/
void SetTitle(const std::string& title)
{
- // TODO
- }
-
- void ShowMenu()
- {
- Stage stage = Stage::GetCurrent();
- const float popupWidth = stage.GetSize().x * 0.75f;
-
- mMenu = Toolkit::Popup::New();
- mMenu.SetParentOrigin( ParentOrigin::BOTTOM_LEFT );
- mMenu.SetAnchorPoint( AnchorPoint::BOTTOM_LEFT );
- mMenu.OutsideTouchedSignal().Connect( this, &ItemViewExample::HideMenu );
- stage.Add( mMenu );
-
- TableView tableView = TableView::New( 0, 0 );
- Vector2 tableSize = Vector2( popupWidth, MENU_OPTION_HEIGHT * 2 );
- tableView.SetSize( tableSize );
- mMenu.Add( tableView );
-
- Slider slider = Slider::New();
- slider.SetProperty( Slider::Property::LOWER_BOUND, 0.0f );
- slider.SetProperty( Slider::Property::UPPER_BOUND, 3.0f );
- slider.SetProperty( Slider::Property::VALUE, mDurationSeconds );
- slider.SetProperty( Slider::Property::VALUE_PRECISION, 2 );
- slider.SetProperty( Slider::Property::SHOW_POPUP, true );
- slider.ValueChangedSignal().Connect( this, &ItemViewExample::SliderValueChange );
- tableView.AddChild( slider, TableView::CellPosition( 0, 0 ) );
- tableView.SetRelativeHeight( 0, 0.5f );
-
- mMenu.Show();
- mMenuShown = true;
- }
-
- bool SliderValueChange( Toolkit::Slider slider, float value )
- {
- mDurationSeconds = value;
-
- return true;
- }
-
- void ChangeAlphaFunctionOnTap( Actor actor, const TapGesture& tap )
- {
- if( NUM_ALPHA_FUNCTIONS <= ++mAlphaFuncIndex )
- {
- mAlphaFuncIndex = 0;
- }
-
- if( mItemView )
- {
- mItemView.GetActiveLayout()->SetAlphaFunction( ALPHA_FUNCTIONS[mAlphaFuncIndex] );
- }
- }
-
- void HideMenu()
- {
- mTapDetector.Reset();
-
- if( mMenu )
+ if(!mTitleActor)
{
- mMenu.Hide();
- mMenu.Reset();
+ mTitleActor = DemoHelper::CreateToolBarLabel( "" );
+ // Add title to the tool bar.
+ mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
}
- mMenuShown = false;
+ mTitleActor.SetProperty( TextLabel::Property::TEXT, title );
}
/**
{
if(event.state == KeyEvent::Down)
{
- if( IsKey( event, DALI_KEY_MENU ) )
- {
- if( mMenuShown )
- {
- HideMenu();
- }
- else
- {
- ShowMenu();
- }
- }
- else if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
+ if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
{
- if( mMenuShown )
- {
- HideMenu();
- }
- else
- {
- mApplication.Quit();
- }
+ mApplication.Quit();
}
}
}
Application& mApplication;
Mode mMode;
- bool mMenuShown;
- Toolkit::View mView;
+ Toolkit::Control mView;
unsigned int mOrientation;
Toolkit::ToolBar mToolBar;
+ TextLabel mTitleActor; ///< The Toolbar's Title.
ItemView mItemView;
- Image mBorderImage;
unsigned int mCurrentLayout;
float mDurationSeconds;
- SpiralLayoutPtr mSpiralLayout;
- DepthLayoutPtr mDepthLayout;
- GridLayoutPtr mGridLayout;
-
- Toolkit::Popup mMenu;
+ ItemLayoutPtr mSpiralLayout;
+ ItemLayoutPtr mDepthLayout;
+ ItemLayoutPtr mGridLayout;
TapGestureDetector mTapDetector;
Toolkit::PushButton mLayoutButton;
Toolkit::PushButton mInsertButton;
Toolkit::PushButton mReplaceButton;
- unsigned int mAlphaFuncIndex;
- BufferImage mWhiteImage;
+ LongPressGestureDetector mLongPressDetector;
};
-void RunTest(Application& app)
+int DALI_EXPORT_API main(int argc, char **argv)
{
+ Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);
ItemViewExample test(app);
-
app.MainLoop();
-}
-
-int main(int argc, char **argv)
-{
- Application app = Application::New(&argc, &argv);
-
- RunTest(app);
-
return 0;
}