2 * Copyright (c) 2018 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>
23 #include <dali-toolkit/devel-api/controls/buttons/button-devel.h>
24 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
27 using namespace Dali::Toolkit;
41 const char* IMAGE_PATHS[] = {
42 DEMO_IMAGE_DIR "gallery-medium-1.jpg",
43 DEMO_IMAGE_DIR "gallery-medium-2.jpg",
44 DEMO_IMAGE_DIR "gallery-medium-3.jpg",
45 DEMO_IMAGE_DIR "gallery-medium-4.jpg",
46 DEMO_IMAGE_DIR "gallery-medium-5.jpg",
47 DEMO_IMAGE_DIR "gallery-medium-6.jpg",
48 DEMO_IMAGE_DIR "gallery-medium-7.jpg",
49 DEMO_IMAGE_DIR "gallery-medium-8.jpg",
50 DEMO_IMAGE_DIR "gallery-medium-9.jpg",
51 DEMO_IMAGE_DIR "gallery-medium-10.jpg",
52 DEMO_IMAGE_DIR "gallery-medium-11.jpg",
53 DEMO_IMAGE_DIR "gallery-medium-12.jpg",
54 DEMO_IMAGE_DIR "gallery-medium-13.jpg",
55 DEMO_IMAGE_DIR "gallery-medium-14.jpg",
56 DEMO_IMAGE_DIR "gallery-medium-15.jpg",
57 DEMO_IMAGE_DIR "gallery-medium-16.jpg",
58 DEMO_IMAGE_DIR "gallery-medium-17.jpg",
59 DEMO_IMAGE_DIR "gallery-medium-18.jpg",
60 DEMO_IMAGE_DIR "gallery-medium-19.jpg",
61 DEMO_IMAGE_DIR "gallery-medium-20.jpg",
62 DEMO_IMAGE_DIR "gallery-medium-21.jpg",
63 DEMO_IMAGE_DIR "gallery-medium-22.jpg",
64 DEMO_IMAGE_DIR "gallery-medium-23.jpg",
65 DEMO_IMAGE_DIR "gallery-medium-24.jpg",
66 DEMO_IMAGE_DIR "gallery-medium-25.jpg",
67 DEMO_IMAGE_DIR "gallery-medium-26.jpg",
68 DEMO_IMAGE_DIR "gallery-medium-27.jpg",
69 DEMO_IMAGE_DIR "gallery-medium-28.jpg",
70 DEMO_IMAGE_DIR "gallery-medium-29.jpg",
71 DEMO_IMAGE_DIR "gallery-medium-30.jpg",
72 DEMO_IMAGE_DIR "gallery-medium-31.jpg",
73 DEMO_IMAGE_DIR "gallery-medium-32.jpg",
74 DEMO_IMAGE_DIR "gallery-medium-33.jpg",
75 DEMO_IMAGE_DIR "gallery-medium-34.jpg",
76 DEMO_IMAGE_DIR "gallery-medium-35.jpg",
77 DEMO_IMAGE_DIR "gallery-medium-36.jpg",
78 DEMO_IMAGE_DIR "gallery-medium-37.jpg",
79 DEMO_IMAGE_DIR "gallery-medium-38.jpg",
80 DEMO_IMAGE_DIR "gallery-medium-39.jpg",
81 DEMO_IMAGE_DIR "gallery-medium-40.jpg",
82 DEMO_IMAGE_DIR "gallery-medium-41.jpg",
83 DEMO_IMAGE_DIR "gallery-medium-42.jpg",
84 DEMO_IMAGE_DIR "gallery-medium-43.jpg",
85 DEMO_IMAGE_DIR "gallery-medium-44.jpg",
86 DEMO_IMAGE_DIR "gallery-medium-45.jpg",
87 DEMO_IMAGE_DIR "gallery-medium-46.jpg",
88 DEMO_IMAGE_DIR "gallery-medium-47.jpg",
89 DEMO_IMAGE_DIR "gallery-medium-48.jpg",
90 DEMO_IMAGE_DIR "gallery-medium-49.jpg",
91 DEMO_IMAGE_DIR "gallery-medium-50.jpg",
92 DEMO_IMAGE_DIR "gallery-medium-51.jpg",
93 DEMO_IMAGE_DIR "gallery-medium-52.jpg",
94 DEMO_IMAGE_DIR "gallery-medium-53.jpg",
97 const unsigned int NUM_IMAGES = sizeof(IMAGE_PATHS) / sizeof(char*);
99 const char* BACKGROUND_IMAGE( "" );
100 const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
101 const char* EDIT_IMAGE( DEMO_IMAGE_DIR "icon-edit.png" );
102 const char* EDIT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-edit-selected.png" );
103 const char* SPIRAL_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-spiral.png" );
104 const char* SPIRAL_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-spiral-selected.png" );
105 const char* GRID_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-grid.png" );
106 const char* GRID_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-grid-selected.png" );
107 const char* DEPTH_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-depth.png" );
108 const char* DEPTH_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-depth-selected.png" );
109 const char* DELETE_IMAGE( DEMO_IMAGE_DIR "icon-delete.png" );
110 const char* DELETE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-delete-selected.png" );
111 const char* REPLACE_IMAGE( DEMO_IMAGE_DIR "icon-replace.png" );
112 const char* REPLACE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" );
113 const char* INSERT_IMAGE( DEMO_IMAGE_DIR "icon-insert.png" );
114 const char* INSERT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-insert-selected.png" );
115 const char* SELECTED_IMAGE( DEMO_IMAGE_DIR "item-select-check.png" );
116 const char* APPLICATION_TITLE( "ItemView" );
118 const char* SPIRAL_LABEL("Spiral");
119 const char* GRID_LABEL("Grid");
120 const char* DEPTH_LABEL("Depth");
122 const float ITEM_BORDER_SIZE = 2.0f;
124 const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT = 1.0f;
125 const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE = 0.8f;
126 const float DEPTH_LAYOUT_COLUMNS = 3.0f;
128 const float MIN_SWIPE_DISTANCE = 15.0f;
129 const float MIN_SWIPE_SPEED = 5.0f;
131 const float SELECTION_BORDER_WIDTH = 3.0f;
132 const float BUTTON_BORDER = -10.0f;
133 const float MENU_OPTION_HEIGHT(140.0f);
134 const float LABEL_TEXT_SIZE_Y = 20.0f;
136 const Vector3 INITIAL_OFFSCREEN_POSITION( 1000.0f, 0, -1000.0f );
138 const float SCROLL_TO_ITEM_ANIMATION_TIME = 5.f;
140 static Vector3 DepthLayoutItemSizeFunctionPortrait( float layoutWidth )
142 float width = ( layoutWidth / ( DEPTH_LAYOUT_COLUMNS + 1.0f ) ) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT;
145 return Vector3(width, width, width);
148 static Vector3 DepthLayoutItemSizeFunctionLandscape( float layoutWidth )
150 float width = ( layoutWidth / ( DEPTH_LAYOUT_COLUMNS + 1.0f ) ) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE;
153 return Vector3(width, width, width);
156 } // unnamed namespace
159 * This example shows how to use ItemView UI control.
160 * There are three layouts created for ItemView, i.e., Spiral, Depth and Grid.
161 * There is one button in the upper-left corner for quitting the application and
162 * another button in the upper-right corner for switching between different layouts.
164 class ItemViewExample : public ConnectionTracker, public ItemFactory
182 * @param application class, stored as reference
184 ItemViewExample( Application& application )
185 : mApplication( application ),
186 mMode( MODE_NORMAL ),
188 mCurrentLayout( SPIRAL_LAYOUT ),
189 mDurationSeconds( 0.25f )
191 // Connect to the Application's Init signal
192 mApplication.InitSignal().Connect(this, &ItemViewExample::OnInit);
196 * This method gets called once the main loop of application is up and running
198 void OnInit(Application& app)
200 Stage stage = Dali::Stage::GetCurrent();
201 stage.KeyEventSignal().Connect(this, &ItemViewExample::OnKeyEvent);
202 stage.GetRootLayer().SetBehavior(Layer::LAYER_3D);
204 Vector2 stageSize = Stage::GetCurrent().GetSize();
206 // Creates a default view with a default tool bar.
207 // The view is added to the stage.
209 Layer contents = DemoHelper::CreateView( mApplication,
216 // Create an edit mode button. (left of toolbar)
217 Toolkit::PushButton editButton = Toolkit::PushButton::New();
218 editButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, EDIT_IMAGE );
219 editButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, EDIT_IMAGE_SELECTED );
220 editButton.ClickedSignal().Connect( this, &ItemViewExample::OnModeButtonClicked);
221 editButton.SetLeaveRequired( true );
222 mToolBar.AddControl( editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
224 // Create a layout toggle button. (right of toolbar)
225 mLayoutButton = Toolkit::PushButton::New();
226 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE );
227 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE_SELECTED );
228 mLayoutButton.ClickedSignal().Connect( this, &ItemViewExample::OnLayoutButtonClicked);
229 mLayoutButton.SetLeaveRequired( true );
230 mToolBar.AddControl( mLayoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
232 // Create a delete button (bottom right of screen)
233 mDeleteButton = Toolkit::PushButton::New();
234 mDeleteButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
235 mDeleteButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
236 mDeleteButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
237 mDeleteButton.SetDrawMode( DrawMode::OVERLAY_2D );
238 mDeleteButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, DELETE_IMAGE );
239 mDeleteButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, DELETE_IMAGE_SELECTED );
240 mDeleteButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE );
241 mDeleteButton.SetSize( Vector2( stageSize.width * 0.15f, stageSize.width * 0.15f ) );
242 mDeleteButton.ClickedSignal().Connect( this, &ItemViewExample::OnDeleteButtonClicked);
243 mDeleteButton.SetLeaveRequired( true );
244 mDeleteButton.SetVisible( false );
245 stage.Add( mDeleteButton );
247 // Create an insert button (bottom right of screen)
248 mInsertButton = Toolkit::PushButton::New();
249 mInsertButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
250 mInsertButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
251 mInsertButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
252 mInsertButton.SetDrawMode( DrawMode::OVERLAY_2D );
253 mInsertButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, INSERT_IMAGE );
254 mInsertButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, INSERT_IMAGE_SELECTED );
255 mInsertButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE );
256 mInsertButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
257 mInsertButton.ClickedSignal().Connect( this, &ItemViewExample::OnInsertButtonClicked);
258 mInsertButton.SetLeaveRequired( true );
259 mInsertButton.SetVisible( false );
260 stage.Add( mInsertButton );
262 // Create an replace button (bottom right of screen)
263 mReplaceButton = Toolkit::PushButton::New();
264 mReplaceButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
265 mReplaceButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
266 mReplaceButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
267 mReplaceButton.SetDrawMode( DrawMode::OVERLAY_2D );
268 mReplaceButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, REPLACE_IMAGE );
269 mReplaceButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, REPLACE_IMAGE_SELECTED );
270 mReplaceButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE );
271 mReplaceButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
272 mReplaceButton.ClickedSignal().Connect( this, &ItemViewExample::OnReplaceButtonClicked);
273 mReplaceButton.SetLeaveRequired( true );
274 mReplaceButton.SetVisible( false );
275 stage.Add( mReplaceButton );
277 // Create the item view actor
278 mItemView = ItemView::New(*this);
279 mItemView.SetParentOrigin(ParentOrigin::CENTER);
280 mItemView.SetAnchorPoint(AnchorPoint::CENTER);
282 // Display item view on the stage
283 stage.Add( mItemView );
284 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
286 // Create the layouts
287 mSpiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
288 mDepthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
289 mGridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
291 // Add the layouts to item view
292 mItemView.AddLayout(*mSpiralLayout);
293 mItemView.AddLayout(*mDepthLayout);
294 mItemView.AddLayout(*mGridLayout);
296 mItemView.SetMinimumSwipeDistance(MIN_SWIPE_DISTANCE);
297 mItemView.SetMinimumSwipeSpeed(MIN_SWIPE_SPEED);
299 // Activate the spiral layout
300 SetLayout( mCurrentLayout );
301 mItemView.SetKeyboardFocusable( true );
302 KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &ItemViewExample::OnKeyboardPreFocusChange );
304 // Set the title and icon to the current layout
308 mLongPressDetector = LongPressGestureDetector::New();
309 mLongPressDetector.Attach( mItemView );
310 mLongPressDetector.DetectedSignal().Connect( this, &ItemViewExample::OnLongPress );
313 Actor OnKeyboardPreFocusChange( Actor current, Actor proposed, Control::KeyboardFocus::Direction direction )
315 if ( !current && !proposed )
324 * Animate to a different layout
328 Animation animation = Animation::New( mDurationSeconds );
329 animation.FinishedSignal().Connect( this, &ItemViewExample::AnimationFinished );
330 animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 0.0f );
334 void AnimationFinished( Animation& )
336 SetLayout( mCurrentLayout );
338 Animation animation = Animation::New( mDurationSeconds );
339 animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 1.0f );
344 * Switch to a different item view layout
346 void SetLayout( int layoutId )
348 Stage stage = Dali::Stage::GetCurrent();
349 switch( mCurrentLayout )
354 stage.GetRootLayer().SetBehavior(Layer::LAYER_3D);
359 stage.GetRootLayer().SetBehavior(Layer::LAYER_UI);
364 // Set the new orientation to the layout
365 mItemView.GetLayout(layoutId)->SetOrientation(static_cast<ControlOrientation::Type>(mOrientation / 90));
367 Vector2 stageSize = Stage::GetCurrent().GetSize();
369 if(layoutId == DEPTH_LAYOUT)
371 // Set up the depth layout according to the new orientation
372 if(Toolkit::IsVertical(mDepthLayout->GetOrientation()))
374 mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionPortrait( stageSize.width ) );
378 mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionLandscape( stageSize.height ) );
382 // Enable anchoring for depth layout only
383 mItemView.SetAnchoring(layoutId == DEPTH_LAYOUT);
385 // Activate the layout
386 mItemView.ActivateLayout( layoutId, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
389 bool OnLayoutButtonClicked( Toolkit::Button button )
391 // Switch to the next layout
392 mCurrentLayout = (mCurrentLayout + 1) % mItemView.GetLayoutCount();
402 bool OnModeButtonClicked( Toolkit::Button button )
409 void SwitchToNextMode()
416 mMode = MODE_REMOVE_MANY;
417 EnterRemoveManyMode();
421 case MODE_REMOVE_MANY:
423 ExitRemoveManyMode();
432 mMode = MODE_INSERT_MANY;
433 EnterInsertManyMode();
437 case MODE_INSERT_MANY:
439 ExitInsertManyMode();
440 mMode = MODE_REPLACE;
448 mMode = MODE_REPLACE_MANY;
449 EnterReplaceManyMode();
453 case MODE_REPLACE_MANY:
455 ExitReplaceManyMode();
471 void EnterRemoveMode()
473 SetTitle("Edit: Remove");
475 mTapDetector = TapGestureDetector::New();
477 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
479 mTapDetector.Attach(mItemView.GetChildAt(i));
482 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::RemoveOnTap );
485 void ExitRemoveMode()
487 mTapDetector.Reset();
490 void RemoveOnTap( Actor actor, const TapGesture& tap )
492 mItemView.RemoveItem( mItemView.GetItemId(actor), 0.5f );
495 void EnterRemoveManyMode()
497 SetTitle("Edit: Remove Many");
499 mDeleteButton.SetVisible( true );
501 mTapDetector = TapGestureDetector::New();
503 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
505 Actor child = mItemView.GetChildAt( i );
506 Actor box = child.FindChildByName( "CheckBox" );
510 mTapDetector.Attach( child );
511 box.SetVisible( true );
515 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
518 void ExitRemoveManyMode()
520 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
522 Actor child = mItemView.GetChildAt( i );
523 Actor box = child.FindChildByName( "CheckBox" );
527 box.SetVisible( false );
529 Actor tick = box.FindChildByName( "Tick" );
532 tick.SetVisible( false );
537 mTapDetector.Reset();
539 mDeleteButton.SetVisible( false );
542 void SelectOnTap( Actor actor, const TapGesture& tap )
544 Actor tick = actor.FindChildByName( "Tick" );
547 tick.SetVisible( !tick.IsVisible() );
551 void OnLongPress( Actor actor, const LongPressGesture& gesture )
553 switch( gesture.state )
555 case Gesture::Started:
557 const Size& size = Stage::GetCurrent().GetSize();
559 ItemRange range( 0u, 0u );
560 mItemView.GetItemsRange( range );
562 const unsigned int item = ( gesture.screenPoint.y < 0.5f * size.height ) ? range.begin : range.end;
563 mItemView.ScrollToItem( item, SCROLL_TO_ITEM_ANIMATION_TIME );
567 case Gesture::Finished:
569 Property::Map attributes;
570 mItemView.DoAction( "stopScrolling", attributes );
580 bool OnDeleteButtonClicked( Toolkit::Button button )
582 ItemIdContainer removeList;
584 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
586 Actor child = mItemView.GetChildAt( i );
587 Actor tick = child.FindChildByName( "Tick" );
589 if( tick && tick.IsVisible() )
591 removeList.push_back( mItemView.GetItemId(child) );
595 if( ! removeList.empty() )
597 mItemView.RemoveItems( removeList, 0.5f );
603 void EnterInsertMode()
605 SetTitle("Edit: Insert");
607 mTapDetector = TapGestureDetector::New();
609 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
611 mTapDetector.Attach( mItemView.GetChildAt(i) );
614 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::InsertOnTap );
617 void ExitInsertMode()
619 mTapDetector.Reset();
622 void InsertOnTap( Actor actor, const TapGesture& tap )
624 ItemId id = mItemView.GetItemId( actor );
626 Actor newActor = NewItem( rand() );
628 mItemView.InsertItem( Item(id,newActor), 0.5f );
631 void EnterInsertManyMode()
633 SetTitle("Edit: Insert Many");
635 mInsertButton.SetVisible( true );
637 mTapDetector = TapGestureDetector::New();
639 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
641 Actor child = mItemView.GetChildAt( i );
642 Actor box = child.FindChildByName( "CheckBox" );
646 mTapDetector.Attach( child );
647 box.SetVisible( true );
651 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
654 void ExitInsertManyMode()
656 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
658 Actor child = mItemView.GetChildAt( i );
659 Actor box = child.FindChildByName( "CheckBox" );
663 box.SetVisible( false );
665 Actor tick = box.FindChildByName( "Tick" );
668 tick.SetVisible( false );
673 mTapDetector.Reset();
675 mInsertButton.SetVisible( false );
678 bool OnInsertButtonClicked( Toolkit::Button button )
680 ItemContainer insertList;
682 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
684 Actor child = mItemView.GetChildAt( i );
685 Actor tick = child.FindChildByName( "Tick" );
687 if( tick && tick.IsVisible() )
689 insertList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) );
693 if( ! insertList.empty() )
695 mItemView.InsertItems( insertList, 0.5f );
701 void EnterReplaceMode()
703 SetTitle("Edit: Replace");
705 mTapDetector = TapGestureDetector::New();
707 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
709 mTapDetector.Attach(mItemView.GetChildAt(i));
712 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::ReplaceOnTap );
715 void ReplaceOnTap( Actor actor, const TapGesture& tap )
717 mItemView.ReplaceItem( Item( mItemView.GetItemId(actor), NewItem(rand()) ), 0.5f );
720 void ExitReplaceMode()
722 mTapDetector.Reset();
725 void EnterReplaceManyMode()
727 SetTitle("Edit: Replace Many");
729 mReplaceButton.SetVisible( true );
731 mTapDetector = TapGestureDetector::New();
733 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
735 Actor child = mItemView.GetChildAt( i );
736 Actor box = child.FindChildByName( "CheckBox" );
740 mTapDetector.Attach( child );
741 box.SetVisible( true );
745 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
748 void ExitReplaceManyMode()
750 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
752 Actor child = mItemView.GetChildAt( i );
753 Actor box = child.FindChildByName( "CheckBox" );
757 box.SetVisible( false );
759 Actor tick = box.FindChildByName( "Tick" );
762 tick.SetVisible( false );
767 mTapDetector.Reset();
769 mReplaceButton.SetVisible( false );
772 bool OnReplaceButtonClicked( Toolkit::Button button )
774 ItemContainer replaceList;
776 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
778 Actor child = mItemView.GetChildAt( i );
779 Actor tick = child.FindChildByName( "Tick" );
781 if( tick && tick.IsVisible() )
783 replaceList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) );
787 if( ! replaceList.empty() )
789 mItemView.ReplaceItems( replaceList, 0.5f );
795 void SetLayoutTitle()
797 if( MODE_NORMAL == mMode )
799 std::stringstream ss(APPLICATION_TITLE);
800 switch(mCurrentLayout)
803 ss << APPLICATION_TITLE << ": " << SPIRAL_LABEL;
806 ss << APPLICATION_TITLE << ": " << GRID_LABEL;
809 ss << APPLICATION_TITLE << ": " << DEPTH_LABEL;
818 void SetLayoutImage()
822 switch( mCurrentLayout )
826 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE );
827 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE_SELECTED );
833 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, GRID_LAYOUT_IMAGE );
834 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, GRID_LAYOUT_IMAGE_SELECTED );
840 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, DEPTH_LAYOUT_IMAGE );
841 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, DEPTH_LAYOUT_IMAGE_SELECTED );
851 public: // From ItemFactory
854 * Query the number of items available from the factory.
855 * The maximum available item has an ID of GetNumberOfItems() - 1.
857 virtual unsigned int GetNumberOfItems()
859 return NUM_IMAGES * 10;
863 * Create an Actor to represent a visible item.
865 * @return the created actor.
867 virtual Actor NewItem(unsigned int itemId)
869 // Create an image view for this item
870 Property::Map propertyMap;
871 propertyMap.Insert(Toolkit::Visual::Property::TYPE, Visual::IMAGE);
872 propertyMap.Insert(ImageVisual::Property::URL, IMAGE_PATHS[ itemId % NUM_IMAGES ] );
873 propertyMap.Insert(DevelVisual::Property::VISUAL_FITTING_MODE, DevelVisual::FILL);
874 ImageView actor = ImageView::New();
875 actor.SetProperty( Toolkit::ImageView::Property::IMAGE, propertyMap );
877 actor.SetPosition( INITIAL_OFFSCREEN_POSITION );
879 // Add a border image child actor
880 ImageView borderActor = ImageView::New();
881 borderActor.SetParentOrigin( ParentOrigin::CENTER );
882 borderActor.SetAnchorPoint( AnchorPoint::CENTER );
883 borderActor.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
884 borderActor.SetSizeModeFactor( Vector3( 2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f ) );
885 borderActor.SetColorMode( USE_PARENT_COLOR );
887 Property::Map borderProperty;
888 borderProperty.Insert( Toolkit::Visual::Property::TYPE, Visual::BORDER );
889 borderProperty.Insert( BorderVisual::Property::COLOR, Color::WHITE );
890 borderProperty.Insert( BorderVisual::Property::SIZE, ITEM_BORDER_SIZE );
891 borderProperty.Insert( BorderVisual::Property::ANTI_ALIASING, true );
892 borderActor.SetProperty( ImageView::Property::IMAGE, borderProperty );
894 actor.Add(borderActor);
896 actor.SetKeyboardFocusable( true );
898 Vector3 spiralItemSize;
899 static_cast<ItemLayout&>(*mSpiralLayout).GetItemSize( 0u, Vector3( Stage::GetCurrent().GetSize() ), spiralItemSize );
901 // Add a checkbox child actor; invisible until edit-mode is enabled
902 ImageView checkbox = ImageView::New();
903 checkbox.SetName( "CheckBox" );
904 checkbox.SetColorMode( USE_PARENT_COLOR );
905 checkbox.SetParentOrigin( ParentOrigin::TOP_RIGHT );
906 checkbox.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
907 checkbox.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
908 checkbox.SetPosition( -SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH );
909 checkbox.SetZ( 0.1f );
911 Property::Map solidColorProperty;
912 solidColorProperty.Insert( Toolkit::Visual::Property::TYPE, Visual::COLOR );
913 solidColorProperty.Insert( ColorVisual::Property::MIX_COLOR, Vector4(0.f, 0.f, 0.f, 0.6f) );
914 checkbox.SetProperty( ImageView::Property::IMAGE, solidColorProperty );
916 if( MODE_REMOVE_MANY != mMode &&
917 MODE_INSERT_MANY != mMode &&
918 MODE_REPLACE_MANY != mMode )
920 checkbox.SetVisible( false );
922 borderActor.Add( checkbox );
924 ImageView tick = ImageView::New( SELECTED_IMAGE );
925 tick.SetName( "Tick" );
926 tick.SetColorMode( USE_PARENT_COLOR );
927 tick.SetParentOrigin( ParentOrigin::TOP_RIGHT );
928 tick.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
929 tick.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
931 tick.SetVisible( false );
932 checkbox.Add( tick );
934 // Connect new items for various editing modes
937 mTapDetector.Attach( actor );
946 * Sets/Updates the title of the View
947 * @param[in] title The new title for the view.
949 void SetTitle(const std::string& title)
953 mTitleActor = DemoHelper::CreateToolBarLabel( "" );
954 // Add title to the tool bar.
955 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
958 mTitleActor.SetProperty( TextLabel::Property::TEXT, title );
962 * Main key event handler
964 void OnKeyEvent(const KeyEvent& event)
966 if(event.state == KeyEvent::Down)
968 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
977 Application& mApplication;
980 Toolkit::Control mView;
981 unsigned int mOrientation;
983 Toolkit::ToolBar mToolBar;
984 TextLabel mTitleActor; ///< The Toolbar's Title.
987 unsigned int mCurrentLayout;
988 float mDurationSeconds;
990 ItemLayoutPtr mSpiralLayout;
991 ItemLayoutPtr mDepthLayout;
992 ItemLayoutPtr mGridLayout;
994 TapGestureDetector mTapDetector;
995 Toolkit::PushButton mLayoutButton;
996 Toolkit::PushButton mDeleteButton;
997 Toolkit::PushButton mInsertButton;
998 Toolkit::PushButton mReplaceButton;
1000 LongPressGestureDetector mLongPressDetector;
1003 int DALI_EXPORT_API main(int argc, char **argv)
1005 Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);
1006 ItemViewExample test(app);