X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Ftext%2Fcursor-helper-functions.h;h=dc005a3626c35f690e10f63688cb6a2b50bb70a8;hp=e89c3350d13c9ddf90048740223389580ea0e20c;hb=00758f1301dd0bfbf6dc87659a6db9d0ba2c6816;hpb=1fcc4ed0e91129dff19b946257bcee49560d9748 diff --git a/dali-toolkit/internal/text/cursor-helper-functions.h b/dali-toolkit/internal/text/cursor-helper-functions.h index e89c335..dc005a3 100644 --- a/dali-toolkit/internal/text/cursor-helper-functions.h +++ b/dali-toolkit/internal/text/cursor-helper-functions.h @@ -1,8 +1,8 @@ -#ifndef __DALI_TOOLKIT_TEXT_CURSOR_HELPER_FUNCTIONS_H__ -#define __DALI_TOOLKIT_TEXT_CURSOR_HELPER_FUNCTIONS_H__ +#ifndef DALI_TOOLKIT_TEXT_CURSOR_HELPER_FUNCTIONS_H +#define DALI_TOOLKIT_TEXT_CURSOR_HELPER_FUNCTIONS_H /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,31 +25,44 @@ namespace Dali { - namespace Toolkit { - namespace Text { +struct CharacterHitTest +{ + /** + * @brief Enumeration of the types of hit test. + */ + enum Mode + { + TAP, ///< Retrieves the first or last character of the line if the touch point is outside of the boundaries of the text. + SCROLL ///< Retrieves the character above or below to the touch point if it's outside of the boundaries of the text. + }; +}; struct CursorInfo { CursorInfo() : primaryPosition(), secondaryPosition(), - lineOffset( 0.f ), - lineHeight( 0.f ), - primaryCursorHeight( 0.f ), - secondaryCursorHeight( 0.f ), - isSecondaryCursor( false ) - {} + lineOffset(0.f), + glyphOffset(0.f), + lineHeight(0.f), + primaryCursorHeight(0.f), + secondaryCursorHeight(0.f), + isSecondaryCursor(false) + { + } ~CursorInfo() - {} + { + } Vector2 primaryPosition; ///< The primary cursor's position (in text's coords). Vector2 secondaryPosition; ///< The secondary cursor's position (in text's coords). float lineOffset; ///< The vertical offset where the line containing the cursor starts. + float glyphOffset; ///< The difference of line ascender and glyph ascender. float lineHeight; ///< The height of the line where the cursor is placed. float primaryCursorHeight; ///< The primary cursor's height. float secondaryCursorHeight; ///< The secondary cursor's height. @@ -57,17 +70,31 @@ struct CursorInfo }; /** + * @brief Parameters passed to the GetCursorPosition() function. + */ +struct GetCursorPositionParameters +{ + VisualModelPtr visualModel; ///< The visual model. + LogicalModelPtr logicalModel; ///< The logical model. + MetricsPtr metrics; ///< A wrapper around FontClient used to get metrics. + CharacterIndex 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. + bool isMultiline; ///< Whether the text control is multi-line. +}; + +/** * @brief Retrieves the closest line for a given touch point. * * It returns the first line if the touch point is above the text and the last line if the touch point is below. * * @param[in] visualModel The visual model. * @param[in] visualY The touch point 'y' in text's coords. + * @param[out] matchedLine Whether the touch point actually hits a line. * * @return A line index. */ -LineIndex GetClosestLine( VisualModelPtr visualModel, - float visualY ); +LineIndex GetClosestLine(VisualModelPtr visualModel, + float visualY, + bool& matchedLine); /** * @brief Calculates the vertical line's offset for a given line. @@ -79,26 +106,34 @@ LineIndex GetClosestLine( VisualModelPtr visualModel, * * @return The vertical offset of the given line. */ -float CalculateLineOffset( const Vector& lines, - LineIndex lineIndex ); +float CalculateLineOffset(const Vector& lines, + LineIndex lineIndex); /** * @brief Retrieves the cursor's logical position for a given touch point x,y * + * There are two types of hit test: CharacterHitTest::TAP retrieves the first or + * last character of a line if the touch point is outside the boundaries of the + * text, CharacterHitTest::SCROLL retrieves the character above or below to the + * touch point if it's outside the boundaries of the text. + * * @param[in] visualModel The visual model. * @param[in] logicalModel The logical model. * @param[in] metrics A wrapper around FontClient used to get metrics. * @param[in] visualX The touch point 'x' in text's coords. * @param[in] visualY The touch point 'y' in text's coords. + * @param[in] mode The type of hit test. + * @param[out] matchedCharacter Whether the touch point actually hits a character. * * @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. */ -CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel, - LogicalModelPtr logicalModel, - MetricsPtr metrics, - float visualX, - float visualY ); - +CharacterIndex GetClosestCursorIndex(VisualModelPtr visualModel, + LogicalModelPtr logicalModel, + MetricsPtr metrics, + float visualX, + float visualY, + CharacterHitTest::Mode mode, + bool& matchedCharacter); /** * @brief Calculates the cursor's position for a given character index in the logical order. @@ -106,17 +141,11 @@ CharacterIndex GetClosestCursorIndex( VisualModelPtr visualModel, * It retrieves as well the line's height and the cursor's height and * if there is a valid alternative cursor, its position and height. * - * @param[in] visualModel The visual model. - * @param[in] logicalModel The logical model. - * @param[in] metrics A wrapper around FontClient used to get metrics. - * @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. + * @param[in] parameters Parameters used to calculate the cursor's position. * @param[out] cursorInfo The line's height, the cursor's height, the cursor's position and whether there is an alternative cursor. */ -void GetCursorPosition( VisualModelPtr visualModel, - LogicalModelPtr logicalModel, - MetricsPtr metrics, - CharacterIndex logical, - CursorInfo& cursorInfo ); +void GetCursorPosition(GetCursorPositionParameters& parameters, + CursorInfo& cursorInfo); /** * @brief Find the indices to the first and last characters of a word for the given touch point. @@ -128,14 +157,18 @@ void GetCursorPosition( VisualModelPtr visualModel, * @param[in] visualY The touch point 'y' in text's coords. * @param[out] startIndex Index to the first character of the selected word. * @param[out] endIndex Index to the last character of the selected word. + * @param[out] noTextHitIndex Index to the nearest character when there is no hit. + * + * @return @e true if the touch point hits a character. */ -void FindSelectionIndices( VisualModelPtr visualModel, - LogicalModelPtr logicalModel, - MetricsPtr metrics, - float visualX, - float visualY, - CharacterIndex& startIndex, - CharacterIndex& endIndex ); +bool FindSelectionIndices(VisualModelPtr visualModel, + LogicalModelPtr logicalModel, + MetricsPtr metrics, + float visualX, + float visualY, + CharacterIndex& startIndex, + CharacterIndex& endIndex, + CharacterIndex& noTextHitIndex); } // namespace Text @@ -143,4 +176,4 @@ void FindSelectionIndices( VisualModelPtr visualModel, } // namespace Dali -#endif // __DALI_TOOLKIT_TEXT_CURSOR_HELPER_FUNCTIONS_H__ +#endif // DALI_TOOLKIT_TEXT_CURSOR_HELPER_FUNCTIONS_H