Merge "Add Placeholder Ellipsis in TextField" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / rendering / view-model.h
1 #ifndef DALI_TOOLKIT_TEXT_VIEW_MODEL_H
2 #define DALI_TOOLKIT_TEXT_VIEW_MODEL_H
3
4 /*
5  * Copyright (c) 2017 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/common/dali-vector.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/internal/text/text-model-interface.h>
26
27 namespace Dali
28 {
29
30 namespace Toolkit
31 {
32
33 namespace Text
34 {
35
36 /**
37  * @brief Responsible of creating and store temporary modifications of the text model.
38  * i.e. The elide of text.
39  */
40 class ViewModel : public ModelInterface
41 {
42 public:
43   /**
44    * @brief Constructor.
45    *
46    * Keeps the pointer to the text's model. It initializes all the members of the class to their defaults.
47    *
48    * @param[in] model Pointer to the text's model interface.
49    */
50   ViewModel( const ModelInterface* const model );
51
52   /**
53    * @brief Virtual destructor.
54    *
55    * It's a default destructor.
56    */
57   virtual ~ViewModel();
58
59   /**
60    * @copydoc ModelInterface::GetControlSize()
61    */
62   virtual const Size& GetControlSize() const;
63
64   /**
65    * @copydoc ModelInterface::GetLayoutSize()
66    */
67   virtual const Size& GetLayoutSize() const;
68
69   /**
70    * @copydoc ModelInterface::GetScrollPosition()
71    */
72   virtual const Vector2& GetScrollPosition() const;
73
74   /**
75    * @copydoc ModelInterface::GetHorizontalAlignment()
76    */
77   virtual Layout::HorizontalAlignment GetHorizontalAlignment() const;
78
79   /**
80    * @copydoc ModelInterface::GetVerticalAlignment()
81    */
82   virtual Layout::VerticalAlignment GetVerticalAlignment() const;
83
84   /**
85    * @copydoc ModelInterface::IsTextElideEnabled()
86    */
87   virtual bool IsTextElideEnabled() const;
88
89   /**
90    * @copydoc ModelInterface::GetNumberOfLines()
91    */
92   virtual Length GetNumberOfLines() const;
93
94   /**
95    * @copydoc ModelInterface::GetLines()
96    */
97   virtual const LineRun* const GetLines() const;
98
99   /**
100    * @copydoc ModelInterface::GetNumberOfScripts()
101    */
102   virtual Length GetNumberOfScripts() const;
103
104   /**
105    * @copydoc ModelInterface::GetScriptRuns()
106    */
107   virtual const ScriptRun* const GetScriptRuns() const;
108
109   /**
110    * @copydoc ModelInterface::GetNumberOfGlyphs()
111    */
112   virtual Length GetNumberOfGlyphs() const;
113
114   /**
115    * @copydoc ModelInterface::GetGlyphs()
116    */
117   virtual const GlyphInfo* const GetGlyphs() const;
118
119   /**
120    * @copydoc ModelInterface::GetLayout()
121    */
122   virtual const Vector2* const GetLayout() const;
123
124   /**
125    * @copydoc ModelInterface::GetColors()
126    */
127   virtual const Vector4* const GetColors() const;
128
129   /**
130    * @copydoc ModelInterface::GetColorIndices()
131    */
132   virtual const ColorIndex* const GetColorIndices() const;
133
134   /**
135    * @copydoc ModelInterface::GetDefaultColor()
136    */
137   virtual const Vector4& GetDefaultColor() const;
138
139   /**
140    * @copydoc ModelInterface::GetShadowOffset()
141    */
142   virtual const Vector2& GetShadowOffset() const;
143
144   /**
145    * @copydoc ModelInterface::GetShadowColor()
146    */
147   virtual const Vector4& GetShadowColor() const;
148
149   /**
150    * @copydoc ModelInterface::GetUnderlineColor()
151    */
152   virtual const Vector4& GetUnderlineColor() const;
153
154   /**
155    * @copydoc ModelInterface::IsUnderlineEnabled()
156    */
157   virtual bool IsUnderlineEnabled() const;
158
159   /**
160    * @copydoc ModelInterface::GetUnderlineHeight()
161    */
162   virtual float GetUnderlineHeight() const;
163
164   /**
165    * @copydoc ModelInterface::GetNumberOfUnderlineRuns()
166    */
167   virtual Length GetNumberOfUnderlineRuns() const;
168
169   /**
170    * @copydoc ModelInterface::GetUnderlineRuns()
171    */
172   virtual void GetUnderlineRuns( GlyphRun* underlineRuns, UnderlineRunIndex index, Length numberOfRuns ) const;
173
174   /**
175    * @copydoc ModelInterface::GetOutlineColor()
176    */
177   virtual const Vector4& GetOutlineColor() const;
178
179   /**
180    * @copydoc ModelInterface::GetOutlineWidth()
181    */
182   virtual float GetOutlineWidth() const;
183
184  /**
185    * @brief Does the text elide.
186    *
187    * It stores a copy of the visible glyphs and removes as many glyphs as needed
188    * from the last visible line to add the ellipsis glyph.
189    *
190    * It stores as well a copy of the positions for each visible glyph.
191    */
192   void ElideGlyphs();
193
194 private:
195   const ModelInterface* const mModel;            ///< Pointer to the text's model.
196   Vector<GlyphInfo>           mElidedGlyphs;     ///< Stores the glyphs of the elided text.
197   Vector<Vector2>             mElidedLayout;     ///< Stores the positions of each glyph of the elided text.
198   bool                        mIsTextElided : 1; ///< Whether the text has been elided.
199 };
200
201 } // namespace Text
202
203 } // namespace Toolkit
204
205 } // namespace Dali
206
207 #endif // DALI_TOOLKIT_TEXT_VIEW_MODEL_H