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;
83 static const char* const SIGNAL_PRESSED;
84 static const char* const SIGNAL_HIDE_FINISHED;
85 static const char* const SIGNAL_SHOW_FINISHED;
87 // Popup Button Pressed
88 typedef Signal< bool( Toolkit::Button ) > PressedSignalType;
90 // Popup Hide Finished
91 typedef Signal< void( TextInputPopup& ) > HideFinishedSignalType;
93 // Popup Show Finished
94 typedef Signal< void( TextInputPopup& ) > ShowFinishedSignalType;
97 * Signal emitted when the button is touched.
99 PressedSignalType& PressedSignal();
102 * Signal emitted when popup is completely hidden
103 * @note Only occurs after a Show() call with animation enabled.
105 HideFinishedSignalType& HideFinishedSignal();
108 * Signal emitted when popup is completely shown
109 * @note Only occurs after a Hide() call with animation enabled.
111 ShowFinishedSignalType& ShowFinishedSignal();
116 * Default constructor
117 * Creates an empty popup base actor (no content i.e. invisible)
122 * Clears popup options (popup no longer exists)
128 * @return the newly created Image actor to be used as the icon
130 ImageActor CreateOptionIcon( Image iconImage, const Vector4& color );
134 * @param[in] styledCaption The text to be displayed
135 * @return the newly created label
137 Toolkit::TextView CreateOptionCaption( const std::string& caption, const Vector4& color );
140 * Creates and sets up the background
142 void CreateBackground();
145 * Create and set up the tail
150 * Create divider if multiple options
151 * @return Return a divider image actor
153 ImageActor CreateDivider();
156 * Create a background to be used when option pressed
157 * @param[in] requiredSize size Image actor should be
158 * @return Returns an Image Actor to be used a pressed background
160 ImageActor CreatePressedBackground( const Vector2& requiredSize );
163 * Creates a ordered vector of button options
165 void CreateOrderedListOfOptions();
168 * Get the TextSize after constrained by the Popup margins.
169 * @param[in] textSize Natural size of text
170 * @return Vector2 constrained text size.
173 Vector2 GetConstrainedTextSize( const Vector2& textSize );
176 * Adds a popup option.
177 * @note Creates popup frame if not already created.
178 * @param[in] name The unique name for this option.
179 * @param[in] caption The caption (label) for this option
180 * @param[in] iconImage Image to displayed with text.
181 * @param[in] finalOption Flag to indicate that this is the final option.
182 * (set to true on the last option you add)
184 void AddOption(const std::string& name, const std::string& caption, const Image iconImage, bool finalOption);
188 * @param[in] animate (optional) whether to animate popup to hide state over time (i.e. tween).
190 void Hide(bool animate = true);
194 * @param[in] animate (optional) whether to animate popup to show state over time (i.e. tween).
195 * @param[in] target Actor to parent popup.
197 void Show( Actor target, bool animate = true );
200 * Returns the current state of the popup.
201 * @return The state of the popup see enum State
203 State GetState(void) const;
206 * Get the root actor which the buttons are added to.
207 * @return the root actor
209 Actor GetRootActor() const;
212 * Set the Cut and Paste buttons color when in normal state
213 * @param[in] color color to use
215 void SetCutPastePopupColor( const Vector4& color );
218 * Get the set color of the Copy and Paste Popup buttons
221 const Vector4& GetCutPastePopupColor() const;
224 * Set the Cut and Paste button color when pressed.
225 * @param[in] color color to use
227 void SetCutPastePopupPressedColor( const Vector4& color );
230 * Get the Cut and Paste pressed button color.
233 const Vector4& GetCutPastePopupPressedColor() const;
236 * Set the border color of the popup
237 * @param[in] color required color
239 void SetCutPastePopupBorderColor( const Vector4& color );
242 * Get the border color
243 * @return Vector4 the color of the border
245 const Vector4& GetCutPastePopupBorderColor() const;
248 * Toggle if a popup button should be enabled (shown) or not
249 * @param[in] requiredButton Button Id to enable or disable
250 * @param[in] enable toggle to enable (true) or disable (false)
252 void TogglePopupButtonOnOff( TextInputPopup::Buttons requiredButton, bool enable );
255 * Set the Button Priority Position
256 * @param[in] button Button id for priority to be set on
257 * @param[in] priority Priority level, 1 is highest so will appear first. 0 priority will not show the button.
259 void SetButtonPriorityPosition( TextInputPopup::Buttons button, unsigned int priority );
262 * Set the icon color of the popup
263 * @param[in] color required color
265 void SetCutPastePopupIconColor( const Vector4& color );
268 * Get the popup icon color
269 * @return Vector4 the color of the popup icon
271 const Vector4& GetCutPastePopupIconColor() const;
274 * Set the pressed icon color of the popup
275 * @param[in] color required color
277 void SetCutPastePopupIconPressedColor( const Vector4& color );
280 * Get the popup pressed icon color
281 * @return Vector4 the color of the popup pressed icon
283 const Vector4& GetCutPastePopupIconPressedColor();
286 * Set the text color of the popup
287 * @param[in] color required color
289 void SetCutPastePopupTextColor( const Vector4& color );
292 * Get the popup text color
293 * @return Vector4 the color of the popup text
295 const Vector4& GetCutPastePopupTextColor();
298 * Set the pressed text color of the popup
299 * @param[in] color required color
301 void SetCutPastePopupTextPressedColor( const Vector4& color );
304 * Get the popup pressed text color
305 * @return Vector4 the color of the popup pressed text
307 const Vector4& GetCutPastePopupTextPressedColor();
310 * Get the Button Priority Position
311 * @param[in] button Button id to get priority of
312 * @return the button priority, 1 is highest, 0 is not shown.
314 unsigned int GetButtonPriorityPosition( TextInputPopup::Buttons button ) const;
317 * Adds Popup options which have been enabled.
319 void AddPopupOptions();
322 * Get Visible size of the Popup, excludes content that needs scrolling
323 * @return Vector3 size of Popup
325 const Vector3& GetVisibileSize() const;
328 * Sets the positon of the PopUp tail relative to TextInput
329 * @param[in] position Position to set
330 * @param[in] yAxisFlip If tail should be flipped in y axis
332 void SetTailPosition( const Vector3& position, const bool yAxisFlip );
337 * Creates a Button with the required parameters.
338 * @param[in] buttonId enum representing the button
339 * @param[in] orderOfPriority Position in toolbar button should be position, 1 is first from left to right.
340 * @param[in] name Given name for Button actor
341 * @param[in] caption Text to display in button
342 * @param[in] iconImage Icon to display in button
343 * @param[in] enabled Toggle if button should be used or not, this is decided by the current state/conditions.
345 TextInputPopup::ButtonRequirement CreateRequiredButton( TextInputPopup::Buttons buttonId, std::size_t orderOfPriority,
346 const std::string& name, const std::string& caption, Image iconImage, bool enabled );
349 * @brief Adds popup to the given parent
350 * @paran[in] parent target to add Popup to
352 void AddToParent( Actor parent );
355 * @brief Removes Popup from Parent
357 void RemoveFromParent();
360 * Applies constraint to keep Popup in view within the desired area.
362 void ApplyConfinementConstraint();
365 * Applies constraint to keep the Tail attached to Popup
367 void ApplyTailConstraint();
370 * Create Layer to be used with stencil to allow scrolling of buttons which do not fit in visible popup
371 * @param[in] size of the layer.
373 void CreateLayer( const Vector2& size );
376 * Create a stencil to clip the scroll view content
377 * @param[in] size of the stencil.
379 void CreateStencil( const Vector2& size );
382 * Popup has started to scroll
383 * @param[in] position current scroll view position
385 void OnScrollStarted( const Vector3& position );
388 * Popup has stopped scrolling
389 * @param[in] position current scroll view position
391 void OnScrollCompleted( const Vector3& position );
394 * Create a scroll view to hold the popup buttons and allow scrolling if too many buttons to fit within the visible boundary
396 void CreateScrollView();
399 * Set the scroll view size and ruler.
400 * @param[in] visibleSize size of the visible scroll view
402 void UpdateScrollViewRulerAndSize( const Vector2& visibleSize );
405 * Called when a button is pressed in the Popup
406 * @param[in] button The button pressed.
408 bool OnButtonPressed( Toolkit::Button button );
411 * Invoked upon popup Hide animation completing.
412 * @note Only called for animating hide, not called for instantaneous (animate = false)
413 * @param[in] source The animation which completed.
415 void OnHideFinished(Animation& source);
418 * Invoked upon popup Show animation completing.
419 * @note Only called for animating show, not called for instantaneous (animate = false)
420 * @param[in] source The animation which completed.
422 void OnShowFinished(Animation& source);
426 State mState; ///< Popup State.
427 Layer mRoot; ///< The actor which all popup content is added to (i.e. panel and buttons)
428 Actor mButtons; ///< Actor which holds all the buttons, sensitivity can be set on all buttons via this actor
429 ImageActor mBackground; ///< The background popup panel
430 ImageActor mBackgroundEffect; ///< The background effect
431 ImageActor mBackgroundLine; ///< The background line
432 ImageActor mTail; ///< The tail for the popup
433 ImageActor mTailEffect; ///< the tail effect
434 ImageActor mTailLine; ///< The border/outline around the tail
436 Vector3 mVisiblePopUpSize; ///< Visible Size of Popup excluding content that needs scrolling.
437 float mPopupTailXPosition; ///< X position of PopUp tail.
439 Vector2 mContentSize; ///< Size of Content (i.e. Buttons)
440 ActorContainer mDividerContainer; ///< List of dividers added to popup.
441 Animation mAnimation; ///< Popup Hide/Show animation.
443 Layer mLayer; ///< Layer to be used with Stencil
444 Actor mStencil; ///< Stencil to clip scrollview
445 Toolkit::ScrollView mScrollView; ///< Scrollview to house the popup
447 std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
449 Vector4 mBackgroundColor; // Color of the background of the text input popup
450 Vector4 mBackgroundPressedColor; // Color of the option background.
451 Vector4 mLineColor; // Color of the line around the text input popup
452 Vector4 mIconColor; // Color of the popup icon.
453 Vector4 mIconPressedColor; // Color of the popup icon when pressed.
454 Vector4 mTextColor; // Color of the popup text.
455 Vector4 mTextPressedColor; // Color of the popup text when pressed.
457 // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
458 std::size_t mSelectOptionPriority; // Position of Select Button
459 std::size_t mSelectAllOptionPriority; // Position of Select All button
460 std::size_t mCutOptionPriority; // Position of Cut button
461 std::size_t mCopyOptionPriority; // Position of Copy button
462 std::size_t mPasteOptionPriority; // Position of Paste button
463 std::size_t mClipboardOptionPriority; // Position of Clipboard button
465 PressedSignalType mPressedSignal; ///< Signal emitted when a button within the popup is pressed.
466 HideFinishedSignalType mHideFinishedSignal; ///< Signal emitted when popup is completely hidden
467 ShowFinishedSignalType mShowFinishedSignal; ///< Signal emitted when popup is completely shown
471 } // namespace Internal
473 } // namespace Toolkit
477 #endif // __DALI_TOOLKIT_INTERNAL_ITEM_VIEW_H__