2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "shared/view.h"
21 #include <dali/dali.h>
22 #include <dali-toolkit/dali-toolkit.h>
25 using namespace Dali::Toolkit;
39 const char* IMAGE_PATHS[] = {
40 DEMO_IMAGE_DIR "gallery-medium-1.jpg",
41 DEMO_IMAGE_DIR "gallery-medium-2.jpg",
42 DEMO_IMAGE_DIR "gallery-medium-3.jpg",
43 DEMO_IMAGE_DIR "gallery-medium-4.jpg",
44 DEMO_IMAGE_DIR "gallery-medium-5.jpg",
45 DEMO_IMAGE_DIR "gallery-medium-6.jpg",
46 DEMO_IMAGE_DIR "gallery-medium-7.jpg",
47 DEMO_IMAGE_DIR "gallery-medium-8.jpg",
48 DEMO_IMAGE_DIR "gallery-medium-9.jpg",
49 DEMO_IMAGE_DIR "gallery-medium-10.jpg",
50 DEMO_IMAGE_DIR "gallery-medium-11.jpg",
51 DEMO_IMAGE_DIR "gallery-medium-12.jpg",
52 DEMO_IMAGE_DIR "gallery-medium-13.jpg",
53 DEMO_IMAGE_DIR "gallery-medium-14.jpg",
54 DEMO_IMAGE_DIR "gallery-medium-15.jpg",
55 DEMO_IMAGE_DIR "gallery-medium-16.jpg",
56 DEMO_IMAGE_DIR "gallery-medium-17.jpg",
57 DEMO_IMAGE_DIR "gallery-medium-18.jpg",
58 DEMO_IMAGE_DIR "gallery-medium-19.jpg",
59 DEMO_IMAGE_DIR "gallery-medium-20.jpg",
60 DEMO_IMAGE_DIR "gallery-medium-21.jpg",
61 DEMO_IMAGE_DIR "gallery-medium-22.jpg",
62 DEMO_IMAGE_DIR "gallery-medium-23.jpg",
63 DEMO_IMAGE_DIR "gallery-medium-24.jpg",
64 DEMO_IMAGE_DIR "gallery-medium-25.jpg",
65 DEMO_IMAGE_DIR "gallery-medium-26.jpg",
66 DEMO_IMAGE_DIR "gallery-medium-27.jpg",
67 DEMO_IMAGE_DIR "gallery-medium-28.jpg",
68 DEMO_IMAGE_DIR "gallery-medium-29.jpg",
69 DEMO_IMAGE_DIR "gallery-medium-30.jpg",
70 DEMO_IMAGE_DIR "gallery-medium-31.jpg",
71 DEMO_IMAGE_DIR "gallery-medium-32.jpg",
72 DEMO_IMAGE_DIR "gallery-medium-33.jpg",
73 DEMO_IMAGE_DIR "gallery-medium-34.jpg",
74 DEMO_IMAGE_DIR "gallery-medium-35.jpg",
75 DEMO_IMAGE_DIR "gallery-medium-36.jpg",
76 DEMO_IMAGE_DIR "gallery-medium-37.jpg",
77 DEMO_IMAGE_DIR "gallery-medium-38.jpg",
78 DEMO_IMAGE_DIR "gallery-medium-39.jpg",
79 DEMO_IMAGE_DIR "gallery-medium-40.jpg",
80 DEMO_IMAGE_DIR "gallery-medium-41.jpg",
81 DEMO_IMAGE_DIR "gallery-medium-42.jpg",
82 DEMO_IMAGE_DIR "gallery-medium-43.jpg",
83 DEMO_IMAGE_DIR "gallery-medium-44.jpg",
84 DEMO_IMAGE_DIR "gallery-medium-45.jpg",
85 DEMO_IMAGE_DIR "gallery-medium-46.jpg",
86 DEMO_IMAGE_DIR "gallery-medium-47.jpg",
87 DEMO_IMAGE_DIR "gallery-medium-48.jpg",
88 DEMO_IMAGE_DIR "gallery-medium-49.jpg",
89 DEMO_IMAGE_DIR "gallery-medium-50.jpg",
90 DEMO_IMAGE_DIR "gallery-medium-51.jpg",
91 DEMO_IMAGE_DIR "gallery-medium-52.jpg",
92 DEMO_IMAGE_DIR "gallery-medium-53.jpg",
95 const unsigned int NUM_IMAGES = sizeof(IMAGE_PATHS) / sizeof(char*);
97 const char* BACKGROUND_IMAGE( "" );
98 const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
99 const char* EDIT_IMAGE( DEMO_IMAGE_DIR "icon-edit.png" );
100 const char* EDIT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-edit-selected.png" );
101 const char* SPIRAL_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-spiral.png" );
102 const char* SPIRAL_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-spiral-selected.png" );
103 const char* GRID_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-grid.png" );
104 const char* GRID_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-grid-selected.png" );
105 const char* DEPTH_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-depth.png" );
106 const char* DEPTH_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-depth-selected.png" );
107 const char* DELETE_IMAGE( DEMO_IMAGE_DIR "icon-delete.png" );
108 const char* DELETE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-delete-selected.png" );
109 const char* REPLACE_IMAGE( DEMO_IMAGE_DIR "icon-replace.png" );
110 const char* REPLACE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" );
111 const char* INSERT_IMAGE( DEMO_IMAGE_DIR "icon-insert.png" );
112 const char* INSERT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-insert-selected.png" );
113 const char* SELECTED_IMAGE( DEMO_IMAGE_DIR "item-select-check.png" );
114 const char* APPLICATION_TITLE( "ItemView" );
116 const char* SPIRAL_LABEL("Spiral");
117 const char* GRID_LABEL("Grid");
118 const char* DEPTH_LABEL("Depth");
120 const float ITEM_BORDER_SIZE = 2.0f;
122 const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT = 1.0f;
123 const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE = 0.8f;
124 const float DEPTH_LAYOUT_COLUMNS = 3.0f;
126 const float MIN_SWIPE_DISTANCE = 15.0f;
127 const float MIN_SWIPE_SPEED = 5.0f;
129 const float SELECTION_BORDER_WIDTH = 3.0f;
130 const float BUTTON_BORDER = -10.0f;
131 const float MENU_OPTION_HEIGHT(140.0f);
132 const float LABEL_TEXT_SIZE_Y = 20.0f;
134 const Vector3 INITIAL_OFFSCREEN_POSITION( 1000.0f, 0, -1000.0f );
136 const float SCROLL_TO_ITEM_ANIMATION_TIME = 5.f;
138 static Vector3 DepthLayoutItemSizeFunctionPortrait( float layoutWidth )
140 float width = ( layoutWidth / ( DEPTH_LAYOUT_COLUMNS + 1.0f ) ) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT;
143 return Vector3(width, width, width);
146 static Vector3 DepthLayoutItemSizeFunctionLandscape( float layoutWidth )
148 float width = ( layoutWidth / ( DEPTH_LAYOUT_COLUMNS + 1.0f ) ) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE;
151 return Vector3(width, width, width);
154 } // unnamed namespace
157 * This example shows how to use ItemView UI control.
158 * There are three layouts created for ItemView, i.e., Spiral, Depth and Grid.
159 * There is one button in the upper-left corner for quitting the application and
160 * another button in the upper-right corner for switching between different layouts.
162 class ItemViewExample : public ConnectionTracker, public ItemFactory
180 * @param application class, stored as reference
182 ItemViewExample( Application& application )
183 : mApplication( application ),
184 mMode( MODE_NORMAL ),
186 mCurrentLayout( SPIRAL_LAYOUT ),
187 mDurationSeconds( 0.25f )
189 // Connect to the Application's Init signal
190 mApplication.InitSignal().Connect(this, &ItemViewExample::OnInit);
194 * This method gets called once the main loop of application is up and running
196 void OnInit(Application& app)
198 Stage stage = Dali::Stage::GetCurrent();
199 stage.KeyEventSignal().Connect(this, &ItemViewExample::OnKeyEvent);
200 stage.GetRootLayer().SetBehavior(Layer::LAYER_3D);
202 Vector2 stageSize = Stage::GetCurrent().GetSize();
204 // Creates a default view with a default tool bar.
205 // The view is added to the stage.
207 Layer contents = DemoHelper::CreateView( mApplication,
214 // Create an edit mode button. (left of toolbar)
215 Toolkit::PushButton editButton = Toolkit::PushButton::New();
216 editButton.SetUnselectedImage( EDIT_IMAGE );
217 editButton.SetSelectedImage( EDIT_IMAGE_SELECTED );
218 editButton.ClickedSignal().Connect( this, &ItemViewExample::OnModeButtonClicked);
219 editButton.SetLeaveRequired( true );
220 mToolBar.AddControl( editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
222 // Create a layout toggle button. (right of toolbar)
223 mLayoutButton = Toolkit::PushButton::New();
224 mLayoutButton.SetUnselectedImage( SPIRAL_LAYOUT_IMAGE );
225 mLayoutButton.SetSelectedImage(SPIRAL_LAYOUT_IMAGE_SELECTED );
226 mLayoutButton.ClickedSignal().Connect( this, &ItemViewExample::OnLayoutButtonClicked);
227 mLayoutButton.SetLeaveRequired( true );
228 mToolBar.AddControl( mLayoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
230 // Create a delete button (bottom right of screen)
231 mDeleteButton = Toolkit::PushButton::New();
232 mDeleteButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
233 mDeleteButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
234 mDeleteButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
235 mDeleteButton.SetDrawMode( DrawMode::OVERLAY_2D );
236 mDeleteButton.SetUnselectedImage( DELETE_IMAGE );
237 mDeleteButton.SetSelectedImage( DELETE_IMAGE_SELECTED );
238 mDeleteButton.SetBackgroundImage( TOOLBAR_IMAGE );
239 mDeleteButton.SetSize( Vector2( stageSize.width * 0.15f, stageSize.width * 0.15f ) );
240 mDeleteButton.ClickedSignal().Connect( this, &ItemViewExample::OnDeleteButtonClicked);
241 mDeleteButton.SetLeaveRequired( true );
242 mDeleteButton.SetVisible( false );
243 stage.Add( mDeleteButton );
245 // Create an insert button (bottom right of screen)
246 mInsertButton = Toolkit::PushButton::New();
247 mInsertButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
248 mInsertButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
249 mInsertButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
250 mInsertButton.SetDrawMode( DrawMode::OVERLAY_2D );
251 mInsertButton.SetUnselectedImage( INSERT_IMAGE );
252 mInsertButton.SetSelectedImage( INSERT_IMAGE_SELECTED );
253 mInsertButton.SetBackgroundImage( TOOLBAR_IMAGE );
254 mInsertButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
255 mInsertButton.ClickedSignal().Connect( this, &ItemViewExample::OnInsertButtonClicked);
256 mInsertButton.SetLeaveRequired( true );
257 mInsertButton.SetVisible( false );
258 stage.Add( mInsertButton );
260 // Create an replace button (bottom right of screen)
261 mReplaceButton = Toolkit::PushButton::New();
262 mReplaceButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
263 mReplaceButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
264 mReplaceButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
265 mReplaceButton.SetDrawMode( DrawMode::OVERLAY_2D );
266 mReplaceButton.SetUnselectedImage( REPLACE_IMAGE );
267 mReplaceButton.SetSelectedImage( REPLACE_IMAGE_SELECTED );
268 mReplaceButton.SetBackgroundImage( TOOLBAR_IMAGE );
269 mReplaceButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
270 mReplaceButton.ClickedSignal().Connect( this, &ItemViewExample::OnReplaceButtonClicked);
271 mReplaceButton.SetLeaveRequired( true );
272 mReplaceButton.SetVisible( false );
273 stage.Add( mReplaceButton );
275 // Create the item view actor
276 mItemView = ItemView::New(*this);
277 mItemView.SetParentOrigin(ParentOrigin::CENTER);
278 mItemView.SetAnchorPoint(AnchorPoint::CENTER);
280 // Display item view on the stage
281 stage.Add( mItemView );
282 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
284 // Create the layouts
285 mSpiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
286 mDepthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
287 mGridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
289 // Add the layouts to item view
290 mItemView.AddLayout(*mSpiralLayout);
291 mItemView.AddLayout(*mDepthLayout);
292 mItemView.AddLayout(*mGridLayout);
294 mItemView.SetMinimumSwipeDistance(MIN_SWIPE_DISTANCE);
295 mItemView.SetMinimumSwipeSpeed(MIN_SWIPE_SPEED);
297 // Activate the spiral layout
298 SetLayout( mCurrentLayout );
299 mItemView.SetKeyboardFocusable( true );
300 KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &ItemViewExample::OnKeyboardPreFocusChange );
302 // Set the title and icon to the current layout
306 mLongPressDetector = LongPressGestureDetector::New();
307 mLongPressDetector.Attach( mItemView );
308 mLongPressDetector.DetectedSignal().Connect( this, &ItemViewExample::OnLongPress );
311 Actor OnKeyboardPreFocusChange( Actor current, Actor proposed, Control::KeyboardFocus::Direction direction )
313 if ( !current && !proposed )
322 * Animate to a different layout
326 Animation animation = Animation::New( mDurationSeconds );
327 animation.FinishedSignal().Connect( this, &ItemViewExample::AnimationFinished );
328 animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 0.0f );
332 void AnimationFinished( Animation& )
334 SetLayout( mCurrentLayout );
336 Animation animation = Animation::New( mDurationSeconds );
337 animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 1.0f );
342 * Switch to a different item view layout
344 void SetLayout( int layoutId )
346 Stage stage = Dali::Stage::GetCurrent();
347 switch( mCurrentLayout )
352 stage.GetRootLayer().SetBehavior(Layer::LAYER_3D);
357 stage.GetRootLayer().SetBehavior(Layer::LAYER_2D);
362 // Set the new orientation to the layout
363 mItemView.GetLayout(layoutId)->SetOrientation(static_cast<ControlOrientation::Type>(mOrientation / 90));
365 Vector2 stageSize = Stage::GetCurrent().GetSize();
367 if(layoutId == DEPTH_LAYOUT)
369 // Set up the depth layout according to the new orientation
370 if(Toolkit::IsVertical(mDepthLayout->GetOrientation()))
372 mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionPortrait( stageSize.width ) );
376 mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionLandscape( stageSize.height ) );
380 // Enable anchoring for depth layout only
381 mItemView.SetAnchoring(layoutId == DEPTH_LAYOUT);
383 // Activate the layout
384 mItemView.ActivateLayout( layoutId, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
387 bool OnLayoutButtonClicked( Toolkit::Button button )
389 // Switch to the next layout
390 mCurrentLayout = (mCurrentLayout + 1) % mItemView.GetLayoutCount();
400 bool OnModeButtonClicked( Toolkit::Button button )
407 void SwitchToNextMode()
414 mMode = MODE_REMOVE_MANY;
415 EnterRemoveManyMode();
419 case MODE_REMOVE_MANY:
421 ExitRemoveManyMode();
430 mMode = MODE_INSERT_MANY;
431 EnterInsertManyMode();
435 case MODE_INSERT_MANY:
437 ExitInsertManyMode();
438 mMode = MODE_REPLACE;
446 mMode = MODE_REPLACE_MANY;
447 EnterReplaceManyMode();
451 case MODE_REPLACE_MANY:
453 ExitReplaceManyMode();
469 void EnterRemoveMode()
471 SetTitle("Edit: Remove");
473 mTapDetector = TapGestureDetector::New();
475 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
477 mTapDetector.Attach(mItemView.GetChildAt(i));
480 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::RemoveOnTap );
483 void ExitRemoveMode()
485 mTapDetector.Reset();
488 void RemoveOnTap( Actor actor, const TapGesture& tap )
490 mItemView.RemoveItem( mItemView.GetItemId(actor), 0.5f );
493 void EnterRemoveManyMode()
495 SetTitle("Edit: Remove Many");
497 mDeleteButton.SetVisible( true );
499 mTapDetector = TapGestureDetector::New();
501 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
503 Actor child = mItemView.GetChildAt( i );
504 Actor box = child.FindChildByName( "CheckBox" );
508 mTapDetector.Attach( child );
509 box.SetVisible( true );
513 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
516 void ExitRemoveManyMode()
518 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
520 Actor child = mItemView.GetChildAt( i );
521 Actor box = child.FindChildByName( "CheckBox" );
525 box.SetVisible( false );
527 Actor tick = box.FindChildByName( "Tick" );
530 tick.SetVisible( false );
535 mTapDetector.Reset();
537 mDeleteButton.SetVisible( false );
540 void SelectOnTap( Actor actor, const TapGesture& tap )
542 Actor tick = actor.FindChildByName( "Tick" );
545 tick.SetVisible( !tick.IsVisible() );
549 void OnLongPress( Actor actor, const LongPressGesture& gesture )
551 switch( gesture.state )
553 case Gesture::Started:
555 const Size& size = Stage::GetCurrent().GetSize();
557 ItemRange range( 0u, 0u );
558 mItemView.GetItemsRange( range );
560 const unsigned int item = ( gesture.screenPoint.y < 0.5f * size.height ) ? range.begin : range.end;
561 mItemView.ScrollToItem( item, SCROLL_TO_ITEM_ANIMATION_TIME );
565 case Gesture::Finished:
567 Property::Map attributes;
568 mItemView.DoAction( "stopScrolling", attributes );
578 bool OnDeleteButtonClicked( Toolkit::Button button )
580 ItemIdContainer removeList;
582 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
584 Actor child = mItemView.GetChildAt( i );
585 Actor tick = child.FindChildByName( "Tick" );
587 if( tick && tick.IsVisible() )
589 removeList.push_back( mItemView.GetItemId(child) );
593 if( ! removeList.empty() )
595 mItemView.RemoveItems( removeList, 0.5f );
601 void EnterInsertMode()
603 SetTitle("Edit: Insert");
605 mTapDetector = TapGestureDetector::New();
607 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
609 mTapDetector.Attach( mItemView.GetChildAt(i) );
612 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::InsertOnTap );
615 void ExitInsertMode()
617 mTapDetector.Reset();
620 void InsertOnTap( Actor actor, const TapGesture& tap )
622 ItemId id = mItemView.GetItemId( actor );
624 Actor newActor = NewItem( rand() );
626 mItemView.InsertItem( Item(id,newActor), 0.5f );
629 void EnterInsertManyMode()
631 SetTitle("Edit: Insert Many");
633 mInsertButton.SetVisible( true );
635 mTapDetector = TapGestureDetector::New();
637 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
639 Actor child = mItemView.GetChildAt( i );
640 Actor box = child.FindChildByName( "CheckBox" );
644 mTapDetector.Attach( child );
645 box.SetVisible( true );
649 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
652 void ExitInsertManyMode()
654 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
656 Actor child = mItemView.GetChildAt( i );
657 Actor box = child.FindChildByName( "CheckBox" );
661 box.SetVisible( false );
663 Actor tick = box.FindChildByName( "Tick" );
666 tick.SetVisible( false );
671 mTapDetector.Reset();
673 mInsertButton.SetVisible( false );
676 bool OnInsertButtonClicked( Toolkit::Button button )
678 ItemContainer insertList;
680 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
682 Actor child = mItemView.GetChildAt( i );
683 Actor tick = child.FindChildByName( "Tick" );
685 if( tick && tick.IsVisible() )
687 insertList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) );
691 if( ! insertList.empty() )
693 mItemView.InsertItems( insertList, 0.5f );
699 void EnterReplaceMode()
701 SetTitle("Edit: Replace");
703 mTapDetector = TapGestureDetector::New();
705 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
707 mTapDetector.Attach(mItemView.GetChildAt(i));
710 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::ReplaceOnTap );
713 void ReplaceOnTap( Actor actor, const TapGesture& tap )
715 mItemView.ReplaceItem( Item( mItemView.GetItemId(actor), NewItem(rand()) ), 0.5f );
718 void ExitReplaceMode()
720 mTapDetector.Reset();
723 void EnterReplaceManyMode()
725 SetTitle("Edit: Replace Many");
727 mReplaceButton.SetVisible( true );
729 mTapDetector = TapGestureDetector::New();
731 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
733 Actor child = mItemView.GetChildAt( i );
734 Actor box = child.FindChildByName( "CheckBox" );
738 mTapDetector.Attach( child );
739 box.SetVisible( true );
743 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
746 void ExitReplaceManyMode()
748 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
750 Actor child = mItemView.GetChildAt( i );
751 Actor box = child.FindChildByName( "CheckBox" );
755 box.SetVisible( false );
757 Actor tick = box.FindChildByName( "Tick" );
760 tick.SetVisible( false );
765 mTapDetector.Reset();
767 mReplaceButton.SetVisible( false );
770 bool OnReplaceButtonClicked( Toolkit::Button button )
772 ItemContainer replaceList;
774 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
776 Actor child = mItemView.GetChildAt( i );
777 Actor tick = child.FindChildByName( "Tick" );
779 if( tick && tick.IsVisible() )
781 replaceList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) );
785 if( ! replaceList.empty() )
787 mItemView.ReplaceItems( replaceList, 0.5f );
793 void SetLayoutTitle()
795 if( MODE_NORMAL == mMode )
797 std::stringstream ss(APPLICATION_TITLE);
798 switch(mCurrentLayout)
801 ss << APPLICATION_TITLE << ": " << SPIRAL_LABEL;
804 ss << APPLICATION_TITLE << ": " << GRID_LABEL;
807 ss << APPLICATION_TITLE << ": " << DEPTH_LABEL;
816 void SetLayoutImage()
820 switch( mCurrentLayout )
824 mLayoutButton.SetUnselectedImage( SPIRAL_LAYOUT_IMAGE );
825 mLayoutButton.SetSelectedImage( SPIRAL_LAYOUT_IMAGE_SELECTED );
831 mLayoutButton.SetUnselectedImage( GRID_LAYOUT_IMAGE );
832 mLayoutButton.SetSelectedImage( GRID_LAYOUT_IMAGE_SELECTED );
838 mLayoutButton.SetUnselectedImage( DEPTH_LAYOUT_IMAGE );
839 mLayoutButton.SetSelectedImage( DEPTH_LAYOUT_IMAGE_SELECTED );
849 public: // From ItemFactory
852 * Query the number of items available from the factory.
853 * The maximum available item has an ID of GetNumberOfItems() - 1.
855 virtual unsigned int GetNumberOfItems()
857 return NUM_IMAGES * 10;
861 * Create an Actor to represent a visible item.
863 * @return the created actor.
865 virtual Actor NewItem(unsigned int itemId)
867 // Create an image view for this item
868 ImageView actor = ImageView::New( IMAGE_PATHS[ itemId % NUM_IMAGES ] );
870 actor.SetPosition( INITIAL_OFFSCREEN_POSITION );
872 // Add a border image child actor
873 ImageView borderActor = ImageView::New();
874 borderActor.SetParentOrigin( ParentOrigin::CENTER );
875 borderActor.SetAnchorPoint( AnchorPoint::CENTER );
876 borderActor.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
877 borderActor.SetSizeModeFactor( Vector3( 2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f ) );
878 borderActor.SetColorMode( USE_PARENT_COLOR );
880 Property::Map borderProperty;
881 borderProperty.Insert( "rendererType", "border" );
882 borderProperty.Insert( "borderColor", Color::WHITE );
883 borderProperty.Insert( "borderSize", ITEM_BORDER_SIZE );
884 borderProperty.Insert( "antiAliasing", true );
885 borderActor.SetProperty( ImageView::Property::IMAGE, borderProperty );
887 actor.Add(borderActor);
889 actor.SetKeyboardFocusable( true );
891 Vector3 spiralItemSize;
892 static_cast<ItemLayout&>(*mSpiralLayout).GetItemSize( 0u, Vector3( Stage::GetCurrent().GetSize() ), spiralItemSize );
894 // Add a checkbox child actor; invisible until edit-mode is enabled
895 ImageView checkbox = ImageView::New();
896 checkbox.SetName( "CheckBox" );
897 checkbox.SetColorMode( USE_PARENT_COLOR );
898 checkbox.SetParentOrigin( ParentOrigin::TOP_RIGHT );
899 checkbox.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
900 checkbox.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
901 checkbox.SetPosition( -SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH );
902 checkbox.SetZ( 0.1f );
904 Property::Map solidColorProperty;
905 solidColorProperty.Insert( "rendererType", "color" );
906 solidColorProperty.Insert( "mixColor", Vector4(0.f, 0.f, 0.f, 0.6f) );
907 checkbox.SetProperty( ImageView::Property::IMAGE, solidColorProperty );
909 if( MODE_REMOVE_MANY != mMode &&
910 MODE_INSERT_MANY != mMode &&
911 MODE_REPLACE_MANY != mMode )
913 checkbox.SetVisible( false );
915 borderActor.Add( checkbox );
917 ImageView tick = ImageView::New( SELECTED_IMAGE );
918 tick.SetName( "Tick" );
919 tick.SetColorMode( USE_PARENT_COLOR );
920 tick.SetParentOrigin( ParentOrigin::TOP_RIGHT );
921 tick.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
922 tick.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
924 tick.SetVisible( false );
925 checkbox.Add( tick );
927 // Connect new items for various editing modes
930 mTapDetector.Attach( actor );
939 * Sets/Updates the title of the View
940 * @param[in] title The new title for the view.
942 void SetTitle(const std::string& title)
946 mTitleActor = DemoHelper::CreateToolBarLabel( "" );
947 // Add title to the tool bar.
948 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
951 mTitleActor.SetProperty( TextLabel::Property::TEXT, title );
955 * Main key event handler
957 void OnKeyEvent(const KeyEvent& event)
959 if(event.state == KeyEvent::Down)
961 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
970 Application& mApplication;
973 Toolkit::Control mView;
974 unsigned int mOrientation;
976 Toolkit::ToolBar mToolBar;
977 TextLabel mTitleActor; ///< The Toolbar's Title.
980 unsigned int mCurrentLayout;
981 float mDurationSeconds;
983 ItemLayoutPtr mSpiralLayout;
984 ItemLayoutPtr mDepthLayout;
985 ItemLayoutPtr mGridLayout;
987 TapGestureDetector mTapDetector;
988 Toolkit::PushButton mLayoutButton;
989 Toolkit::PushButton mDeleteButton;
990 Toolkit::PushButton mInsertButton;
991 Toolkit::PushButton mReplaceButton;
993 LongPressGestureDetector mLongPressDetector;
996 void RunTest(Application& app)
998 ItemViewExample test(app);
1003 int DALI_EXPORT_API main(int argc, char **argv)
1005 Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);