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 static Vector3 DepthLayoutItemSizeFunctionPortrait( float layoutWidth )
138 float width = ( layoutWidth / ( DEPTH_LAYOUT_COLUMNS + 1.0f ) ) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_PORTRAIT;
141 return Vector3(width, width, width);
144 static Vector3 DepthLayoutItemSizeFunctionLandscape( float layoutWidth )
146 float width = ( layoutWidth / ( DEPTH_LAYOUT_COLUMNS + 1.0f ) ) * DEPTH_LAYOUT_ITEM_SIZE_FACTOR_LANDSCAPE;
149 return Vector3(width, width, width);
152 } // unnamed namespace
155 * This example shows how to use ItemView UI control.
156 * There are three layouts created for ItemView, i.e., Spiral, Depth and Grid.
157 * There is one button in the upper-left corner for quitting the application and
158 * another button in the upper-right corner for switching between different layouts.
160 class ItemViewExample : public ConnectionTracker, public ItemFactory
178 * @param application class, stored as reference
180 ItemViewExample( Application& application )
181 : mApplication( application ),
182 mMode( MODE_NORMAL ),
184 mCurrentLayout( SPIRAL_LAYOUT ),
185 mDurationSeconds( 0.25f )
187 // Connect to the Application's Init signal
188 mApplication.InitSignal().Connect(this, &ItemViewExample::OnInit);
192 * This method gets called once the main loop of application is up and running
194 void OnInit(Application& app)
196 Stage stage = Dali::Stage::GetCurrent();
197 stage.KeyEventSignal().Connect(this, &ItemViewExample::OnKeyEvent);
198 stage.GetRootLayer().SetBehavior(Layer::LAYER_3D);
200 Vector2 stageSize = Stage::GetCurrent().GetSize();
202 // Creates a default view with a default tool bar.
203 // The view is added to the stage.
205 Layer contents = DemoHelper::CreateView( mApplication,
212 //app.GetWindow().GetOrientation().ChangedSignal().Connect( this, &ItemViewExample::OnOrientationChanged );
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
307 Actor OnKeyboardPreFocusChange( Actor current, Actor proposed, Control::KeyboardFocus::Direction direction )
309 if ( !current && !proposed )
318 * Animate to a different layout
322 Animation animation = Animation::New( mDurationSeconds );
323 animation.FinishedSignal().Connect( this, &ItemViewExample::AnimationFinished );
324 animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 0.0f );
328 void AnimationFinished( Animation& )
330 SetLayout( mCurrentLayout );
332 Animation animation = Animation::New( mDurationSeconds );
333 animation.AnimateTo( Property( mItemView, Actor::Property::COLOR_ALPHA ), 1.0f );
338 * Switch to a different item view layout
340 void SetLayout( int layoutId )
342 Stage stage = Dali::Stage::GetCurrent();
343 switch( mCurrentLayout )
348 stage.GetRootLayer().SetBehavior(Layer::LAYER_3D);
353 stage.GetRootLayer().SetBehavior(Layer::LAYER_2D);
358 // Set the new orientation to the layout
359 mItemView.GetLayout(layoutId)->SetOrientation(static_cast<ControlOrientation::Type>(mOrientation / 90));
361 Vector2 stageSize = Stage::GetCurrent().GetSize();
363 if(layoutId == DEPTH_LAYOUT)
365 // Set up the depth layout according to the new orientation
366 if(Toolkit::IsVertical(mDepthLayout->GetOrientation()))
368 mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionPortrait( stageSize.width ) );
372 mDepthLayout->SetItemSize( DepthLayoutItemSizeFunctionLandscape( stageSize.height ) );
376 // Enable anchoring for depth layout only
377 mItemView.SetAnchoring(layoutId == DEPTH_LAYOUT);
379 // Activate the layout
380 mItemView.ActivateLayout( layoutId, Vector3(stageSize.x, stageSize.y, stageSize.x), 0.0f );
384 * Orientation changed signal callback
387 void OnOrientationChanged( Orientation orientation )
389 const unsigned int angle = orientation.GetDegrees();
391 // If orientation really changed
392 if( mOrientation != angle )
394 // Remember orientation
395 mOrientation = angle;
397 SetLayout( mCurrentLayout );
401 bool OnLayoutButtonClicked( Toolkit::Button button )
403 // Switch to the next layout
404 mCurrentLayout = (mCurrentLayout + 1) % mItemView.GetLayoutCount();
414 bool OnModeButtonClicked( Toolkit::Button button )
421 void SwitchToNextMode()
428 mMode = MODE_REMOVE_MANY;
429 EnterRemoveManyMode();
433 case MODE_REMOVE_MANY:
435 ExitRemoveManyMode();
444 mMode = MODE_INSERT_MANY;
445 EnterInsertManyMode();
449 case MODE_INSERT_MANY:
451 ExitInsertManyMode();
452 mMode = MODE_REPLACE;
460 mMode = MODE_REPLACE_MANY;
461 EnterReplaceManyMode();
465 case MODE_REPLACE_MANY:
467 ExitReplaceManyMode();
483 void EnterRemoveMode()
485 SetTitle("Edit: Remove");
487 mTapDetector = TapGestureDetector::New();
489 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
491 mTapDetector.Attach(mItemView.GetChildAt(i));
494 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::RemoveOnTap );
497 void ExitRemoveMode()
499 mTapDetector.Reset();
502 void RemoveOnTap( Actor actor, const TapGesture& tap )
504 mItemView.RemoveItem( mItemView.GetItemId(actor), 0.5f );
507 void EnterRemoveManyMode()
509 SetTitle("Edit: Remove Many");
511 mDeleteButton.SetVisible( true );
513 mTapDetector = TapGestureDetector::New();
515 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
517 Actor child = mItemView.GetChildAt( i );
518 Actor box = child.FindChildByName( "CheckBox" );
522 mTapDetector.Attach( child );
523 box.SetVisible( true );
527 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
530 void ExitRemoveManyMode()
532 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
534 Actor child = mItemView.GetChildAt( i );
535 Actor box = child.FindChildByName( "CheckBox" );
539 box.SetVisible( false );
541 Actor tick = box.FindChildByName( "Tick" );
544 tick.SetVisible( false );
549 mTapDetector.Reset();
551 mDeleteButton.SetVisible( false );
554 void SelectOnTap( Actor actor, const TapGesture& tap )
556 Actor tick = actor.FindChildByName( "Tick" );
559 tick.SetVisible( !tick.IsVisible() );
563 bool OnDeleteButtonClicked( Toolkit::Button button )
565 ItemIdContainer removeList;
567 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
569 Actor child = mItemView.GetChildAt( i );
570 Actor tick = child.FindChildByName( "Tick" );
572 if( tick && tick.IsVisible() )
574 removeList.push_back( mItemView.GetItemId(child) );
578 if( ! removeList.empty() )
580 mItemView.RemoveItems( removeList, 0.5f );
586 void EnterInsertMode()
588 SetTitle("Edit: Insert");
590 mTapDetector = TapGestureDetector::New();
592 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
594 mTapDetector.Attach( mItemView.GetChildAt(i) );
597 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::InsertOnTap );
600 void ExitInsertMode()
602 mTapDetector.Reset();
605 void InsertOnTap( Actor actor, const TapGesture& tap )
607 ItemId id = mItemView.GetItemId( actor );
609 Actor newActor = NewItem( rand() );
611 mItemView.InsertItem( Item(id,newActor), 0.5f );
614 void EnterInsertManyMode()
616 SetTitle("Edit: Insert Many");
618 mInsertButton.SetVisible( true );
620 mTapDetector = TapGestureDetector::New();
622 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
624 Actor child = mItemView.GetChildAt( i );
625 Actor box = child.FindChildByName( "CheckBox" );
629 mTapDetector.Attach( child );
630 box.SetVisible( true );
634 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
637 void ExitInsertManyMode()
639 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
641 Actor child = mItemView.GetChildAt( i );
642 Actor box = child.FindChildByName( "CheckBox" );
646 box.SetVisible( false );
648 Actor tick = box.FindChildByName( "Tick" );
651 tick.SetVisible( false );
656 mTapDetector.Reset();
658 mInsertButton.SetVisible( false );
661 bool OnInsertButtonClicked( Toolkit::Button button )
663 ItemContainer insertList;
665 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
667 Actor child = mItemView.GetChildAt( i );
668 Actor tick = child.FindChildByName( "Tick" );
670 if( tick && tick.IsVisible() )
672 insertList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) );
676 if( ! insertList.empty() )
678 mItemView.InsertItems( insertList, 0.5f );
684 void EnterReplaceMode()
686 SetTitle("Edit: Replace");
688 mTapDetector = TapGestureDetector::New();
690 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
692 mTapDetector.Attach(mItemView.GetChildAt(i));
695 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::ReplaceOnTap );
698 void ReplaceOnTap( Actor actor, const TapGesture& tap )
700 mItemView.ReplaceItem( Item( mItemView.GetItemId(actor), NewItem(rand()) ), 0.5f );
703 void ExitReplaceMode()
705 mTapDetector.Reset();
708 void EnterReplaceManyMode()
710 SetTitle("Edit: Replace Many");
712 mReplaceButton.SetVisible( true );
714 mTapDetector = TapGestureDetector::New();
716 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
718 Actor child = mItemView.GetChildAt( i );
719 Actor box = child.FindChildByName( "CheckBox" );
723 mTapDetector.Attach( child );
724 box.SetVisible( true );
728 mTapDetector.DetectedSignal().Connect( this, &ItemViewExample::SelectOnTap );
731 void ExitReplaceManyMode()
733 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
735 Actor child = mItemView.GetChildAt( i );
736 Actor box = child.FindChildByName( "CheckBox" );
740 box.SetVisible( false );
742 Actor tick = box.FindChildByName( "Tick" );
745 tick.SetVisible( false );
750 mTapDetector.Reset();
752 mReplaceButton.SetVisible( false );
755 bool OnReplaceButtonClicked( Toolkit::Button button )
757 ItemContainer replaceList;
759 for( unsigned int i = 0u; i < mItemView.GetChildCount(); ++i )
761 Actor child = mItemView.GetChildAt( i );
762 Actor tick = child.FindChildByName( "Tick" );
764 if( tick && tick.IsVisible() )
766 replaceList.push_back( Item( mItemView.GetItemId(child), NewItem(rand()) ) );
770 if( ! replaceList.empty() )
772 mItemView.ReplaceItems( replaceList, 0.5f );
778 void SetLayoutTitle()
780 if( MODE_NORMAL == mMode )
782 std::stringstream ss(APPLICATION_TITLE);
783 switch(mCurrentLayout)
786 ss << APPLICATION_TITLE << ": " << SPIRAL_LABEL;
789 ss << APPLICATION_TITLE << ": " << GRID_LABEL;
792 ss << APPLICATION_TITLE << ": " << DEPTH_LABEL;
801 void SetLayoutImage()
805 switch( mCurrentLayout )
809 mLayoutButton.SetUnselectedImage( SPIRAL_LAYOUT_IMAGE );
810 mLayoutButton.SetSelectedImage( SPIRAL_LAYOUT_IMAGE_SELECTED );
816 mLayoutButton.SetUnselectedImage( GRID_LAYOUT_IMAGE );
817 mLayoutButton.SetSelectedImage( GRID_LAYOUT_IMAGE_SELECTED );
823 mLayoutButton.SetUnselectedImage( DEPTH_LAYOUT_IMAGE );
824 mLayoutButton.SetSelectedImage( DEPTH_LAYOUT_IMAGE_SELECTED );
834 public: // From ItemFactory
837 * Query the number of items available from the factory.
838 * The maximum available item has an ID of GetNumberOfItems() - 1.
840 virtual unsigned int GetNumberOfItems()
842 return NUM_IMAGES * 10;
846 * Create an Actor to represent a visible item.
848 * @return the created actor.
850 virtual Actor NewItem(unsigned int itemId)
852 // Create an image view for this item
853 ImageView actor = ImageView::New( IMAGE_PATHS[ itemId % NUM_IMAGES ] );
855 actor.SetPosition( INITIAL_OFFSCREEN_POSITION );
857 // Add a border image child actor
858 ImageView borderActor = ImageView::New();
859 borderActor.SetParentOrigin( ParentOrigin::CENTER );
860 borderActor.SetAnchorPoint( AnchorPoint::CENTER );
861 borderActor.SetResizePolicy( ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT, Dimension::ALL_DIMENSIONS );
862 borderActor.SetSizeModeFactor( Vector3( 2.0f * ITEM_BORDER_SIZE, 2.0f * ITEM_BORDER_SIZE, 0.0f ) );
863 borderActor.SetColorMode( USE_PARENT_COLOR );
865 Property::Map borderProperty;
866 borderProperty.Insert( "rendererType", "borderRenderer" );
867 borderProperty.Insert( "borderColor", Color::WHITE );
868 borderProperty.Insert( "borderSize", ITEM_BORDER_SIZE );
869 borderActor.SetProperty( ImageView::Property::IMAGE, borderProperty );
871 actor.Add(borderActor);
873 actor.SetKeyboardFocusable( true );
875 Vector3 spiralItemSize;
876 static_cast<ItemLayout&>(*mSpiralLayout).GetItemSize( 0u, Vector3( Stage::GetCurrent().GetSize() ), spiralItemSize );
878 // Add a checkbox child actor; invisible until edit-mode is enabled
879 ImageView checkbox = ImageView::New();
880 checkbox.SetName( "CheckBox" );
881 checkbox.SetColorMode( USE_PARENT_COLOR );
882 checkbox.SetParentOrigin( ParentOrigin::TOP_RIGHT );
883 checkbox.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
884 checkbox.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
885 checkbox.SetPosition( -SELECTION_BORDER_WIDTH, SELECTION_BORDER_WIDTH );
886 checkbox.SetZ( 0.1f );
888 Property::Map solidColorProperty;
889 solidColorProperty.Insert( "rendererType", "colorRenderer" );
890 solidColorProperty.Insert( "blendColor", Vector4(0.f, 0.f, 0.f, 0.6f) );
891 checkbox.SetProperty( ImageView::Property::IMAGE, solidColorProperty );
893 if( MODE_REMOVE_MANY != mMode &&
894 MODE_INSERT_MANY != mMode &&
895 MODE_REPLACE_MANY != mMode )
897 checkbox.SetVisible( false );
899 borderActor.Add( checkbox );
901 ImageView tick = ImageView::New( SELECTED_IMAGE );
902 tick.SetName( "Tick" );
903 tick.SetColorMode( USE_PARENT_COLOR );
904 tick.SetParentOrigin( ParentOrigin::TOP_RIGHT );
905 tick.SetAnchorPoint( AnchorPoint::TOP_RIGHT );
906 tick.SetSize( spiralItemSize.width * 0.2f, spiralItemSize.width * 0.2f );
908 tick.SetVisible( false );
909 checkbox.Add( tick );
911 // Connect new items for various editing modes
914 mTapDetector.Attach( actor );
923 * Sets/Updates the title of the View
924 * @param[in] title The new title for the view.
926 void SetTitle(const std::string& title)
930 mTitleActor = DemoHelper::CreateToolBarLabel( "" );
931 // Add title to the tool bar.
932 mToolBar.AddControl( mTitleActor, DemoHelper::DEFAULT_VIEW_STYLE.mToolBarTitlePercentage, Alignment::HorizontalCenter );
935 mTitleActor.SetProperty( TextLabel::Property::TEXT, title );
939 * Main key event handler
941 void OnKeyEvent(const KeyEvent& event)
943 if(event.state == KeyEvent::Down)
945 if( IsKey( event, DALI_KEY_ESCAPE) || IsKey( event, DALI_KEY_BACK ) )
954 Application& mApplication;
957 Toolkit::Control mView;
958 unsigned int mOrientation;
960 Toolkit::ToolBar mToolBar;
961 TextLabel mTitleActor; ///< The Toolbar's Title.
964 unsigned int mCurrentLayout;
965 float mDurationSeconds;
967 ItemLayoutPtr mSpiralLayout;
968 ItemLayoutPtr mDepthLayout;
969 ItemLayoutPtr mGridLayout;
971 TapGestureDetector mTapDetector;
972 Toolkit::PushButton mLayoutButton;
973 Toolkit::PushButton mDeleteButton;
974 Toolkit::PushButton mInsertButton;
975 Toolkit::PushButton mReplaceButton;
978 void RunTest(Application& app)
980 ItemViewExample test(app);
985 int main(int argc, char **argv)
987 Application app = Application::New(&argc, &argv, DEMO_THEME_PATH);