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