[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / controller / text-controller-relayouter.h
1 #ifndef DALI_TOOLKIT_TEXT_CONTROLLER_RELAYOUTER_H
2 #define DALI_TOOLKIT_TEXT_CONTROLLER_RELAYOUTER_H
3
4 /*
5  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/actors/actor-enumerations.h>
23 #include <dali/public-api/math/vector2.h>
24 #include <dali/public-api/math/vector3.h>
25
26 // INTERNAL INCLUDES
27 #include <dali-toolkit/internal/text/controller/text-controller.h>
28
29 namespace Dali
30 {
31 namespace Toolkit
32 {
33 namespace Text
34 {
35 /**
36  * Contains all the relayouting related methods for Text::Controller
37  */
38 struct Controller::Relayouter
39 {
40   /**
41    * @brief Called by the Controller to retrieve the natural size.
42    *
43    * @param[in] controller A reference to the controller class
44    * @return
45    */
46   static Vector3 GetNaturalSize(Controller& controller);
47
48   /**
49    * @brief Called by the Controller to check if the text fits.
50    *
51    * @param[in] controller A reference to the controller class
52    * @param[in] pointSize The point size
53    * @param[in] layoutSize The layout size
54    * @return
55    */
56   static bool CheckForTextFit(Controller& controller, float pointSize, const Size& layoutSize);
57
58   /**
59    * @brief Calculates the point size for text for given layout()
60    *
61    * @param[in] controller A reference to the controller class
62    * @param[in] layoutSize The layout size
63    */
64   static void FitPointSizeforLayout(Controller& controller, const Size& layoutSize);
65
66   /**
67    * @brief Calculates the point size for text for given layout() using text fit array.
68    *
69    * @param[in] controller A reference to the controller class
70    * @param[in] layoutSize The layout size
71    */
72   static void FitArrayPointSizeforLayout(Controller& controller, const Size& layoutSize);
73
74   /**
75    * @brief Called by the Controller to get the height for a particular width.
76    *
77    * @param[in] controller A reference to the controller class
78    * @param[in] width The width we want the height for
79    * @return
80    */
81   static float GetHeightForWidth(Controller& controller, float width);
82
83   /**
84    * @brief Called by the Controller to do the relayout itself.
85    *
86    * @param[in] controller A reference to the controller class
87    * @param[in] size The size to set
88    * @param[in] layoutDirection The layout direction
89    * @return
90    */
91   static Controller::UpdateTextType Relayout(Controller& controller, const Size& size, Dali::LayoutDirection::Type layoutDirection);
92
93   /**
94    * @brief Called by the Controller to do certain operations when relayouting.
95    *
96    * @param[in] impl A reference to the controller impl class
97    * @param[in] size The size to set
98    * @param[in] operationsRequired The operations we need to do
99    * @param[in/out] layoutSize The Layout size which can be updated depending on the result of the performed operations
100    * @return whether view updated after relayout
101    */
102
103   static bool DoRelayout(Controller::Impl& impl, const Size& size, OperationsMask operationsRequired, Size& layoutSize);
104
105   /**
106    * @brief Called by the Controller to do certain operations when relayouting.
107    *
108    * @param[in] impl A reference to the controller impl class
109    * @param[in] size The size to set
110    * @param[in] operationsRequired The operations we need to do
111    * @param[in/out] layoutSize The Layout size which can be updated depending on the result of the performed operations
112    * @param[out] layoutTooSmall True if layout is too small to render one glyph, else false.
113    * @return whether view updated after relayout
114    */
115
116   static bool DoRelayout(Controller::Impl& impl, const Size& size, OperationsMask operationsRequired, Size& layoutSize, bool& layoutTooSmall);
117
118   /**
119    * @brief Called by the Controller to calculate the veritcal offset give the control size.
120    *
121    * @param[in] impl A reference to the controller impl class
122    * @param[in] controlSize The control size
123    */
124   static void CalculateVerticalOffset(Controller::Impl& impl, const Size& controlSize);
125
126   /**
127   * @brief Calculates the layout size of control according to @p requestedControllerSize and @p requestedOperationsMask
128   *
129   * GetNaturalSize() and GetHeightForWidth() calls this method.
130   *
131   * @param[in] controller The controller to calcualte size on it.
132   * @param[in] requestedControllerSize The requested size of controller to calcualte layout size on it.
133   * @param[in] requestedOperationsMask The requested operations-mask to calcualte layout size according to it.
134   *
135   * @return The calculated layout-size.
136   */
137   static Size CalculateLayoutSizeOnRequiredControllerSize(Controller& controller, const Size& requestedControllerSize, const OperationsMask& requestedOperationsMask);
138
139 private:
140   /**
141    * @brief Called by the DoRelayout to do HorizontalAlignment operation when relayouting.
142    *
143    * @param[in] impl A reference to the controller impl class
144    * @param[in] size The size to set
145    * @param[in] startIndex The start index for relayouting
146    * @param[in] requestedNumberOfCharacters The number Of characters for relayouting
147    */
148
149   static void DoRelayoutHorizontalAlignment(Controller::Impl& impl, const Size& size, const CharacterIndex startIndex, const Length requestedNumberOfCharacters);
150 };
151
152 inline bool compareByPointSize(Toolkit::DevelTextLabel::FitOption& lhs, Toolkit::DevelTextLabel::FitOption& rhs)
153 {
154   return lhs.GetPointSize() < rhs.GetPointSize();
155 }
156
157 } // namespace Text
158
159 } // namespace Toolkit
160
161 } // namespace Dali
162
163 #endif // DALI_TOOLKIT_TEXT_CONTROLLER_RELAYOUTER_H