Updated demos to use DALi clang-format
[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 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali-toolkit/devel-api/controls/popup/popup.h>
23 #include <dali/dali.h>
24
25 class Example;
26
27 typedef std::vector<Example>        ExampleList;
28 typedef ExampleList::iterator       ExampleListIter;
29 typedef ExampleList::const_iterator ExampleListConstIter;
30
31 typedef std::vector<Dali::Animation>  AnimationList;
32 typedef AnimationList::iterator       AnimationListIter;
33 typedef AnimationList::const_iterator AnimationListConstIter;
34
35 /**
36  * Example information
37  *
38  * Represents a single Example.
39  */
40 struct Example
41 {
42   // Constructors
43
44   /**
45    * @param[in] name unique name of example
46    * @param[in] title The caption for the example to appear on a tile button.
47    */
48   Example(std::string name, std::string title)
49   : name(name),
50     title(title)
51   {
52   }
53
54   Example()
55   {
56   }
57
58   // Data
59
60   std::string name;  ///< unique name of example
61   std::string title; ///< title (caption) of example to appear on tile button.
62 };
63
64 /**
65  * Dali-Demo instance
66  */
67 class DaliTableView : public Dali::ConnectionTracker
68 {
69 public:
70   DaliTableView(Dali::Application& application);
71   ~DaliTableView();
72
73 public:
74   /**
75    * Adds an Example to our demo showcase
76    *
77    * @param[in] example The Example description.
78    *
79    * @note Should be called before the Application MainLoop is started.
80    */
81   void AddExample(Example example);
82
83   /**
84    * Sorts the example list alphabetically by Title if parameter is true.
85    *
86    * @param[in] sortAlphabetically If true, example list is sorted alphabetically.
87    *
88    * @note Should be called before the Application MainLoop is started.
89    * @note By default the examples are NOT sorted alphabetically by Title.
90    */
91   void SortAlphabetically(bool sortAlphabetically);
92
93 private:                                                      // Application callbacks & implementation
94   static const unsigned int FOCUS_ANIMATION_ACTOR_NUMBER = 2; ///< The number of elements used to form the custom focus effect
95
96   /**
97    * Shape enum for create function
98    */
99   enum ShapeType
100   {
101     CIRCLE,
102     BUBBLE
103   };
104
105   /**
106    * Initialize application.
107    *
108    * @param[in] app Application instance
109    */
110   void Initialize(Dali::Application& app);
111
112   /**
113    * Populates the contents (ScrollView) with all the
114    * Examples that have been Added using the AddExample(...)
115    * call
116    */
117   void Populate();
118
119   /**
120    * Rotates RootActor orientation to that specified.
121    *
122    * @param[in] degrees The requested angle.
123    */
124   void Rotate(unsigned int degrees);
125
126   /**
127    * Creates a tile for the main menu.
128    *
129    * @param[in] name The unique name for this Tile
130    * @param[in] title The text caption that appears on the Tile
131    * @param[in] parentSize Tile's parent size.
132    * @param[in] position The tiles relative position within a page
133    *
134    * @return The Actor for the created tile.
135    */
136   Dali::Actor CreateTile(const std::string& name, const std::string& title, const Dali::Vector3& sizeMultiplier, Dali::Vector2& position);
137
138   // Signal handlers
139
140   /**
141    * Signal emitted when any tile has been pressed
142    *
143    * @param[in] actor The Actor representing this tile.
144    * @param[in] event The Touch information.
145    *
146    * @return Consume flag
147    */
148   bool OnTilePressed(Dali::Actor actor, const Dali::TouchEvent& event);
149
150   /**
151    * Called by OnTilePressed & Accessibility to do the appropriate action.
152    *
153    * @param[in] actor The Actor representing this tile.
154    * @param[in] state The Touch state
155    *
156    * @return Consume flag
157    */
158   bool DoTilePress(Dali::Actor actor, Dali::PointState::Type state);
159
160   /**
161    * Signal emitted when any tile has been hovered
162    *
163    * @param[in] actor The Actor representing this tile.
164    * @param[in] event The HoverEvent
165    *
166    * @return Consume flag
167    */
168   bool OnTileHovered(Dali::Actor actor, const Dali::HoverEvent& event);
169
170   /**
171    * Signal emitted when the pressed animation has completed.
172    *
173    * @param[in] source The animation source.
174    */
175   void OnPressedAnimationFinished(Dali::Animation& source);
176
177   /**
178    * Signal emitted when the button has been clicked
179    *
180    * @param[in] button The Button that is clicked.
181    *
182    * @return Consume flag
183    */
184   bool OnButtonClicked(Dali::Toolkit::Button& button);
185
186   /**
187    * Signal emitted when scrolling has started.
188    *
189    * @param[in] position The current position of the scroll contents.
190    */
191   void OnScrollStart(const Dali::Vector2& position);
192
193   /**
194    * Signal emitted when scrolling has completed.
195    *
196    * @param[in] position The current position of the scroll contents.
197    */
198   void OnScrollComplete(const Dali::Vector2& position);
199
200   /**
201    * Signal emitted when any Sensitive Actor has been touched
202    * (other than those touches consumed by OnTilePressed)
203    *
204    * @param[in] actor The Actor touched.
205    * @param[in] event The Touch information.
206    *
207    * @return Consume flag
208    */
209   bool OnScrollTouched(Dali::Actor actor, const Dali::TouchEvent& event);
210
211   /**
212    * Setup the effect on the scroll view
213    */
214   void ApplyScrollViewEffect();
215
216   /**
217    * Apply the cube effect to all the page actors
218    */
219   void ApplyCubeEffectToPages();
220
221   /**
222    * Setup the inner cube effect
223    */
224   void SetupInnerPageCubeEffect();
225
226   /**
227    * Apply a shader effect to a table tile
228    */
229   void ApplyEffectToTile(Dali::Actor tile);
230
231   /**
232    * Apply effect to the content of a tile
233    */
234   void ApplyEffectToTileContent(Dali::Actor tileContent);
235
236   /**
237    * Key event handler
238    */
239   void OnKeyEvent(const Dali::KeyEvent& event);
240
241   /**
242    * Create a depth field background
243    *
244    * @param[in] bubbleLayer Add the graphics to this layer
245    */
246   void SetupBackground(Dali::Actor bubbleLayer);
247
248   /**
249    * Create background actors for the given layer
250    *
251    * @param[in] layer The layer to add the actors to
252    * @param[in] count The number of actors to generate
253    */
254   void AddBackgroundActors(Dali::Actor layer, int count);
255
256   /**
257    * Timer handler for ending background animation
258    *
259    * @return Return value for timer handler
260    */
261   bool PauseBackgroundAnimation();
262
263   /**
264    * Pause all animations
265    */
266   void PauseAnimation();
267
268   /**
269    * Resume all animations
270    */
271   void PlayAnimation();
272
273   /**
274    * @brief Creates and sets up the custom effect used for the keyboard (and mouse) focus.
275    */
276   void CreateFocusEffect();
277
278   /**
279    * Callback when the keyboard focus is going to be changed.
280    *
281    * @param[in] current The current focused actor
282    * @param[in] proposed The actor proposed by the keyboard focus manager to move the focus to
283    * @param[in] direction The direction to move the focus
284    * @return The actor to move the keyboard focus to.
285    */
286   Dali::Actor OnKeyboardPreFocusChange(Dali::Actor current, Dali::Actor proposed, Dali::Toolkit::Control::KeyboardFocus::Direction direction);
287
288   /**
289    * Callback when the keyboard focused actor is activated.
290    *
291    * @param[in] activatedActor The activated actor
292    */
293   void OnFocusedActorActivated(Dali::Actor activatedActor);
294
295   /**
296    * Callback when the keyboard focus indicator is enabled.
297    *
298    * @param[in] actor The keyboard focus indicator.
299    */
300   void OnFocusIndicatorEnabled(Dali::Actor actor);
301
302   /**
303    * Callback when the keyboard focus indicator is disabled.
304    *
305    * @param[in] actor The keyboard focus indicator.
306    */
307   void OnFocusIndicatorDisabled(Dali::Actor actor);
308
309   /**
310    * Called when the logo is tapped
311    *
312    * @param[in]  actor  The tapped actor
313    * @param[in]  tap    The tap information.
314    */
315   void OnLogoTapped(Dali::Actor actor, const Dali::TapGesture& tap);
316
317   /**
318    * Hides the popup
319    */
320   void HideVersionPopup();
321
322   /*
323   * @brief Callback called when the buttons page actor is relaid out
324   *
325   * @param[in] actor The page actor
326   */
327   void OnButtonsPageRelayout(const Dali::Actor& actor);
328
329   /**
330   * @brief The is connected to the keyboard focus highlight actor, and called when it is placed on the scene.
331   * @param[in] actor The actor that has been placed on the scene.
332   */
333   void OnSceneConnect(Dali::Actor actor);
334
335   /**
336   * @brief Callback called to set up background actors
337   *
338   * @param[in] actor The actor raising the callback
339   */
340   void InitialiseBackgroundActors(Dali::Actor actor);
341
342 private:
343   Dali::Application&              mApplication;      ///< Application instance.
344   Dali::Toolkit::Control          mRootActor;        ///< All content (excluding background is anchored to this Actor)
345   Dali::Animation                 mRotateAnimation;  ///< Animation to rotate and resize mRootActor.
346   Dali::Animation                 mPressedAnimation; ///< Button press scaling animation.
347   Dali::Toolkit::ScrollView       mScrollView;       ///< ScrollView container (for all Examples)
348   Dali::Toolkit::ScrollViewEffect mScrollViewEffect; ///< Effect to be applied to the scroll view
349   Dali::Toolkit::RulerPtr         mScrollRulerX;     ///< ScrollView X (horizontal) ruler
350   Dali::Toolkit::RulerPtr         mScrollRulerY;     ///< ScrollView Y (vertical) ruler
351   Dali::Actor                     mPressedActor;     ///< The currently pressed actor.
352   Dali::Timer                     mAnimationTimer;   ///< Timer used to turn off animation after a specific time period
353   Dali::TapGestureDetector        mLogoTapDetector;  ///< To detect taps on the logo
354   Dali::Toolkit::Popup            mVersionPopup;     ///< Displays DALi library version information
355
356   /**
357    * This struct encapsulates all data relevant to each of the elements used within the custom keyboard focus effect.
358    */
359   struct FocusEffect
360   {
361     Dali::Toolkit::ImageView actor;     ///< The parent keyboard focus highlight actor
362     Dali::Animation          animation; ///< The animation for the parent keyboard focus highlight actor
363   };
364   FocusEffect mFocusEffect[FOCUS_ANIMATION_ACTOR_NUMBER]; ///< The elements used to create the custom focus effect
365
366   std::vector<Dali::Actor> mPages;                ///< List of pages.
367   AnimationList            mBackgroundAnimations; ///< List of background bubble animations
368   ExampleList              mExampleList;          ///< List of examples.
369
370   float mPageWidth;  ///< The width of a page within the scroll-view, used to calculate the domain
371   int   mTotalPages; ///< Total pages within scrollview.
372
373   bool mScrolling : 1;              ///< Flag indicating whether view is currently being scrolled
374   bool mSortAlphabetically : 1;     ///< Sort examples alphabetically.
375   bool mBackgroundAnimsPlaying : 1; ///< Are background animations playing
376 };
377
378 #endif // DALI_DEMO_TABLEVIEW_H