1 #ifndef __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_POPUP_H__
2 #define __DALI_TOOLKIT_INTERNAL_TEXT_INPUT_POPUP_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/actors/image-actor.h>
23 #include <dali/public-api/actors/layer.h>
24 #include <dali/public-api/animation/animation.h>
27 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
28 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
41 class TextInputPopup : public ConnectionTracker
65 struct ButtonRequirement
67 TextInputPopup::Buttons buttonId;
68 std::size_t orderOfPriority;
75 static const char* const OPTION_SELECT_WORD;
76 static const char* const OPTION_SELECT_ALL;
77 static const char* const OPTION_CUT;
78 static const char* const OPTION_COPY;
79 static const char* const OPTION_PASTE;
80 static const char* const OPTION_CLIPBOARD;
82 // Popup Button Pressed
83 typedef Signal< bool( Toolkit::Button ) > PressedSignalType;
85 // Popup Hide / Show Finished
86 typedef Signal< void( TextInputPopup& ) > VisibilityChangeFinishedSignalType;
89 * Signal emitted when the button is touched.
91 PressedSignalType& PressedSignal();
94 * Signal emitted when popup is completely hidden
95 * @note Only occurs after a Show() call with animation enabled.
97 VisibilityChangeFinishedSignalType& HideFinishedSignal();
100 * Signal emitted when popup is completely shown
101 * @note Only occurs after a Hide() call with animation enabled.
103 VisibilityChangeFinishedSignalType& ShowFinishedSignal();
108 * Default constructor
109 * Creates an empty popup base actor (no content i.e. invisible)
114 * Clears popup options (popup no longer exists)
120 * @return the newly created Image actor to be used as the icon
122 ImageActor CreateOptionIcon( Image iconImage, const Vector4& color );
126 * @param[in] styledCaption The text to be displayed
127 * @return the newly created label
129 Toolkit::TextView CreateOptionCaption( const std::string& caption, const Vector4& color );
132 * Creates and sets up the background
134 void CreateBackground();
137 * Create and set up the tail
142 * Create divider if multiple options
143 * @return Return a divider image actor
145 ImageActor CreateDivider();
148 * Create a background to be used when option pressed
149 * @param[in] requiredSize size Image actor should be
150 * @return Returns an Image Actor to be used a pressed background
152 ImageActor CreatePressedBackground( const Vector2& requiredSize );
155 * Creates a ordered vector of button options
157 void CreateOrderedListOfOptions();
160 * Get the TextSize after constrained by the Popup margins.
161 * @param[in] textSize Natural size of text
162 * @return Vector2 constrained text size.
165 Vector2 GetConstrainedTextSize( const Vector2& textSize );
168 * Adds a popup option.
169 * @note Creates popup frame if not already created.
170 * @param[in] name The unique name for this option.
171 * @param[in] caption The caption (label) for this option
172 * @param[in] iconImage Image to displayed with text.
173 * @param[in] finalOption Flag to indicate that this is the final option.
174 * (set to true on the last option you add)
176 void AddOption(const std::string& name, const std::string& caption, const Image iconImage, bool finalOption);
180 * @param[in] animate (optional) whether to animate popup to hide state over time (i.e. tween).
182 void Hide(bool animate = true);
186 * @param[in] animate (optional) whether to animate popup to show state over time (i.e. tween).
187 * @param[in] target Actor to parent popup.
189 void Show( Actor target, bool animate = true );
192 * Returns the current state of the popup.
193 * @return The state of the popup see enum State
195 State GetState(void) const;
198 * Get the root actor which the buttons are added to.
199 * @return the root actor
201 Actor GetRootActor() const;
204 * Set the Cut and Paste buttons color when in normal state
205 * @param[in] color color to use
207 void SetCutPastePopupColor( const Vector4& color );
210 * Get the set color of the Copy and Paste Popup buttons
213 const Vector4& GetCutPastePopupColor() const;
216 * Set the Cut and Paste button color when pressed.
217 * @param[in] color color to use
219 void SetCutPastePopupPressedColor( const Vector4& color );
222 * Get the Cut and Paste pressed button color.
225 const Vector4& GetCutPastePopupPressedColor() const;
228 * Set the border color of the popup
229 * @param[in] color required color
231 void SetCutPastePopupBorderColor( const Vector4& color );
234 * Get the border color
235 * @return Vector4 the color of the border
237 const Vector4& GetCutPastePopupBorderColor() const;
240 * Toggle if a popup button should be enabled (shown) or not
241 * @param[in] requiredButton Button Id to enable or disable
242 * @param[in] enable toggle to enable (true) or disable (false)
244 void TogglePopupButtonOnOff( TextInputPopup::Buttons requiredButton, bool enable );
247 * Set the Button Priority Position
248 * @param[in] button Button id for priority to be set on
249 * @param[in] priority Priority level, 1 is highest so will appear first. 0 priority will not show the button.
251 void SetButtonPriorityPosition( TextInputPopup::Buttons button, unsigned int priority );
254 * Set the icon color of the popup
255 * @param[in] color required color
257 void SetCutPastePopupIconColor( const Vector4& color );
260 * Get the popup icon color
261 * @return Vector4 the color of the popup icon
263 const Vector4& GetCutPastePopupIconColor() const;
266 * Set the pressed icon color of the popup
267 * @param[in] color required color
269 void SetCutPastePopupIconPressedColor( const Vector4& color );
272 * Get the popup pressed icon color
273 * @return Vector4 the color of the popup pressed icon
275 const Vector4& GetCutPastePopupIconPressedColor();
278 * Set the text color of the popup
279 * @param[in] color required color
281 void SetCutPastePopupTextColor( const Vector4& color );
284 * Get the popup text color
285 * @return Vector4 the color of the popup text
287 const Vector4& GetCutPastePopupTextColor();
290 * Set the pressed text color of the popup
291 * @param[in] color required color
293 void SetCutPastePopupTextPressedColor( const Vector4& color );
296 * Get the popup pressed text color
297 * @return Vector4 the color of the popup pressed text
299 const Vector4& GetCutPastePopupTextPressedColor();
302 * Get the Button Priority Position
303 * @param[in] button Button id to get priority of
304 * @return the button priority, 1 is highest, 0 is not shown.
306 unsigned int GetButtonPriorityPosition( TextInputPopup::Buttons button ) const;
309 * Adds Popup options which have been enabled.
311 void AddPopupOptions();
314 * Get Visible size of the Popup, excludes content that needs scrolling
315 * @return Vector3 size of Popup
317 const Vector3& GetVisibileSize() const;
320 * Sets the positon of the PopUp tail relative to TextInput
321 * @param[in] position Position to set
322 * @param[in] yAxisFlip If tail should be flipped in y axis
324 void SetTailPosition( const Vector3& position, const bool yAxisFlip );
329 * Creates a Button with the required parameters.
330 * @param[in] buttonId enum representing the button
331 * @param[in] orderOfPriority Position in toolbar button should be position, 1 is first from left to right.
332 * @param[in] name Given name for Button actor
333 * @param[in] caption Text to display in button
334 * @param[in] iconImage Icon to display in button
335 * @param[in] enabled Toggle if button should be used or not, this is decided by the current state/conditions.
337 TextInputPopup::ButtonRequirement CreateRequiredButton( TextInputPopup::Buttons buttonId, std::size_t orderOfPriority,
338 const std::string& name, const std::string& caption, Image iconImage, bool enabled );
341 * @brief Adds popup to the given parent
342 * @paran[in] parent target to add Popup to
344 void AddToParent( Actor parent );
347 * @brief Removes Popup from Parent
349 void RemoveFromParent();
352 * Applies constraint to keep Popup in view within the desired area.
354 void ApplyConfinementConstraint();
357 * Applies constraint to keep the Tail attached to Popup
359 void ApplyTailConstraint();
362 * Create Layer to be used with stencil to allow scrolling of buttons which do not fit in visible popup
363 * @param[in] size of the layer.
365 void CreateLayer( const Vector2& size );
368 * Create a stencil to clip the scroll view content
369 * @param[in] size of the stencil.
371 void CreateStencil( const Vector2& size );
374 * Popup has started to scroll
375 * @param[in] position current scroll view position
377 void OnScrollStarted( const Vector3& position );
380 * Popup has stopped scrolling
381 * @param[in] position current scroll view position
383 void OnScrollCompleted( const Vector3& position );
386 * Create a scroll view to hold the popup buttons and allow scrolling if too many buttons to fit within the visible boundary
388 void CreateScrollView();
391 * Set the scroll view size and ruler.
392 * @param[in] visibleSize size of the visible scroll view
394 void UpdateScrollViewRulerAndSize( const Vector2& visibleSize );
397 * Called when a button is pressed in the Popup
398 * @param[in] button The button pressed.
400 bool OnButtonPressed( Toolkit::Button button );
403 * Invoked upon popup Hide animation completing.
404 * @note Only called for animating hide, not called for instantaneous (animate = false)
405 * @param[in] source The animation which completed.
407 void OnHideFinished(Animation& source);
410 * Invoked upon popup Show animation completing.
411 * @note Only called for animating show, not called for instantaneous (animate = false)
412 * @param[in] source The animation which completed.
414 void OnShowFinished(Animation& source);
418 State mState; ///< Popup State.
419 Layer mRoot; ///< The actor which all popup content is added to (i.e. panel and buttons)
420 Actor mButtons; ///< Actor which holds all the buttons, sensitivity can be set on all buttons via this actor
421 ImageActor mBackground; ///< The background popup panel
422 ImageActor mBackgroundEffect; ///< The background effect
423 ImageActor mBackgroundLine; ///< The background line
424 ImageActor mTail; ///< The tail for the popup
425 ImageActor mTailEffect; ///< the tail effect
426 ImageActor mTailLine; ///< The border/outline around the tail
428 Vector3 mVisiblePopUpSize; ///< Visible Size of Popup excluding content that needs scrolling.
429 float mPopupTailXPosition; ///< X position of PopUp tail.
431 Vector2 mContentSize; ///< Size of Content (i.e. Buttons)
432 ActorContainer mDividerContainer; ///< List of dividers added to popup.
433 Animation mAnimation; ///< Popup Hide/Show animation.
435 Layer mLayer; ///< Layer to be used with Stencil
436 Actor mStencil; ///< Stencil to clip scrollview
437 Toolkit::ScrollView mScrollView; ///< Scrollview to house the popup
439 std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
441 Vector4 mBackgroundColor; // Color of the background of the text input popup
442 Vector4 mBackgroundPressedColor; // Color of the option background.
443 Vector4 mLineColor; // Color of the line around the text input popup
444 Vector4 mIconColor; // Color of the popup icon.
445 Vector4 mIconPressedColor; // Color of the popup icon when pressed.
446 Vector4 mTextColor; // Color of the popup text.
447 Vector4 mTextPressedColor; // Color of the popup text when pressed.
449 // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
450 std::size_t mSelectOptionPriority; // Position of Select Button
451 std::size_t mSelectAllOptionPriority; // Position of Select All button
452 std::size_t mCutOptionPriority; // Position of Cut button
453 std::size_t mCopyOptionPriority; // Position of Copy button
454 std::size_t mPasteOptionPriority; // Position of Paste button
455 std::size_t mClipboardOptionPriority; // Position of Clipboard button
457 PressedSignalType mPressedSignal; ///< Signal emitted when a button within the popup is pressed.
458 VisibilityChangeFinishedSignalType mHideFinishedSignal; ///< Signal emitted when popup is completely hidden
459 VisibilityChangeFinishedSignalType mShowFinishedSignal; ///< Signal emitted when popup is completely shown
463 } // namespace Internal
465 } // namespace Toolkit
469 #endif // __DALI_TOOLKIT_INTERNAL_ITEM_VIEW_H__