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/dali.h>
24 #include <dali-toolkit/public-api/controls/text-view/text-view.h>
25 #include <dali-toolkit/public-api/controls/scrollable/scroll-view/scroll-view.h>
38 class TextInputPopup : public ConnectionTracker
62 struct ButtonRequirement
64 TextInputPopup::Buttons buttonId;
65 std::size_t orderOfPriority;
72 static const char* const OPTION_SELECT_WORD;
73 static const char* const OPTION_SELECT_ALL;
74 static const char* const OPTION_CUT;
75 static const char* const OPTION_COPY;
76 static const char* const OPTION_PASTE;
77 static const char* const OPTION_CLIPBOARD;
80 static const char* const SIGNAL_PRESSED;
81 static const char* const SIGNAL_HIDE_FINISHED;
82 static const char* const SIGNAL_SHOW_FINISHED;
84 // Popup Button Pressed
85 typedef SignalV2< bool( Toolkit::Button ) > PressedSignalV2;
87 // Popup Hide Finished
88 typedef SignalV2< void( TextInputPopup& ) > HideFinishedSignalV2;
90 // Popup Show Finished
91 typedef SignalV2< void( TextInputPopup& ) > ShowFinishedSignalV2;
94 * Signal emitted when the button is touched.
96 PressedSignalV2& PressedSignal();
99 * Signal emitted when popup is completely hidden
100 * @note Only occurs after a Show() call with animation enabled.
102 HideFinishedSignalV2& HideFinishedSignal();
105 * Signal emitted when popup is completely shown
106 * @note Only occurs after a Hide() call with animation enabled.
108 ShowFinishedSignalV2& ShowFinishedSignal();
113 * Default constructor
114 * Creates an empty popup base actor (no content i.e. invisible)
119 * @return The root actor of for this popup is returned.
124 * Clears popup options (popup no longer exists)
130 * @param[in] styledCaption The text to be displayed
131 * @return the newly created label
133 Toolkit::TextView CreateOptionText( const MarkupProcessor::StyledTextArray& styledCaption );
137 * @param[in] iconImage the image to be used
138 * @return the newly created Image actor to be used as the icon
140 ImageActor CreateOptionIcon( Image iconImage );
143 * Creates and sets up the popup background
145 void CreatePopUpBackground();
148 * Create divider if multiple options
150 void CreateDivider();
153 * Create a background to be used when button pressed
154 * @param[in] requiredSize size Image actor should be
155 * @return Returns an Image Actor to be used a pressed background
157 ImageActor CreatePressedBackground( const Vector3 requiredSize );
160 * Creates a ordered vector of button options
162 void CreateOrderedListOfOptions();
165 * Adds a popup option.
166 * @note Creates popup frame if not already created.
167 * @param[in] name The unique name for this option.
168 * @param[in] caption The caption (label) for this option
169 * @param[in] iconImage Image to displayed with text.
170 * @param[in] finalOption Flag to indicate that this is the final option.
171 * (set to true on the last option you add)
173 void AddOption(const std::string& name, const std::string& caption, const Image iconImage, bool finalOption);
177 * @param[in] animate (optional) whether to animate popup to hide state over time (i.e. tween).
179 void Hide(bool animate = true);
183 * @param[in] animate (optional) whether to animate popup to show state over time (i.e. tween).
185 void Show(bool animate = true);
188 * Sets Alternative offset property.
189 * The alternative offset property is how much to move in the horizontal and vertical
190 * axes when the popup goes out of the screen on the left/right sides or top/bottom sides.
191 * @param[in] offset Vector holding the left/right offset (x) and top/bottom offset (y)
193 void SetAlternativeOffset(Vector2 offset);
196 * Returns the current state of the popup.
197 * @return The state of the popup see enum State
199 State GetState(void) const;
202 * Get the root actor which the buttons are added to.
203 * @return the root actor
205 Actor GetRootActor() const;
208 * Set the Cut and Paste buttons color when in normal state
209 * @param[in] color color to use
211 void SetCutPastePopUpColor( const Vector4& color );
214 * Get the set color of the Copy and Paste PopUp buttons
217 const Vector4& GetCutPastePopUpColor() const;
220 * Set the Cut and Paste button color when pressed.
221 * @param[in] color color to use
223 void SetCutPastePopUpPressedColor( const Vector4& color );
226 * Get the Cut and Paste pressed button color.
229 const Vector4& GetCutPastePopUpPressedColor() const;
232 * Toggle if a popup button should be enabled (shown) or not
233 * @param[in] requiredButton Button Id to enable or disable
234 * @param[in] enable toggle to enable (true) or disable (false)
236 void TogglePopUpButtonOnOff( TextInputPopup::Buttons requiredButton, bool enable );
239 * Set the Button Priority Position
240 * @param[in] button Button id for priority to be set on
241 * @param[in] priority Priority level, 1 is highest so will appear first. 0 priority will not show the button.
243 void SetButtonPriorityPosition( TextInputPopup::Buttons button, unsigned int priority );
246 * Get the Button Priority Position
247 * @param[in] button Button id to get priority of
248 * @return the button priority, 1 is highest, 0 is not shown.
250 unsigned int GetButtonPriorityPosition( TextInputPopup::Buttons button ) const;
253 * Adds Popup options which have been enabled.
255 void AddPopupOptions();
258 * Set Boundary that PopUp should stay within
259 * @param[in] boundingRectangle coordinates of bounding box from Top Left
261 void SetPopupBoundary( const Rect<float>& boundingRectangle );
264 * Sets the positon of the PopUp tail relative to TextInput
265 * @param position Position to set
267 void SetTailPosition( const Vector3& position );
272 * Creates a Button with the required parameters.
273 * @param[in] buttonId enum representing the button
274 * @param[in] orderOfPriority Position in toolbar button should be position, 1 is first from left to right.
275 * @param[in] name Given name for Button actor
276 * @param[in] caption Text to display in button
277 * @param[in] iconImage Icon to display in button
278 * @param[in] enabled Toggle if button should be used or not, this is decided by the current state/conditions.
280 TextInputPopup::ButtonRequirement CreateRequiredButton( TextInputPopup::Buttons buttonId, std::size_t orderOfPriority,
281 const std::string& name, const std::string& caption, Image iconImage, bool enabled );
284 * Adds Popup to the stage (ideally on a separate top-most layer and as an overlay)
289 * Applies constraint to keep Popup in view within the desired area.
291 void ApplyConfinementConstraint();
294 * Applies constraint to keep the Tail attached to Popup
296 void ApplyTailConstraint();
299 * Create a layer to hold the stencil
300 * @param[in] size Size to of layer
302 void CreateLayer( const Vector2& size );
305 * Create a stencil to clip the scroll view content
306 * @param[in] size Size to of stencil
308 void CreateStencil( const Vector2& size );
311 * Popup has started to scroll
312 * @param[in] position current scroll view position
314 void OnScrollStarted( const Vector3& position );
317 * Popup has stopped scrolling
318 * @param[in] position current scroll view position
320 void OnScrollCompleted( const Vector3& position );
323 * Create a scroll view to hold the popup buttons and allow scrolling if too many buttons to fit within the visible boundary
324 * @param[in] scrollViewSize size of content of the scroll view which can exceed its visible size
325 * @param[in] visibleSize size of the visible scroll view
327 void CreateScrollView( const Vector2& scrollViewSize, const Vector2& visibleSize );
330 * Removes Popup from the stage.
332 void RemoveFromStage();
335 * Called when a button is pressed in the Popup
336 * @param[in] button The button pressed.
338 bool OnButtonPressed( Toolkit::Button button );
341 * Invoked upon popup Hide animation completing.
342 * @note Only called for animating hide, not called for instantaneous (animate = false)
343 * @param[in] source The animation which completed.
345 void OnHideFinished(Animation& source);
348 * Invoked upon popup Show animation completing.
349 * @note Only called for animating show, not called for instantaneous (animate = false)
350 * @param[in] source The animation which completed.
352 void OnShowFinished(Animation& source);
356 State mState; ///< Popup State.
357 Actor mRootActor; ///< The actor which all popup content is added to (i.e. panel and buttons)
358 Property::Index mAlternativeOffsetProperty; ///< Property [Vector3] how much to offset the popup if it goes out of the screen
359 ImageActor mBackground; ///< The background popup panel
360 ImageActor mTail; ///< The tail for the popup
361 ImageActor mTailOutline; ///< The border/outline around the tail
363 float mPopupTailXPosition; ///< X position of PopUp tail.
365 Vector3 mContentSize; ///< Size of Content (i.e. Buttons)
366 ActorContainer mButtonContainer; ///< List of buttons added to popup.
367 ActorContainer mDividerContainer; ///< List of dividers added to popup.
368 Animation mAnimation; ///< Popup Hide/Show animation.
370 Actor mStencil; ///< Stencil to clip scrollview
371 Toolkit::ScrollView mScrollView; ///< Scrollview to house the popup
372 Layer mLayer; ///< Layer to house the scroll view and stencil
374 std::vector<ButtonRequirement> mOrderListOfButtons; // List of buttons in the order to be displayed and a flag to indicate if needed.
376 Vector4 mCutPasteButtonsColor; // Color of the cut and paste popup
377 Vector4 mCutPasteButtonsPressedColor; // Color of the cut and paste buttons when pressed.
378 Vector4 mBorderColor; // Color of the border around the Cut and Paste Popup
380 Rect<float> mBoundingRect; // Boundary that Popup must stay within.
382 // Priority of Options/Buttons in the Cut and Paste pop-up, higher priority buttons are displayed first, left to right.
383 std::size_t mSelectOptionPriority; // Position of Select Button
384 std::size_t mSelectAllOptionPriority; // Position of Select All button
385 std::size_t mCutOptionPriority; // Position of Cut button
386 std::size_t mCopyOptionPriority; // Position of Copy button
387 std::size_t mPasteOptionPriority; // Position of Paste button
388 std::size_t mClipboardOptionPriority; // Position of Clipboard button
390 PressedSignalV2 mPressedSignal; ///< Signal emitted when a button within the popup is pressed.
391 HideFinishedSignalV2 mHideFinishedSignal; ///< Signal emitted when popup is completely hidden
392 ShowFinishedSignalV2 mShowFinishedSignal; ///< Signal emitted when popup is completely shown
396 } // namespace Internal
398 } // namespace Toolkit
402 #endif // __DALI_TOOLKIT_INTERNAL_ITEM_VIEW_H__