06a85124f6c3d248a5022a6f31f27626404ffe70
[platform/core/uifw/dali-demo.git] / examples / contact-cards / contact-card-layouter.h
1 #ifndef CONTACT_CARD_LAYOUTER_H
2 #define CONTACT_CARD_LAYOUTER_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <vector>
23 #include <string>
24 #include <dali/public-api/adaptor-framework/window.h>
25 #include <dali/public-api/common/intrusive-ptr.h>
26 #include <dali/public-api/math/vector2.h>
27
28 // INTERNAL INCLUDES
29 #include "contact-card-layout-info.h"
30
31 class ContactCard;
32
33 /**
34  * @brief This class lays out contact cards on the screen appropriately.
35  *
36  * The contact cards are added to the passed in window directly and it uses the window size to figure out exactly how to layout them.
37  * It supports a minimum of 3 items on each row or column.
38  *
39  * Relayouting is not supported.
40  */
41 class ContactCardLayouter
42 {
43 public:
44
45   /**
46    * @brief Constructor.
47    */
48   ContactCardLayouter();
49
50   /**
51    * @brief Destructor.
52    */
53   ~ContactCardLayouter();
54
55   /**
56    * @brief Creates a contact card with the given information.
57    * @param[in]  window          The window to add the contact to.
58    * @param[in]  contactName     The name of the contact to display.
59    * @param[in]  contactAddress  The address of the contact to display.
60    * @param[in]  imagePath       The path to the image to display.
61    */
62   void AddContact( Dali::Window window, const std::string& contactName, const std::string& contactAddress, const std::string& imagePath );
63
64 private:
65
66   /**
67    * @brief Calculates the next position of the contact card that's about to be added to our container.
68    * @return A reference to the next position.
69    */
70   const Dali::Vector2& NextCardPosition();
71
72   ContactCardLayoutInfo mContactCardLayoutInfo; ///< The common layouting information used by all contact cards. Set up when AddContact is first called.
73
74   typedef Dali::IntrusivePtr< ContactCard > ContactCardPtr; ///< Better than raw pointers as these are ref counted and the memory is released when the count reduces to 0.
75   typedef std::vector< ContactCardPtr > ContactCardContainer;
76   ContactCardContainer mContactCards; ///< Contains all the contact cards.
77
78   Dali::Vector2 mLastPosition; ///< The last position a contact card was added.
79   Dali::Vector2 mPositionIncrementer; ///< Calculated once when AddContact is first called.
80   size_t mItemsPerRow; ///< Calculated once when AddContact is first called and stores the number of items we have in a row.
81
82   bool mInitialized; ///< Whether initialization has taken place or not.
83 };
84
85
86
87 #endif // CONTACT_CARD_LAYOUTER_H