1 #ifndef DALI_TOOLKIT_TEXT_FIELD_H
2 #define DALI_TOOLKIT_TEXT_FIELD_H
5 * Copyright (c) 2021 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-toolkit/public-api/controls/control.h>
28 namespace Internal DALI_INTERNAL
33 * @addtogroup dali_toolkit_controls_text_controls
38 * @brief A control which provides a single-line editable text field.
41 * | %Signal Name | Method | |
42 * |----------------------|--------------------------------|--------------------|
43 * | textChanged | @ref TextChangedSignal() | @SINCE_1_0.0 |
44 * | maxLengthReached | @ref MaxLengthReachedSignal() | @SINCE_1_0.0 |
45 * | inputStyleChanged | @ref InputStyleChangedSignal() | @SINCE_1_2_2 |
47 class DALI_TOOLKIT_API TextField : public Control
51 * @brief The start and end property ranges for this control.
56 PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0
57 PROPERTY_END_INDEX = PROPERTY_START_INDEX + 1000 ///< Reserve property indices @SINCE_1_0.0
61 * @brief Enumeration for the instance of properties belonging to the TextField class.
67 * @brief Enumeration for the instance of properties belonging to the TextField class.
73 * @brief The text to display in UTF-8 format.
74 * @details Name "text", type Property::STRING.
77 TEXT = PROPERTY_START_INDEX,
80 * @brief The text to display when the TextField is empty and inactive.
81 * @details Name "placeholderText", type Property::STRING.
87 * @brief The text to display when the TextField is empty with key-input focus.
88 * @details Name "placeholderTextFocused", type Property::STRING.
91 PLACEHOLDER_TEXT_FOCUSED,
94 * @brief The requested font family.
95 * @details Name "fontFamily", type Property::STRING.
101 * @brief The requested font style
102 * @details Name "fontStyle", type Property::STRING or Property::MAP.
108 * @brief The size of font in points.
109 * @details Name "pointSize", type Property::FLOAT.
110 * (Conversion from Pixel size to Point size : Point size = Pixel size * 72 / DPI).
116 * @brief The maximum number of characters that can be inserted.
117 * @details Name "maxLength", type Property::INTEGER.
123 * @brief Specifies how the text is truncated when it does not fit.
124 * @details Name "exceedPolicy", type Property::INTEGER.
130 * @brief The line horizontal alignment.
131 * @details Name "horizontalAlignment", type Property::STRING or type HorizontalAlignment::Type (Property::INTEGER)
132 * Values "BEGIN", "CENTER", "END".
133 * @note Return type is Property::STRING
136 HORIZONTAL_ALIGNMENT,
139 * @brief The line vertical alignment.
140 * @details Name "verticalAlignment", type Property::STRING type VerticalAlignment::Type (Property::INTEGER)
141 * Values "TOP", "CENTER", "BOTTOM".
142 * @note Return type is Property::STRING
148 * @brief The text color.
149 * @details Name "textColor", type Property::VECTOR4.
155 * @brief The placeholder-text color.
156 * @details Name "placeholderTextColor", type Property::VECTOR4.
159 PLACEHOLDER_TEXT_COLOR,
162 * @brief The color to apply to the primary cursor.
163 * @details Name "primaryCursorColor", type Property::VECTOR4.
166 PRIMARY_CURSOR_COLOR,
169 * @brief The color to apply to the secondary cursor.
170 * @details Name "secondaryCursorColor", type Property::VECTOR4.
173 SECONDARY_CURSOR_COLOR,
176 * @brief Whether the cursor should blink or not.
177 * @details Name "enableCursorBlink", type Property::BOOLEAN.
183 * @brief The time interval in seconds between cursor on/off states.
184 * @details Name "cursorBlinkInterval", type Property::FLOAT.
187 CURSOR_BLINK_INTERVAL,
190 * @brief The cursor will stop blinking after this number of seconds (if non-zero)
191 * @details Name "cursorBlinkDuration", type Property::FLOAT.
194 CURSOR_BLINK_DURATION,
197 * @brief The cursor width.
198 * @details Name "cursorWidth", type Property::INTEGER.
204 * @brief The image to display for the grab handle.
205 * @details Name "grabHandleImage", type Property::STRING.
211 * @brief The image to display when the grab handle is pressed
212 * @details Name "grabHandlePressedImage", type Property::STRING.
215 GRAB_HANDLE_PRESSED_IMAGE,
218 * @brief Horizontal scrolling will occur if the cursor is this close to the control border.
219 * @details Name "scrollThreshold", type Property::FLOAT.
225 * @brief The scroll speed in pixels per second.
226 * @details Name "scrollSpeed", type Property::FLOAT.
232 * @brief The image to display for the left selection handle.
233 * @details Name "selectionHandleImageLeft", type Property::MAP.
236 SELECTION_HANDLE_IMAGE_LEFT,
239 * @brief The image to display for the right selection handle.
240 * @details Name "selectionHandleImageRight", type Property::MAP.
243 SELECTION_HANDLE_IMAGE_RIGHT,
246 * @brief The image to display when the left selection handle is pressed.
247 * @details Name "selectionHandlePressedImageLeft", type Property::MAP.
250 SELECTION_HANDLE_PRESSED_IMAGE_LEFT,
253 * @brief The image to display when the right selection handle is pressed.
254 * @details Name "selectionHandlePressedImageRight", type Property::MAP.
257 SELECTION_HANDLE_PRESSED_IMAGE_RIGHT,
260 * @brief The image to display for the left selection handle marker.
261 * @details Name "selectionHandleMarkerImageLeft", type Property::MAP.
264 SELECTION_HANDLE_MARKER_IMAGE_LEFT,
267 * @brief The image to display for the right selection handle marker.
268 * @details Name "selectionHandleMarkerImageRight", type Property::MAP.
271 SELECTION_HANDLE_MARKER_IMAGE_RIGHT,
274 * @brief The color of the selection highlight.
275 * @details Name "selectionHighlightColor", type Property::VECTOR4.
278 SELECTION_HIGHLIGHT_COLOR,
281 * @brief The decorations (handles etc) will positioned within this area on-screen.
282 * @details Name "decorationBoundingBox", type Property::RECTANGLE.
285 DECORATION_BOUNDING_BOX,
288 * @brief The settings to relating to the System's Input Method, Key and Value.
289 * @details Name "inputMethodSettings", type Property::MAP.
291 * @note VARIATION key can be changed depending on PANEL_LAYOUT.
292 * For example, when PANEL_LAYOUT key is InputMethod::PanelLayout::NORMAL,
293 * then VARIATION would be among NORMAL, WITH_FILENAME, and WITH_PERSON_NAME in Dali::InputMethod::NormalLayout.
294 * For more information, see Dali::InputMethod::Category.
298 * Property::Map propertyMap;
299 * InputMethod::PanelLayout::Type panelLayout = InputMethod::PanelLayout::NUMBER;
300 * InputMethod::AutoCapital::Type autoCapital = InputMethod::AutoCapital::WORD;
301 * InputMethod::ButtonAction::Type buttonAction = InputMethod::ButtonAction::GO;
302 * int inputVariation = 1;
303 * propertyMap["PANEL_LAYOUT"] = panelLayout;
304 * propertyMap["AUTO_CAPITALIZE"] = autoCapital;
305 * propertyMap["BUTTON_ACTION"] = buttonAction;
306 * propertyMap["VARIATION"] = inputVariation;
308 * field.SetProperty( TextField::Property::INPUT_METHOD_SETTINGS, propertyMap );
312 INPUT_METHOD_SETTINGS,
315 * @brief The color of the new input text.
316 * @details Name "inputColor", type Property::VECTOR4.
322 * @brief Whether the mark-up processing is enabled.
323 * @details Name "enableMarkup", type Property::BOOLEAN.
329 * @brief The font's family of the new input text.
330 * @details Name "inputFontFamily", type Property::STRING.
336 * @brief The font's style of the new input text.
337 * @details Name "inputFontStyle", type Property::MAP.
343 * @brief The font's size of the new input text in points.
344 * @details Name "inputPointSize", type Property::FLOAT.
350 * @copydoc Dali::Toolkit::TextLabel::Property::UNDERLINE
355 * @brief The underline parameters of the new input text.
356 * @details Name "inputUnderline", type Property::MAP.
362 * @copydoc Dali::Toolkit::TextLabel::Property::SHADOW
367 * @brief The shadow parameters of the new input text.
368 * @details Name "inputShadow", type Property::MAP.
374 * @brief The default emboss parameters.
375 * @details Name "emboss", type Property::MAP.
381 * @brief The emboss parameters of the new input text.
382 * @details Name "inputEmboss", type Property::MAP.
388 * @copydoc Dali::Toolkit::TextLabel::Property::OUTLINE
393 * @brief The outline parameters of the new input text.
394 * @details Name "inputOutline", type Property::MAP.
400 * @brief Hides the input characters and instead shows a default character for password or pin entry.
401 * @details Name "hiddenInputSettings", type Property::MAP.
404 * @see HiddenInput::Property
406 HIDDEN_INPUT_SETTINGS,
409 * @brief The size of font in pixels.
410 * @details Name "pixelSize", type Property::FLOAT.
411 * Conversion from Point size to Pixel size:
412 * Pixel size = Point size * DPI / 72
418 * @brief Enables Text selection, such as the cursor, handle, clipboard, and highlight color.
419 * @details Name "enableSelection", type Property::BOOLEAN.
425 * @brief Sets the placeholder : text, color, font family, font style, point size, and pixel size.
426 * @details Name "placeholder", type Property::MAP.
429 * Property::Map propertyMap;
430 * propertyMap[ Text::PlaceHolder::Property::TEXT ] = "Setting Placeholder Text";
431 * propertyMap[ Text::PlaceHolder::Property::TEXT_FOCUSED] = "Setting Placeholder Text Focused";
432 * propertyMap[ Text::PlaceHolder::Property::COLOR] = Color::RED;
433 * propertyMap[ Text::PlaceHolder::Property::FONT_FAMILY ] = "Arial";
434 * propertyMap[ Text::PlaceHolder::Property::POINT_SIZE ] = 12.0f;
435 * propertyMap[ Text::PlaceHolder::Property::ELLIPSIS ] = true;
437 * Property::Map fontStyleMap;
438 * fontStyleMap.Insert( "weight", "bold" );
439 * fontStyleMap.Insert( "width", "condensed" );
440 * fontStyleMap.Insert( "slant", "italic" );
441 * propertyMap[ Text::PlaceHolder::Property::FONT_STYLE] = fontStyleMap;
443 * field.SetProperty( TextField::Property::PLACEHOLDER, propertyMap );
450 * @brief Whether we should show the ellipsis if it is required.
451 * @details Name "ellipsis", type Property::BOOLEAN.
453 * @note PLACEHOLDER map is used to add ellipsis to placeholder text.
460 * @brief Enumeration for specifying how the text is truncated when it does not fit.
462 * The default value is \e EXCEED_POLICY_CLIP.
467 EXCEED_POLICY_ORIGINAL, ///< The text will be display at original size, and may exceed the TextField boundary. @SINCE_1_0.0
468 EXCEED_POLICY_CLIP ///< The end of text will be clipped to fit within the TextField. @SINCE_1_0.0
472 * @brief Mask used by the signal InputStyleChangedSignal(). Notifies which parameters of the input style have changed.
479 * @brief Mask used by the signal InputStyleChangedSignal().
485 NONE = 0x0000, ///< @SINCE_1_2_2
486 COLOR = 0x0001, ///< @SINCE_1_2_2
487 FONT_FAMILY = 0x0002, ///< @SINCE_1_2_2
488 POINT_SIZE = 0x0004, ///< @SINCE_1_2_2
489 FONT_STYLE = 0x0008, ///< @SINCE_1_2_2
490 UNDERLINE = 0x0010, ///< @SINCE_1_2_2
491 SHADOW = 0x0020, ///< @SINCE_1_2_2
492 EMBOSS = 0x0040, ///< @SINCE_1_2_2
493 OUTLINE = 0x0080, ///< @SINCE_1_2_2
494 STRIKETHROUGH = 0x1000
501 * @brief Text changed signal type.
504 typedef Signal<void(TextField)> TextChangedSignalType;
507 * @brief Max Characters Exceed signal type.
510 typedef Signal<void(TextField)> MaxLengthReachedSignalType;
513 * @brief Input Style changed signal type.
516 typedef Signal<void(TextField, InputStyle::Mask)> InputStyleChangedSignalType;
519 * @brief Creates the TextField control.
521 * @return A handle to the TextField control
523 static TextField New();
526 * @brief Creates the TextField control with additional behaviour.
529 * @param[in] additionalBehaviour Additional control behaviour
530 * @return A handle to the TextField control
532 static TextField New(ControlBehaviour additionalBehaviour);
535 * @brief Creates an empty handle.
541 * @brief Copy constructor.
544 * @param[in] handle The handle to copy from
546 TextField(const TextField& handle);
549 * @brief Move constructor
552 * @param[in] rhs A reference to the moved handle
554 TextField(TextField&& rhs) noexcept;
557 * @brief Assignment operator.
560 * @param[in] handle The handle to copy from
561 * @return A reference to this
563 TextField& operator=(const TextField& handle);
566 * @brief Move assignment
569 * @param[in] rhs A reference to the moved handle
570 * @return A reference to this
572 TextField& operator=(TextField&& rhs) noexcept;
577 * This is non-virtual since derived Handle types must not contain data or virtual methods.
583 * @brief Downcasts a handle to TextField.
585 * If the BaseHandle points is a TextField, the downcast returns a valid handle.
586 * If not, the returned handle is left empty.
589 * @param[in] handle Handle to an object
590 * @return Handle to a TextField or an empty handle
592 static TextField DownCast(BaseHandle handle);
597 * @brief This signal is emitted when the text changes.
599 * A callback of the following type may be connected:
601 * void YourCallbackName( TextField textField );
604 * @return The signal to connect to.
606 TextChangedSignalType& TextChangedSignal();
609 * @brief This signal is emitted when inserted text exceeds the maximum character limit.
611 * A callback of the following type may be connected:
613 * void YourCallbackName( TextField textField );
616 * @return The signal to connect to
618 MaxLengthReachedSignalType& MaxLengthReachedSignal();
621 * @brief This signal is emitted when the input style is updated as a consequence of a change in the cursor position.
622 * i.e. The signal is not emitted when the input style is updated through the property system.
624 * A callback of the following type may be connected. The @p mask parameter notifies which parts of the style have changed.
626 * void YourCallbackName( TextField textField, TextField::InputStyle::Mask mask );
630 * @return The signal to connect to
632 InputStyleChangedSignalType& InputStyleChangedSignal();
634 public: // Not intended for application developers
636 * @brief Creates a handle using the Toolkit::Internal implementation.
639 * @param[in] implementation The Control implementation
641 DALI_INTERNAL TextField(Internal::TextField& implementation);
644 * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
647 * @param[in] internal A pointer to the internal CustomActor
649 explicit DALI_INTERNAL TextField(Dali::Internal::CustomActor* internal);
655 } // namespace Toolkit
659 #endif // DALI_TOOLKIT_TEXT_FIELD_H