13132535ed8adba1127e6eca38f26a3e8082f6b4
[platform/core/uifw/dali-toolkit.git] / docs / content / shared-javascript-and-cpp-documentation / item-view.md
1 <!--
2 /**-->
3
4 # Item View {#item-view}
5
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:
9
10 |GRID                    |SPIRAL                    |DEPTH                    |
11 |:----------------------:|:------------------------:|:-----------------------:|
12 |![ ](item-view/grid.png)|![ ](item-view/spiral.png)|![ ](item-view/depth.png)|
13
14 The application writer can also create their own custom layout by inheriting from Dali::Toolkit::ItemLayout.
15
16 ## Item Factory
17
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.
20
21 ~~~{.cpp}
22 class MyFactory : public Dali::Toolkit::ItemFactory
23 {
24 public:
25   virtual unsigned int GetNumberOfItems()
26   {
27     // Should return the number of items
28     return MY_ITEM_COUNT;
29   }
30
31   virtual Actor NewItem( unsigned int itemId )
32   {
33     // We should create the actor here that represents our item based on the itemId given.
34
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() );
39
40     // Create an Image Actor from the image and return
41     return Dali::ImageActor::New( image );
42   }
43 };
44 ~~~
45 These overridden methods in our factory will be called by the Item View.
46
47 ## Creating an ItemView
48
49 ~~~{.cpp}
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 );
54
55 // Now create a layout
56 Dali::Toolkit::ItemLayoutPtr spiralLayout = Dali::Toolkit::DefaultItemLayout::New( Dali::Toolkit::DefaultItemLayout::SPIRAL );
57
58 // ... and add the layout to the item view
59 itemView.AddLayout( spiralLayout );
60
61 // More layouts can be created and added to the item-view
62
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
68
69 // And add to the stage
70 Dali::Stage::GetCurrent().Add( itemView );
71 ~~~
72
73 */