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