4 # Item View {#item-view}
6 An Item view is a scrollable container that contains several items.
7 It can have several layouts.
8 There are a few built-in layouts that the application writer can use:
10 |GRID |SPIRAL |DEPTH |
11 |:----------------------:|:------------------------:|:-----------------------:|
12 |![ ](item-view/grid.png)|![ ](item-view/spiral.png)|![ ](item-view/depth.png)|
14 The application writer can also create their own custom layout by inheriting from Dali::Toolkit::ItemLayout.
18 To create an item-view, the application writer has to provide an item-factory.
19 An ItemFactory provides methods to create items and how many items there are among other things.
22 class MyFactory : public Dali::Toolkit::ItemFactory
25 virtual unsigned int GetNumberOfItems()
27 // Should return the number of items
31 virtual Actor NewItem( unsigned int itemId )
33 // We should create the actor here that represents our item based on the itemId given.
35 // Here we'll create an ImageActor which uses the the itemId to parse the image in a particular directory.
36 std::ostringstream imageName;
37 imageName << "my-image-folder/" << itemId << ".png"; // If item was 10, then this would result in my-image-folder/10.png
38 Dali::ResourceImage image = Dali::ResourceImage::New( imageName.str() );
40 // Create an Image Actor from the image and return
41 return Dali::ImageActor::New( image );
45 These overridden methods in our factory will be called by the Item View.
47 ## Creating an ItemView
50 MyFactory factory; // Should store this as a member variable
51 Dali::Toolkit::ItemView itemView = Dali::Toolkit::ItemView::New( factory ); // Pass in our factory
52 itemView.SetParentOrigin( ParentOrigin::CENTER );
53 itemView.SetAnchorPoint( AnchorPoint::CENTER );
55 // Now create a layout
56 Dali::Toolkit::ItemLayoutPtr spiralLayout = Dali::Toolkit::DefaultItemLayout::New( Dali::Toolkit::DefaultItemLayout::SPIRAL );
58 // ... and add the layout to the item view
59 itemView.AddLayout( spiralLayout );
61 // More layouts can be created and added to the item-view
63 // Activate the layout
64 itemView.ActivateLayout(
65 0, // The layout ID matches the order in which layouts are added
66 Dali::Stage::GetCurrent().GetSize(), // Use the stage's size as our item-view size
67 0 ); // We want the item-view to appear straight away
69 // And add to the stage
70 Dali::Stage::GetCurrent().Add( itemView );