Markup procesor - Font.
[platform/core/uifw/dali-toolkit.git] / docs / content / shared-javascript-and-cpp-documentation / text-field.md
1 <!--
2 /**-->
3
4 # Text Field {#text-field}
5
6 ## Overview
7
8 The Dali::Toolkit::TextField is a control which provides a single-line editable text field.
9
10 ### Basic usage
11
12 Before any text has been entered, the TextField can display some placeholder text.
13 An alternative placeholder can be displayed when the TextField has keyboard focus.
14 For example a TextField used to enter a username could initially show "Unknown Name", and then show "Enter Name." when the cursor is shown.
15
16 ~~~{.cpp}
17 // C++
18
19 TextField field = TextField::New();
20 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT, "Unnamed Name" );
21 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_FOCUSED, "Enter Name." );
22
23 Stage::GetCurrent().Add( field );
24 ~~~
25
26 ~~~{.js}
27 // JavaScript
28
29 var field = new dali.TextField();
30 field.placeholderText = "Unnamed Name";
31 field.placeholderTextFocused = "Enter Name.";
32
33 dali.stage.add( field );
34 ~~~
35
36 When the TextField is tapped, it will automatically gain the keyboard focus. Key events will then result in text being inserted, and the placeholder text will be removed.
37 After text has been entered, it can be retrieved from the TEXT property.
38
39 ~~~{.cpp}
40 // C++
41
42 Property::Value fieldText = field.GetProperty( TextField::Property::TEXT );
43 std::cout << "Received text: " << fieldText.Get< std::string >() << std::endl;
44 ~~~
45
46 ~~~{.js}
47 // JavaScript
48
49 console.log( field.text );
50 ~~~
51
52 ### Font Selection
53
54 By default TextField will automatically select a suitable font from the platform. However, a different font could be selected. See the [Font Selection](@ref font-selection) section for more details.
55
56 ### Mark-up Style
57
58 Mark-up tags can be used to change the style of the text. See the [Mark-up Style](@ref markup-style) section for more details.
59
60 ### Input Style
61
62 The input style can be changed through the control properties. All subsequent characters added will be rendered with the new input style.
63
64 Note the input style may change if the cursor is updated by tapping in a new position.
65
66 Current supported input style properties are:
67
68 - *INPUT_COLOR* Sets the input color. The property expects a Vector4 with the red, green, blue and alpha values clamped between 0 and 1.
69 - *INPUT_FONT_FAMILY* Sets the input font's family name. The property expects the name of the font. If the new text is not supported by the given font a suitable one will be set.
70 - *INPUT_FONT_STYLE* Sets the input font's style. The property expects a json formatted string with the font's style. See the [Font Selection](@ref font-selection) section for more details.
71 - *INPUT_POINT_SIZE* Sets the input font's size. The property expects a float with the font's size in points. See the [Font Selection](@ref font-selection) section for more details.
72
73 ### Text Alignment
74
75 TextField displays a single-line of text, which will scroll if there is not enough room for the text displayed.
76 If there is enough room, then the text can be aligned horizontally to the beginning, end, or center of the available area:
77
78 ~~~{.cpp}
79 // C++
80
81 field.SetProperty( TextField::Property::HORIZONTAL_ALIGNMENT, "BEGIN" ); // "CENTER" or "END"
82 ~~~
83
84 ~~~{.js}
85 // JavaScript
86
87 field.HorizontalAlignment = "BEGIN"; // "CENTER" or "END"
88 ~~~
89
90 ### Copy and Paste  (Selection)
91
92 Text can be selected by a long press or double tapping it.   Depending on certain conditions a popup could be shown giving options including [CUT][COPY][PASTE], [SELECT ALL] or [CLIPBOARD]. Below these conditions will be explained.
93
94 [CUT] or [COPY] send the selected text to the clipboard ready to be pasted directly or via the clipboard UI.   Pressing [PASTE] will paste the top item from the clipboard (what has just been copied, possibly from another application).  If the system supports a clipboard UI this can be displayed by pressing the [CLIPBOARD] button.
95
96 Empty text means the user has not inputted any text, a TextField containing special characters or purely whitespace is not empty.
97
98 Below shows how the popup will look depending on the state of the TextField
99
100 |  |  |
101 |--|--|
102 | Condition: Long press/double tap when empty text but clipboard has content  |  Condition: Long press/double tap when TextField contains text |
103 |[PASTE][CLIPBOARD] buttons shown| [CUT][COPY], [SELECT ALL] unless all text selected and [PASTE][CLIPBOARD] if content to paste. |
104 |    ![ ](../assets/img/text-controls/EmptyTextClipboardHasContent.png) ![ ](./EmptyTextClipboardHasContent.png) |   ![ ](../assets/img/text-controls/SelectingText.png) ![ ](./SelectingText.png) |
105 | Condition: Long press/double tap popup when TextField contains just whitespace | Condition: Empty text & clipboard empty |
106 | Whitespace treated as regular text, [CUT][COPY] shown and [PASTE][CLIPBOARD] if content to paste. As all text is selected there is no need for [SELECT ALL] |  No popup shown after longpress/double tap|
107 |  ![ ](../assets/img/text-controls/SelectAllWhitespace.png) ![ ](./SelectAllWhitespace.png) | ![ ](../assets/img/text-controls/EmptyTextAndNoContentToPaste.png) ![ ](./EmptyTextAndNoContentToPaste.png)|
108 | Condition: Longpress/(double tap) on whitespace which is following text | Condition: Tapping text or panning grab handle |
109 | [PASTE][CLIPBOARD] shown if something to paste. [SELECT ALL] as more text to select | If content in clipboard [PASTE][CLIPBOARD] popup will be shown. |
110 | ![ ](../assets/img/text-controls/SelectWhitespaceAfterText.png) ![ ](./SelectWhitespaceAfterText.png) | ![ ](../assets/img/text-controls/TapAfterCopyingText.png) ![ ](./TapAfterCopyingText.png) |
111
112 ### TextField Decorations
113
114 #### Color
115
116 To change the color of the text, the recommended way is to use the TEXT_COLOR property.
117 An alternative color can be used for placeholder text by setting PLACEHOLDER_TEXT_COLOR.
118 Note that unlike the Actor::COLOR property, these properties will not affect child Actors added to the TextField.
119
120 ~~~{.cpp}
121 // C++
122 field.SetProperty( TextField::Property::TEXT_COLOR, Color::CYAN );
123 field.SetProperty( TextField::Property::PLACEHOLDER_TEXT_COLOR, Color::BLACK );
124 ~~~
125
126 ~~~{.js}
127 // JavaScript
128
129 field.textColor = dali.COLOR_CYAN;
130 field.placeholderTextColor = dali.COLOR_BLACK;
131 ~~~
132
133 ### Text Field Properties
134
135  Name (JavaScript)                 |  Name (C++)                          |  Type        | Writable     | Animatable
136 -----------------------------------|--------------------------------------|--------------|--------------|-----------
137  renderingBackend                  | RENDERING_BACKEND                    |  INTEGER     | O            | X
138  text                              | TEXT                                 |  STRING      | O            | X
139  placeholderText                   | PLACEHOLDER_TEXT                     |  STRING      | O            | X
140  placeholderTextFocused            | PLACEHOLDER_TEXT_FOCUSED             |  STRING      | O            | X
141  fontFamily                        | FONT_FAMILY                          |  STRING      | O            | X
142  fontStyle                         | FONT_STYLE                           |  STRING      | O            | X
143  pointSize                         | POINT_SIZE                           |  FLOAT       | O            | X
144  maxLength                         | MAX_LENGTH                           |  INTEGER     | O            | X
145  exceedPolicy                      | EXCEED_POLICY                        |  INTEGER     | O            | X
146  horizontalAlignment               | HORIZONTAL_ALIGNMENT                 |  STRING      | O            | X
147  verticalAlignment                 | VERTICAL_ALIGNMENT                   |  STRING      | O            | X
148  textColor                         | TEXT_COLOR                           |  VECTOR4     | O            | X
149  placeholderTextColor              | PLACEHOLDER_TEXT_COLOR               |  VECTOR4     | O            | X
150  shadowOffset                      | SHADOW_OFFSET                        |  VECTOR2     | O            | X
151  shadowColor                       | SHADOW_COLOR                         |  VECTOR4     | O            | X
152  primaryCursorColor                | PRIMARY_CURSOR_COLOR                 |  VECTOR4     | O            | X
153  secondaryCursorColor              | SECONDARY_CURSOR_COLOR               |  VECTOR4     | O            | X
154  enableCursorBlink                 | ENABLE_CURSOR_BLINK                  |  BOOLEAN     | O            | X
155  cursorBlinkInterval               | CURSOR_BLINK_INTERVAL                |  FLOAT       | O            | X
156  cursorBlinkDuration               | CURSOR_BLINK_DURATION                |  FLOAT       | O            | X
157  cursorWidth                       | CURSOR_WIDTH                         |  INTEGER     | O            | X
158  grabHandleImage                   | GRAB_HANDLE_IMAGE                    |  STRING      | O            | X
159  grabHandlePressedImage            | GRAB_HANDLE_PRESSED_IMAGE            |  STRING      | O            | X
160  scrollThreshold                   | SCROLL_THRESHOLD                     |  FLOAT       | O            | X
161  scrollSpeed                       | SCROLL_SPEED                         |  FLOAT       | O            | X
162  selectionHandleImageLeft          | SELECTION_HANDLE_IMAGE_LEFT          |  STRING      | O            | X
163  selectionHandleImageRight         | SELECTION_HANDLE_IMAGE_RIGHT         |  STRING      | O            | X
164  selectionHandlePressedImageLeft   | SELECTION_HANDLE_PRESSED_IMAGE_LEFT  |  STRING      | O            | X
165  selectionHandlePressedImageRight  | SELECTION_HANDLE_PRESSED_IMAGE_RIGHT |  STRING      | O            | X
166  selectionHandleMarkerImageLeft    | SELECTION_HANDLE_MARKER_IMAGE_LEFT   |  MAP         | O            | X
167  selectionHandleMarkerImageRight   | SELECTION_HANDLE_MARKER_IMAGE_RIGHT  |  MAP         | O            | X
168  selectionHighlightColor           | SELECTION_HIGHLIGHT_COLOR            |  VECTOR4     | O            | X
169  decorationBoundingBox             | DECORATION_BOUNDING_BOX              |  RECTANGLE   | O            | X
170  inputMethodSettings               | INPUT_METHOD_SETTINGS                |  MAP         | O            | X
171  inputColor                        | INPUT_COLOR                          |  VECTOR4     | O            | X
172  enableMarkup                      | ENABLE_MARKUP                        |  BOOLEAN     | O            | X
173  inputFontFamily                   | INPUT_FONT_FAMILY                    |  STRING      | O            | X
174  inputFontStyle                    | INPUT_FONT_STYLE                     |  STRING      | O            | X
175  inputPointSize                    | INPUT_POINT_SIZE                     |  FLOAT       | O            | X
176
177 @class TextField
178
179 */