scene-loader.example fixes.
[platform/core/uifw/dali-demo.git] / shared / dali-table-view.h
1 #ifndef DALI_DEMO_TABLEVIEW_H
2 #define DALI_DEMO_TABLEVIEW_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 <dali-toolkit/dali-toolkit.h>
23 #include <dali-toolkit/devel-api/controls/popup/popup.h>
24 #include <dali/dali.h>
25
26 // INTERNAL INCLUDES
27 #include "bubble-animator.h"
28 #include "example.h"
29
30 /**
31  * Dali-Demo instance
32  */
33 class DaliTableView : public Dali::ConnectionTracker
34 {
35 public:
36
37   /**
38    * Constructor
39    *
40    * @param application A reference to the application class
41    */
42   DaliTableView(Dali::Application& application);
43
44   /**
45    * Destructor
46    */
47   ~DaliTableView() = default;
48
49 public:
50   /**
51    * Adds an Example to our demo showcase
52    *
53    * @param[in] example The Example description.
54    *
55    * @note Should be called before the Application MainLoop is started.
56    */
57   void AddExample(Example example);
58
59   /**
60    * Sorts the example list alphabetically by Title if parameter is true.
61    *
62    * @param[in] sortAlphabetically If true, example list is sorted alphabetically.
63    *
64    * @note Should be called before the Application MainLoop is started.
65    * @note By default the examples are NOT sorted alphabetically by Title.
66    */
67   void SortAlphabetically(bool sortAlphabetically);
68
69 private: // Application callbacks & implementation
70   static constexpr unsigned int FOCUS_ANIMATION_ACTOR_NUMBER = 2; ///< The number of elements used to form the custom focus effect
71
72   /**
73    * Initialize application.
74    *
75    * @param[in] app Application instance
76    */
77   void Initialize(Dali::Application& app);
78
79   /**
80    * Populates the contents (ScrollView) with all the
81    * Examples that have been Added using the AddExample(...)
82    * call
83    */
84   void Populate();
85
86   /**
87    * Creates a tile for the main menu.
88    *
89    * @param[in] name The unique name for this Tile
90    * @param[in] title The text caption that appears on the Tile
91    * @param[in] parentSize Tile's parent size.
92    * @param[in] position The tiles relative position within a page
93    *
94    * @return The Actor for the created tile.
95    */
96   Dali::Actor CreateTile(const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, Dali::Vector2& position);
97
98   // Signal handlers
99
100   /**
101    * Signal emitted when any tile has been pressed
102    *
103    * @param[in] actor The Actor representing this tile.
104    * @param[in] event The Touch information.
105    *
106    * @return Consume flag
107    */
108   bool OnTilePressed(Dali::Actor actor, const Dali::TouchEvent& event);
109
110   /**
111    * Called by OnTilePressed & Accessibility to do the appropriate action.
112    *
113    * @param[in] actor The Actor representing this tile.
114    * @param[in] state The Touch state
115    *
116    * @return Consume flag
117    */
118   bool DoTilePress(Dali::Actor actor, Dali::PointState::Type state);
119
120   /**
121    * Signal emitted when any tile has been hovered
122    *
123    * @param[in] actor The Actor representing this tile.
124    * @param[in] event The HoverEvent
125    *
126    * @return Consume flag
127    */
128   bool OnTileHovered(Dali::Actor actor, const Dali::HoverEvent& event);
129
130   /**
131    * Signal emitted when the pressed animation has completed.
132    *
133    * @param[in] source The animation source.
134    */
135   void OnPressedAnimationFinished(Dali::Animation& source);
136
137   /**
138    * Signal emitted when scrolling has started.
139    *
140    * @param[in] position The current position of the scroll contents.
141    */
142   void OnScrollStart(const Dali::Vector2& position);
143
144   /**
145    * Signal emitted when scrolling has completed.
146    *
147    * @param[in] position The current position of the scroll contents.
148    */
149   void OnScrollComplete(const Dali::Vector2& position);
150
151   /**
152    * Signal emitted when any Sensitive Actor has been touched
153    * (other than those touches consumed by OnTilePressed)
154    *
155    * @param[in] actor The Actor touched.
156    * @param[in] event The Touch information.
157    *
158    * @return Consume flag
159    */
160   bool OnScrollTouched(Dali::Actor actor, const Dali::TouchEvent& event);
161
162   /**
163    * Setup the effect on the scroll view
164    */
165   void ApplyScrollViewEffect();
166
167   /**
168    * Apply the cube effect to all the page actors
169    */
170   void ApplyCubeEffectToPages();
171
172   /**
173    * Key event handler
174    */
175   void OnKeyEvent(const Dali::KeyEvent& event);
176
177   /**
178    * @brief Creates and sets up the custom effect used for the keyboard (and mouse) focus.
179    */
180   void CreateFocusEffect();
181
182   /**
183    * Callback when the keyboard focus is going to be changed.
184    *
185    * @param[in] current The current focused actor
186    * @param[in] proposed The actor proposed by the keyboard focus manager to move the focus to
187    * @param[in] direction The direction to move the focus
188    * @return The actor to move the keyboard focus to.
189    */
190   Dali::Actor OnKeyboardPreFocusChange(Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction);
191
192   /**
193    * Callback when the keyboard focused actor is activated.
194    *
195    * @param[in] activatedActor The activated actor
196    */
197   void OnFocusedActorActivated(Dali::Actor activatedActor);
198
199   /**
200    * Callback when the keyboard focus indicator is enabled.
201    *
202    * @param[in] actor The keyboard focus indicator.
203    */
204   void OnFocusIndicatorEnabled(Dali::Actor actor);
205
206   /**
207    * Callback when the keyboard focus indicator is disabled.
208    *
209    * @param[in] actor The keyboard focus indicator.
210    */
211   void OnFocusIndicatorDisabled(Dali::Actor actor);
212
213   /**
214    * Called when the logo is tapped
215    *
216    * @param[in]  actor  The tapped actor
217    * @param[in]  tap    The tap information.
218    */
219   void OnLogoTapped(Dali::Actor actor, const Dali::TapGesture& tap);
220
221 private:
222   Dali::Application&              mApplication;      ///< Application instance.
223   Dali::Actor                     mRootActor;        ///< All content (excluding background is anchored to this Actor)
224   Dali::Animation                 mPressedAnimation; ///< Button press scaling animation.
225   Dali::Toolkit::ScrollView       mScrollView;       ///< ScrollView container (for all Examples)
226   Dali::Toolkit::ScrollViewEffect mScrollViewEffect; ///< Effect to be applied to the scroll view
227   Dali::Actor                     mPressedActor;     ///< The currently pressed actor.
228   Dali::TapGestureDetector        mLogoTapDetector;  ///< To detect taps on the logo
229   Dali::Toolkit::Popup            mVersionPopup;     ///< Displays DALi library version information
230   BubbleAnimator                  mBubbleAnimator;   ///< Provides bubble animations.
231
232   /**
233    * This struct encapsulates all data relevant to each of the elements used within the custom keyboard focus effect.
234    */
235   struct FocusEffect
236   {
237     Dali::Toolkit::ImageView actor;     ///< The parent keyboard focus highlight actor
238     Dali::Animation          animation; ///< The animation for the parent keyboard focus highlight actor
239   };
240   FocusEffect mFocusEffect[FOCUS_ANIMATION_ACTOR_NUMBER]; ///< The elements used to create the custom focus effect
241
242   std::vector<Dali::Actor> mPages;                ///< List of pages.
243   ExampleList              mExampleList;          ///< List of examples.
244
245   float mPageWidth;  ///< The width of a page within the scroll-view, used to calculate the domain
246   int   mTotalPages; ///< Total pages within scrollview.
247
248   bool mScrolling : 1;              ///< Flag indicating whether view is currently being scrolled
249   bool mSortAlphabetically : 1;     ///< Sort examples alphabetically.
250 };
251
252 #endif // DALI_DEMO_TABLEVIEW_H