1 #ifndef DALI_TOOLKIT_TEXT_CURSOR_HELPER_FUNCTIONS_H
2 #define DALI_TOOLKIT_TEXT_CURSOR_HELPER_FUNCTIONS_H
5 * Copyright (c) 2017 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/internal/text/logical-model-impl.h>
23 #include <dali-toolkit/internal/text/metrics.h>
24 #include <dali-toolkit/internal/text/visual-model-impl.h>
35 struct CharacterHitTest
38 * @brief Enumeration of the types of hit test.
42 TAP, ///< Retrieves the first or last character of the line if the touch point is outside of the boundaries of the text.
43 SCROLL ///< Retrieves the character above or below to the touch point if it's outside of the boundaries of the text.
54 primaryCursorHeight( 0.f ),
55 secondaryCursorHeight( 0.f ),
56 isSecondaryCursor( false )
62 Vector2 primaryPosition; ///< The primary cursor's position (in text's coords).
63 Vector2 secondaryPosition; ///< The secondary cursor's position (in text's coords).
64 float lineOffset; ///< The vertical offset where the line containing the cursor starts.
65 float lineHeight; ///< The height of the line where the cursor is placed.
66 float primaryCursorHeight; ///< The primary cursor's height.
67 float secondaryCursorHeight; ///< The secondary cursor's height.
68 bool isSecondaryCursor; ///< Whether the secondary cursor is valid.
72 * @brief Retrieves the closest line for a given touch point.
74 * It returns the first line if the touch point is above the text and the last line if the touch point is below.
76 * @param[in] visualModel The visual model.
77 * @param[in] visualY The touch point 'y' in text's coords.
78 * @param[out] matchedLine Whether the touch point actually hits a line.
80 * @return A line index.
82 LineIndex GetClosestLine( VisualModelPtr visualModel,
87 * @brief Calculates the vertical line's offset for a given line.
89 * @pre @p lineIndex must be between 0 and the number of lines (both inclusive).
91 * @param[in] lines The laid-out lines.
92 * @param[in] lineIndex Index to the line.
94 * @return The vertical offset of the given line.
96 float CalculateLineOffset( const Vector<LineRun>& lines,
97 LineIndex lineIndex );
100 * @brief Retrieves the cursor's logical position for a given touch point x,y
102 * There are two types of hit test: CharacterHitTest::TAP retrieves the first or
103 * last character of a line if the touch point is outside the boundaries of the
104 * text, CharacterHitTest::SCROLL retrieves the character above or below to the
105 * touch point if it's outside the boundaries of the text.
107 * @param[in] visualModel The visual model.
108 * @param[in] logicalModel The logical model.
109 * @param[in] metrics A wrapper around FontClient used to get metrics.
110 * @param[in] visualX The touch point 'x' in text's coords.
111 * @param[in] visualY The touch point 'y' in text's coords.
112 * @param[in] mode The type of hit test.
113 * @param[out] matchedCharacter Whether the touch point actually hits a character.
115 * @return The logical cursor position (in characters). 0 is just before the first character, a value equal to the number of characters is just after the last character.
117 CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel,
118 LogicalModelPtr logicalModel,
122 CharacterHitTest::Mode mode,
123 bool& matchedCharacter );
126 * @brief Calculates the cursor's position for a given character index in the logical order.
128 * It retrieves as well the line's height and the cursor's height and
129 * if there is a valid alternative cursor, its position and height.
131 * @param[in] visualModel The visual model.
132 * @param[in] logicalModel The logical model.
133 * @param[in] metrics A wrapper around FontClient used to get metrics.
134 * @param[in] logical The logical cursor position (in characters). 0 is just before the first character, a value equal to the number of characters is just after the last character.
135 * @param[out] cursorInfo The line's height, the cursor's height, the cursor's position and whether there is an alternative cursor.
137 void GetCursorPosition( VisualModelPtr visualModel,
138 LogicalModelPtr logicalModel,
140 CharacterIndex logical,
141 CursorInfo& cursorInfo );
144 * @brief Find the indices to the first and last characters of a word for the given touch point.
146 * @param[in] visualModel The visual model.
147 * @param[in] logicalModel The logical model.
148 * @param[in] metrics A wrapper around FontClient used to get metrics.
149 * @param[in] visualX The touch point 'x' in text's coords.
150 * @param[in] visualY The touch point 'y' in text's coords.
151 * @param[out] startIndex Index to the first character of the selected word.
152 * @param[out] endIndex Index to the last character of the selected word.
153 * @param[out] noTextHitIndex Index to the nearest character when there is no hit.
155 * @return @e true if the touch point hits a character.
157 bool FindSelectionIndices( VisualModelPtr visualModel,
158 LogicalModelPtr logicalModel,
162 CharacterIndex& startIndex,
163 CharacterIndex& endIndex,
164 CharacterIndex& noTextHitIndex );
168 } // namespace Toolkit
172 #endif // DALI_TOOLKIT_TEXT_CURSOR_HELPER_FUNCTIONS_H