2 * Copyright (c) 2017 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>
26 using namespace Dali::Toolkit;
40 const char* IMAGE_PATHS[] = {
41 DEMO_IMAGE_DIR "gallery-medium-1.jpg",
42 DEMO_IMAGE_DIR "gallery-medium-2.jpg",
43 DEMO_IMAGE_DIR "gallery-medium-3.jpg",
44 DEMO_IMAGE_DIR "gallery-medium-4.jpg",
45 DEMO_IMAGE_DIR "gallery-medium-5.jpg",
46 DEMO_IMAGE_DIR "gallery-medium-6.jpg",
47 DEMO_IMAGE_DIR "gallery-medium-7.jpg",
48 DEMO_IMAGE_DIR "gallery-medium-8.jpg",
49 DEMO_IMAGE_DIR "gallery-medium-9.jpg",
50 DEMO_IMAGE_DIR "gallery-medium-10.jpg",
51 DEMO_IMAGE_DIR "gallery-medium-11.jpg",
52 DEMO_IMAGE_DIR "gallery-medium-12.jpg",
53 DEMO_IMAGE_DIR "gallery-medium-13.jpg",
54 DEMO_IMAGE_DIR "gallery-medium-14.jpg",
55 DEMO_IMAGE_DIR "gallery-medium-15.jpg",
56 DEMO_IMAGE_DIR "gallery-medium-16.jpg",
57 DEMO_IMAGE_DIR "gallery-medium-17.jpg",
58 DEMO_IMAGE_DIR "gallery-medium-18.jpg",
59 DEMO_IMAGE_DIR "gallery-medium-19.jpg",
60 DEMO_IMAGE_DIR "gallery-medium-20.jpg",
61 DEMO_IMAGE_DIR "gallery-medium-21.jpg",
62 DEMO_IMAGE_DIR "gallery-medium-22.jpg",
63 DEMO_IMAGE_DIR "gallery-medium-23.jpg",
64 DEMO_IMAGE_DIR "gallery-medium-24.jpg",
65 DEMO_IMAGE_DIR "gallery-medium-25.jpg",
66 DEMO_IMAGE_DIR "gallery-medium-26.jpg",
67 DEMO_IMAGE_DIR "gallery-medium-27.jpg",
68 DEMO_IMAGE_DIR "gallery-medium-28.jpg",
69 DEMO_IMAGE_DIR "gallery-medium-29.jpg",
70 DEMO_IMAGE_DIR "gallery-medium-30.jpg",
71 DEMO_IMAGE_DIR "gallery-medium-31.jpg",
72 DEMO_IMAGE_DIR "gallery-medium-32.jpg",
73 DEMO_IMAGE_DIR "gallery-medium-33.jpg",
74 DEMO_IMAGE_DIR "gallery-medium-34.jpg",
75 DEMO_IMAGE_DIR "gallery-medium-35.jpg",
76 DEMO_IMAGE_DIR "gallery-medium-36.jpg",
77 DEMO_IMAGE_DIR "gallery-medium-37.jpg",
78 DEMO_IMAGE_DIR "gallery-medium-38.jpg",
79 DEMO_IMAGE_DIR "gallery-medium-39.jpg",
80 DEMO_IMAGE_DIR "gallery-medium-40.jpg",
81 DEMO_IMAGE_DIR "gallery-medium-41.jpg",
82 DEMO_IMAGE_DIR "gallery-medium-42.jpg",
83 DEMO_IMAGE_DIR "gallery-medium-43.jpg",
84 DEMO_IMAGE_DIR "gallery-medium-44.jpg",
85 DEMO_IMAGE_DIR "gallery-medium-45.jpg",
86 DEMO_IMAGE_DIR "gallery-medium-46.jpg",
87 DEMO_IMAGE_DIR "gallery-medium-47.jpg",
88 DEMO_IMAGE_DIR "gallery-medium-48.jpg",
89 DEMO_IMAGE_DIR "gallery-medium-49.jpg",
90 DEMO_IMAGE_DIR "gallery-medium-50.jpg",
91 DEMO_IMAGE_DIR "gallery-medium-51.jpg",
92 DEMO_IMAGE_DIR "gallery-medium-52.jpg",
93 DEMO_IMAGE_DIR "gallery-medium-53.jpg",
96 const unsigned int NUM_IMAGES = sizeof(IMAGE_PATHS) / sizeof(char*);
98 const char* BACKGROUND_IMAGE( "" );
99 const char* TOOLBAR_IMAGE( DEMO_IMAGE_DIR "top-bar.png" );
100 const char* EDIT_IMAGE( DEMO_IMAGE_DIR "icon-edit.png" );
101 const char* EDIT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-edit-selected.png" );
102 const char* SPIRAL_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-spiral.png" );
103 const char* SPIRAL_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-spiral-selected.png" );
104 const char* GRID_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-grid.png" );
105 const char* GRID_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-grid-selected.png" );
106 const char* DEPTH_LAYOUT_IMAGE( DEMO_IMAGE_DIR "icon-item-view-layout-depth.png" );
107 const char* DEPTH_LAYOUT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-item-view-layout-depth-selected.png" );
108 const char* DELETE_IMAGE( DEMO_IMAGE_DIR "icon-delete.png" );
109 const char* DELETE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-delete-selected.png" );
110 const char* REPLACE_IMAGE( DEMO_IMAGE_DIR "icon-replace.png" );
111 const char* REPLACE_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-replace-selected.png" );
112 const char* INSERT_IMAGE( DEMO_IMAGE_DIR "icon-insert.png" );
113 const char* INSERT_IMAGE_SELECTED( DEMO_IMAGE_DIR "icon-insert-selected.png" );
114 const char* SELECTED_IMAGE( DEMO_IMAGE_DIR "item-select-check.png" );
115 const char* APPLICATION_TITLE( "ItemView" );
117 const char* SPIRAL_LABEL("Spiral");
118 const char* GRID_LABEL("Grid");
119 const char* DEPTH_LABEL("Depth");
121 const float ITEM_BORDER_SIZE = 2.0f;
123 const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT = 1.0f;
124 const float DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE = 0.8f;
125 const float DEPTH_LAYOUT_COLUMNS = 3.0f;
127 const float MIN_SWIPE_DISTANCE = 15.0f;
128 const float MIN_SWIPE_SPEED = 5.0f;
130 const float SELECTION_BORDER_WIDTH = 3.0f;
131 const float BUTTON_BORDER = -10.0f;
132 const float MENU_OPTION_HEIGHT(140.0f);
133 const float LABEL_TEXT_SIZE_Y = 20.0f;
135 const Vector3 INITIAL_OFFSCREEN_POSITION( 1000.0f, 0, -1000.0f );
137 const float SCROLL_TO_ITEM_ANIMATION_TIME = 5.f;
139 static Vector3 DepthLayoutItemSizeFunctionPortrait( float layoutWidth )
141 float width = ( layoutWidth / ( DEPTH_LAYOUT_COLUMNS + 1.0f ) ) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT;
144 return Vector3(width, width, width);
147 static Vector3 DepthLayoutItemSizeFunctionLandscape( float layoutWidth )
149 float width = ( layoutWidth / ( DEPTH_LAYOUT_COLUMNS + 1.0f ) ) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE;
152 return Vector3(width, width, width);
155 } // unnamed namespace
158 * This example shows how to use ItemView UI control.
159 * There are three layouts created for ItemView, i.e., Spiral, Depth and Grid.
160 * There is one button in the upper-left corner for quitting the application and
161 * another button in the upper-right corner for switching between different layouts.
163 class ItemViewExample : public ConnectionTracker, public ItemFactory
181 * @param application class, stored as reference
183 ItemViewExample( Application& application )
184 : mApplication( application ),
185 mMode( MODE_NORMAL ),
187 mCurrentLayout( SPIRAL_LAYOUT ),
188 mDurationSeconds( 0.25f )
190 // Connect to the Application's Init signal
191 mApplication.InitSignal().Connect(this, &ItemViewExample::OnInit);
195 * This method gets called once the main loop of application is up and running
197 void OnInit(Application& app)
199 Stage stage = Dali::Stage::GetCurrent();
200 stage.KeyEventSignal().Connect(this, &ItemViewExample::OnKeyEvent);
201 stage.GetRootLayer().SetBehavior(Layer::LAYER_3D);
203 Vector2 stageSize = Stage::GetCurrent().GetSize();
205 // Creates a default view with a default tool bar.
206 // The view is added to the stage.
208 Layer contents = DemoHelper::CreateView( mApplication,
215 // Create an edit mode button. (left of toolbar)
216 Toolkit::PushButton editButton = Toolkit::PushButton::New();
217 editButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, EDIT_IMAGE );
218 editButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, EDIT_IMAGE_SELECTED );
219 editButton.ClickedSignal().Connect( this, &ItemViewExample::OnModeButtonClicked);
220 editButton.SetLeaveRequired( true );
221 mToolBar.AddControl( editButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalLeft, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
223 // Create a layout toggle button. (right of toolbar)
224 mLayoutButton = Toolkit::PushButton::New();
225 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE );
226 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE_SELECTED );
227 mLayoutButton.ClickedSignal().Connect( this, &ItemViewExample::OnLayoutButtonClicked);
228 mLayoutButton.SetLeaveRequired( true );
229 mToolBar.AddControl( mLayoutButton, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarButtonPercentage, Toolkit::Alignment::HorizontalRight, DemoHelper::DEFAULT_MODE_SWITCH_PADDING );
231 // Create a delete button (bottom right of screen)
232 mDeleteButton = Toolkit::PushButton::New();
233 mDeleteButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
234 mDeleteButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
235 mDeleteButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
236 mDeleteButton.SetDrawMode( DrawMode::OVERLAY_2D );
237 mDeleteButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, DELETE_IMAGE );
238 mDeleteButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, DELETE_IMAGE_SELECTED );
239 mDeleteButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE );
240 mDeleteButton.SetSize( Vector2( stageSize.width * 0.15f, stageSize.width * 0.15f ) );
241 mDeleteButton.ClickedSignal().Connect( this, &ItemViewExample::OnDeleteButtonClicked);
242 mDeleteButton.SetLeaveRequired( true );
243 mDeleteButton.SetVisible( false );
244 stage.Add( mDeleteButton );
246 // Create an insert button (bottom right of screen)
247 mInsertButton = Toolkit::PushButton::New();
248 mInsertButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
249 mInsertButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
250 mInsertButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
251 mInsertButton.SetDrawMode( DrawMode::OVERLAY_2D );
252 mInsertButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, INSERT_IMAGE );
253 mInsertButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, INSERT_IMAGE_SELECTED );
254 mInsertButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE );
255 mInsertButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
256 mInsertButton.ClickedSignal().Connect( this, &ItemViewExample::OnInsertButtonClicked);
257 mInsertButton.SetLeaveRequired( true );
258 mInsertButton.SetVisible( false );
259 stage.Add( mInsertButton );
261 // Create an replace button (bottom right of screen)
262 mReplaceButton = Toolkit::PushButton::New();
263 mReplaceButton.SetParentOrigin(ParentOrigin::BOTTOM_RIGHT);
264 mReplaceButton.SetAnchorPoint(AnchorPoint::BOTTOM_RIGHT);
265 mReplaceButton.SetPosition( BUTTON_BORDER, BUTTON_BORDER );
266 mReplaceButton.SetDrawMode( DrawMode::OVERLAY_2D );
267 mReplaceButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, REPLACE_IMAGE );
268 mReplaceButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, REPLACE_IMAGE_SELECTED );
269 mReplaceButton.SetProperty( Toolkit::Control::Property::BACKGROUND, TOOLBAR_IMAGE );
270 mReplaceButton.SetSize( stageSize.width * 0.15f, stageSize.width * 0.15f );
271 mReplaceButton.ClickedSignal().Connect( this, &ItemViewExample::OnReplaceButtonClicked);
272 mReplaceButton.SetLeaveRequired( true );
273 mReplaceButton.SetVisible( false );
274 stage.Add( mReplaceButton );
276 // Create the item view actor
277 mItemView = ItemView::New(*this);
278 mItemView.SetParentOrigin(ParentOrigin::CENTER);
279 mItemView.SetAnchorPoint(AnchorPoint::CENTER);
281 // Display item view on the stage
282 stage.Add( mItemView );
283 stage.GetRootLayer().SetBehavior( Layer::LAYER_3D );
285 // Create the layouts
286 mSpiralLayout = DefaultItemLayout::New( DefaultItemLayout::SPIRAL );
287 mDepthLayout = DefaultItemLayout::New( DefaultItemLayout::DEPTH );
288 mGridLayout = DefaultItemLayout::New( DefaultItemLayout::GRID );
290 // Add the layouts to item view
291 mItemView.AddLayout(*mSpiralLayout);
292 mItemView.AddLayout(*mDepthLayout);
293 mItemView.AddLayout(*mGridLayout);
295 mItemView.SetMinimumSwipeDistance(MIN_SWIPE_DISTANCE);
296 mItemView.SetMinimumSwipeSpeed(MIN_SWIPE_SPEED);
298 // Activate the spiral layout
299 SetLayout( mCurrentLayout );
300 mItemView.SetKeyboardFocusable( true );
301 KeyboardFocusManager::Get().PreFocusChangeSignal().Connect( this, &ItemViewExample::OnKeyboardPreFocusChange );
303 // Set the title and icon to the current layout
307 mLongPressDetector = LongPressGestureDetector::New();
308 mLongPressDetector.Attach( mItemView );
309 mLongPressDetector.DetectedSignal().Connect( this, &ItemViewExample::OnLongPress );
312 Actor OnKeyboardPreFocusChange( Actor current, Actor proposed, Control::KeyboardFocus::Direction direction )
314 if ( !current && !proposed )
323 * Animate to a different layout
327 Animation animation = Animation::New( mDurationSeconds );
328 animation.FinishedSignal().Connect( this, &ItemViewExample::AnimationFinished );
329 animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 0.0f );
333 void AnimationFinished( Animation& )
335 SetLayout( mCurrentLayout );
337 Animation animation = Animation::New( mDurationSeconds );
338 animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 1.0f );
343 * Switch to a different item view layout
345 void SetLayout( int layoutId )
347 Stage stage = Dali::Stage::GetCurrent();
348 switch( mCurrentLayout )
353 stage.GetRootLayer().SetBehavior(Layer::LAYER_3D);
358 stage.GetRootLayer().SetBehavior(Layer::LAYER_2D);
363 // Set the new orientation to the layout
364 mItemView.GetLayout(layoutId)->SetOrientation(static_cast<ControlOrientation::Type>(mOrientation / 90));
366 Vector2 stageSize = Stage::GetCurrent().GetSize();
368 if(layoutId == DEPTH_LAYOUT)
370 // Set up the depth layout according to the new orientation
371 if(Toolkit::IsVertical(mDepthLayout->GetOrientation()))
373 mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionPortrait( stageSize.width ) );
377 mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionLandscape( stageSize.height ) );
381 // Enable anchoring for depth layout only
382 mItemView.SetAnchoring(layoutId == DEPTH_LAYOUT);
384 // Activate the layout
385 mItemView.ActivateLayout( layoutId, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
388 bool OnLayoutButtonClicked( Toolkit::Button button )
390 // Switch to the next layout
391 mCurrentLayout = (mCurrentLayout + 1) % mItemView.GetLayoutCount();
401 bool OnModeButtonClicked( Toolkit::Button button )
408 void SwitchToNextMode()
415 mMode = MODE_REMOVE_MANY;
416 EnterRemoveManyMode();
420 case MODE_REMOVE_MANY:
422 ExitRemoveManyMode();
431 mMode = MODE_INSERT_MANY;
432 EnterInsertManyMode();
436 case MODE_INSERT_MANY:
438 ExitInsertManyMode();
439 mMode = MODE_REPLACE;
447 mMode = MODE_REPLACE_MANY;
448 EnterReplaceManyMode();
452 case MODE_REPLACE_MANY:
454 ExitReplaceManyMode();
470 void EnterRemoveMode()
472 SetTitle("Edit: Remove");
474 mTapDetector = TapGestureDetector::New();
476 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
478 mTapDetector.Attach(mItemView.GetChildAt(i));
481 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::RemoveOnTap );
484 void ExitRemoveMode()
486 mTapDetector.Reset();
489 void RemoveOnTap( Actor actor, const TapGesture& tap )
491 mItemView.RemoveItem( mItemView.GetItemId(actor), 0.5f );
494 void EnterRemoveManyMode()
496 SetTitle("Edit: Remove Many");
498 mDeleteButton.SetVisible( true );
500 mTapDetector = TapGestureDetector::New();
502 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
504 Actor child = mItemView.GetChildAt( i );
505 Actor box = child.FindChildByName( "CheckBox" );
509 mTapDetector.Attach( child );
510 box.SetVisible( true );
514 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
517 void ExitRemoveManyMode()
519 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
521 Actor child = mItemView.GetChildAt( i );
522 Actor box = child.FindChildByName( "CheckBox" );
526 box.SetVisible( false );
528 Actor tick = box.FindChildByName( "Tick" );
531 tick.SetVisible( false );
536 mTapDetector.Reset();
538 mDeleteButton.SetVisible( false );
541 void SelectOnTap( Actor actor, const TapGesture& tap )
543 Actor tick = actor.FindChildByName( "Tick" );
546 tick.SetVisible( !tick.IsVisible() );
550 void OnLongPress( Actor actor, const LongPressGesture& gesture )
552 switch( gesture.state )
554 case Gesture::Started:
556 const Size& size = Stage::GetCurrent().GetSize();
558 ItemRange range( 0u, 0u );
559 mItemView.GetItemsRange( range );
561 const unsigned int item = ( gesture.screenPoint.y < 0.5f * size.height ) ? range.begin : range.end;
562 mItemView.ScrollToItem( item, SCROLL_TO_ITEM_ANIMATION_TIME );
566 case Gesture::Finished:
568 Property::Map attributes;
569 mItemView.DoAction( "stopScrolling", attributes );
579 bool OnDeleteButtonClicked( Toolkit::Button button )
581 ItemIdContainer removeList;
583 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
585 Actor child = mItemView.GetChildAt( i );
586 Actor tick = child.FindChildByName( "Tick" );
588 if( tick && tick.IsVisible() )
590 removeList.push_back( mItemView.GetItemId(child) );
594 if( ! removeList.empty() )
596 mItemView.RemoveItems( removeList, 0.5f );
602 void EnterInsertMode()
604 SetTitle("Edit: Insert");
606 mTapDetector = TapGestureDetector::New();
608 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
610 mTapDetector.Attach( mItemView.GetChildAt(i) );
613 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::InsertOnTap );
616 void ExitInsertMode()
618 mTapDetector.Reset();
621 void InsertOnTap( Actor actor, const TapGesture& tap )
623 ItemId id = mItemView.GetItemId( actor );
625 Actor newActor = NewItem( rand() );
627 mItemView.InsertItem( Item(id,newActor), 0.5f );
630 void EnterInsertManyMode()
632 SetTitle("Edit: Insert Many");
634 mInsertButton.SetVisible( true );
636 mTapDetector = TapGestureDetector::New();
638 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
640 Actor child = mItemView.GetChildAt( i );
641 Actor box = child.FindChildByName( "CheckBox" );
645 mTapDetector.Attach( child );
646 box.SetVisible( true );
650 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
653 void ExitInsertManyMode()
655 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
657 Actor child = mItemView.GetChildAt( i );
658 Actor box = child.FindChildByName( "CheckBox" );
662 box.SetVisible( false );
664 Actor tick = box.FindChildByName( "Tick" );
667 tick.SetVisible( false );
672 mTapDetector.Reset();
674 mInsertButton.SetVisible( false );
677 bool OnInsertButtonClicked( Toolkit::Button button )
679 ItemContainer insertList;
681 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
683 Actor child = mItemView.GetChildAt( i );
684 Actor tick = child.FindChildByName( "Tick" );
686 if( tick && tick.IsVisible() )
688 insertList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) );
692 if( ! insertList.empty() )
694 mItemView.InsertItems( insertList, 0.5f );
700 void EnterReplaceMode()
702 SetTitle("Edit: Replace");
704 mTapDetector = TapGestureDetector::New();
706 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
708 mTapDetector.Attach(mItemView.GetChildAt(i));
711 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::ReplaceOnTap );
714 void ReplaceOnTap( Actor actor, const TapGesture& tap )
716 mItemView.ReplaceItem( Item( mItemView.GetItemId(actor), NewItem(rand()) ), 0.5f );
719 void ExitReplaceMode()
721 mTapDetector.Reset();
724 void EnterReplaceManyMode()
726 SetTitle("Edit: Replace Many");
728 mReplaceButton.SetVisible( true );
730 mTapDetector = TapGestureDetector::New();
732 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
734 Actor child = mItemView.GetChildAt( i );
735 Actor box = child.FindChildByName( "CheckBox" );
739 mTapDetector.Attach( child );
740 box.SetVisible( true );
744 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
747 void ExitReplaceManyMode()
749 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
751 Actor child = mItemView.GetChildAt( i );
752 Actor box = child.FindChildByName( "CheckBox" );
756 box.SetVisible( false );
758 Actor tick = box.FindChildByName( "Tick" );
761 tick.SetVisible( false );
766 mTapDetector.Reset();
768 mReplaceButton.SetVisible( false );
771 bool OnReplaceButtonClicked( Toolkit::Button button )
773 ItemContainer replaceList;
775 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
777 Actor child = mItemView.GetChildAt( i );
778 Actor tick = child.FindChildByName( "Tick" );
780 if( tick && tick.IsVisible() )
782 replaceList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) );
786 if( ! replaceList.empty() )
788 mItemView.ReplaceItems( replaceList, 0.5f );
794 void SetLayoutTitle()
796 if( MODE_NORMAL == mMode )
798 std::stringstream ss(APPLICATION_TITLE);
799 switch(mCurrentLayout)
802 ss << APPLICATION_TITLE << ": " << SPIRAL_LABEL;
805 ss << APPLICATION_TITLE << ": " << GRID_LABEL;
808 ss << APPLICATION_TITLE << ": " << DEPTH_LABEL;
817 void SetLayoutImage()
821 switch( mCurrentLayout )
825 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE );
826 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, SPIRAL_LAYOUT_IMAGE_SELECTED );
832 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, GRID_LAYOUT_IMAGE );
833 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, GRID_LAYOUT_IMAGE_SELECTED );
839 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::UNSELECTED_BACKGROUND_VISUAL, DEPTH_LAYOUT_IMAGE );
840 mLayoutButton.SetProperty( Toolkit::DevelButton::Property::SELECTED_BACKGROUND_VISUAL, DEPTH_LAYOUT_IMAGE_SELECTED );
850 public: // From ItemFactory
853 * Query the number of items available from the factory.
854 * The maximum available item has an ID of GetNumberOfItems() - 1.
856 virtual unsigned int GetNumberOfItems()
858 return NUM_IMAGES * 10;
862 * Create an Actor to represent a visible item.
864 * @return the created actor.
866 virtual Actor NewItem(unsigned int itemId)
868 // Create an image view for this item
869 ImageView actor = ImageView::New( IMAGE_PATHS[ itemId % NUM_IMAGES ] );
871 actor.SetPosition( INITIAL_OFFSCREEN_POSITION );
873 // Add a border image child actor
874 ImageView borderActor = ImageView::New();
875 borderActor.SetParentOrigin( ParentOrigin::CENTER );
876 borderActor.SetAnchorPoint( AnchorPoint::CENTER );
877 borderActor.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
878 borderActor.SetSizeModeFactor( Vector3( 2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f ) );
879 borderActor.SetColorMode( USE_PARENT_COLOR );
881 Property::Map borderProperty;
882 borderProperty.Insert( Visual::Property::TYPE, Visual::BORDER );
883 borderProperty.Insert( BorderVisual::Property::COLOR, Color::WHITE );
884 borderProperty.Insert( BorderVisual::Property::SIZE, ITEM_BORDER_SIZE );
885 borderProperty.Insert( BorderVisual::Property::ANTI_ALIASING, true );
886 borderActor.SetProperty( ImageView::Property::IMAGE, borderProperty );
888 actor.Add(borderActor);
890 actor.SetKeyboardFocusable( true );
892 Vector3 spiralItemSize;
893 static_cast<ItemLayout&>(*mSpiralLayout).GetItemSize( 0u, Vector3( Stage::GetCurrent().GetSize() ), spiralItemSize );
895 // Add a checkbox child actor; invisible until edit-mode is enabled
896 ImageView checkbox = ImageView::New();
897 checkbox.SetName( "CheckBox" );
898 checkbox.SetColorMode( USE_PARENT_COLOR );
899 checkbox.SetParentOrigin( ParentOrigin::TOP_RIGHT );
900 checkbox.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
901 checkbox.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
902 checkbox.SetPosition( -SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH );
903 checkbox.SetZ( 0.1f );
905 Property::Map solidColorProperty;
906 solidColorProperty.Insert( Visual::Property::TYPE, Visual::COLOR );
907 solidColorProperty.Insert( ColorVisual::Property::MIX_COLOR, Vector4(0.f, 0.f, 0.f, 0.6f) );
908 checkbox.SetProperty( ImageView::Property::IMAGE, solidColorProperty );
910 if( MODE_REMOVE_MANY != mMode &&
911 MODE_INSERT_MANY != mMode &&
912 MODE_REPLACE_MANY != mMode )
914 checkbox.SetVisible( false );
916 borderActor.Add( checkbox );
918 ImageView tick = ImageView::New( SELECTED_IMAGE );
919 tick.SetName( "Tick" );
920 tick.SetColorMode( USE_PARENT_COLOR );
921 tick.SetParentOrigin( ParentOrigin::TOP_RIGHT );
922 tick.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
923 tick.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
925 tick.SetVisible( false );
926 checkbox.Add( tick );
928 // Connect new items for various editing modes
931 mTapDetector.Attach( actor );
940 * Sets/Updates the title of the View
941 * @param[in] title The new title for the view.
943 void SetTitle(const std::string& title)
947 mTitleActor = DemoHelper::CreateToolBarLabel( "" );
948 // Add title to the tool bar.
949 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
952 mTitleActor.SetProperty( TextLabel::Property::TEXT, title );
956 * Main key event handler
958 void OnKeyEvent(const KeyEvent& event)
960 if(event.state == KeyEvent::Down)
962 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
971 Application& mApplication;
974 Toolkit::Control mView;
975 unsigned int mOrientation;
977 Toolkit::ToolBar mToolBar;
978 TextLabel mTitleActor; ///< The Toolbar's Title.
981 unsigned int mCurrentLayout;
982 float mDurationSeconds;
984 ItemLayoutPtr mSpiralLayout;
985 ItemLayoutPtr mDepthLayout;
986 ItemLayoutPtr mGridLayout;
988 TapGestureDetector mTapDetector;
989 Toolkit::PushButton mLayoutButton;
990 Toolkit::PushButton mDeleteButton;
991 Toolkit::PushButton mInsertButton;
992 Toolkit::PushButton mReplaceButton;
994 LongPressGestureDetector mLongPressDetector;
997 void RunTest(Application& app)
999 ItemViewExample test(app);
1004 int DALI_EXPORT_API main(int argc, char **argv)
1006 Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);