[NUI] Modify CA2000 Warnings for TextVisual and VisualAnimator
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Visuals / TextVisual.cs
1 /*
2  * Copyright(c) 2019 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 namespace Tizen.NUI
19 {
20     /// <summary>
21     /// A class encapsulating the property map of the text visual.
22     /// </summary>
23     /// <since_tizen> 3 </since_tizen>
24     public class TextVisual : VisualMap
25     {
26         static private float defaultPointSize = 18;
27         private string text = null;
28         private string fontFamily = null;
29         private PropertyMap fontStyle = null;
30         private float pointSize = defaultPointSize;
31         private bool? multiLine = null;
32         private string horizontalAlignment = null;
33         private string verticalAlignment = null;
34         private Color textColor = null;
35         private bool? enableMarkup = null;
36         private PropertyMap shadow = null;
37         private PropertyMap underline = null;
38         private PropertyMap outline = null;
39         private PropertyMap background = null;
40
41         /// <summary>
42         /// Constructor.
43         /// </summary>
44         /// <since_tizen> 3 </since_tizen>
45         public TextVisual() : base()
46         {
47         }
48
49         /// <summary>
50         /// Gets or sets the text to display in the UTF-8 format.<br />
51         /// Mandatory.
52         /// </summary>
53         /// <since_tizen> 3 </since_tizen>
54         public string Text
55         {
56             get
57             {
58                 return text;
59             }
60             set
61             {
62                 text = value;
63                 UpdateVisual();
64             }
65         }
66
67         /// <summary>
68         /// Gets or sets the requested font family to use.<br />
69         /// Optional.
70         /// </summary>
71         /// <since_tizen> 3 </since_tizen>
72         public string FontFamily
73         {
74             get
75             {
76                 return fontFamily;
77             }
78             set
79             {
80                 fontFamily = value;
81                 UpdateVisual();
82             }
83         }
84
85         /// <summary>
86         /// Gets or sets the requested font style to use.<br />
87         /// Optional.
88         /// </summary>
89         /// <since_tizen> 3 </since_tizen>
90         public PropertyMap FontStyle
91         {
92             get
93             {
94                 return fontStyle;
95             }
96             set
97             {
98                 fontStyle = value;
99                 UpdateVisual();
100             }
101         }
102
103         /// <summary>
104         /// Gets or sets the size of font in points.<br />
105         /// Mandatory.
106         /// </summary>
107         /// <since_tizen> 3 </since_tizen>
108         public float PointSize
109         {
110             get
111             {
112                 return pointSize;
113             }
114             set
115             {
116                 pointSize = value;
117                 UpdateVisual();
118             }
119         }
120
121         /// <summary>
122         /// Gets or sets the single-line or multi-line layout option.<br />
123         /// If not specified, the default is false.<br />
124         /// Optional.
125         /// </summary>
126         /// <since_tizen> 3 </since_tizen>
127         public bool MultiLine
128         {
129             get
130             {
131                 return multiLine ?? (false);
132             }
133             set
134             {
135                 multiLine = value;
136                 UpdateVisual();
137             }
138         }
139
140         /// <summary>
141         /// Gets or sets the line horizontal alignment.<br />
142         /// If not specified, the default is begin.<br />
143         /// Optional.
144         /// </summary>
145         /// <since_tizen> 3 </since_tizen>
146         public HorizontalAlignment HorizontalAlignment
147         {
148             get
149             {
150                 switch (horizontalAlignment)
151                 {
152                     case "BEGIN":
153                         return HorizontalAlignment.Begin;
154                     case "CENTER":
155                         return HorizontalAlignment.Center;
156                     case "END":
157                         return HorizontalAlignment.End;
158                     default:
159                         return HorizontalAlignment.Begin;
160                 }
161             }
162             set
163             {
164                 switch (value)
165                 {
166                     case HorizontalAlignment.Begin:
167                         {
168                             horizontalAlignment = "BEGIN";
169                             break;
170                         }
171                     case HorizontalAlignment.Center:
172                         {
173                             horizontalAlignment = "CENTER";
174                             break;
175                         }
176                     case HorizontalAlignment.End:
177                         {
178                             horizontalAlignment = "END";
179                             break;
180                         }
181                     default:
182                         {
183                             horizontalAlignment = "BEGIN";
184                             break;
185                         }
186                 }
187                 UpdateVisual();
188             }
189         }
190
191         /// <summary>
192         /// Gets or sets the line vertical alignment.<br />
193         /// If not specified, the default is top.<br />
194         /// Optional.
195         /// </summary>
196         /// <since_tizen> 3 </since_tizen>
197         public VerticalAlignment VerticalAlignment
198         {
199             get
200             {
201                 switch (verticalAlignment)
202                 {
203                     case "TOP":
204                         return VerticalAlignment.Top;
205                     case "CENTER":
206                         return VerticalAlignment.Center;
207                     case "BOTTOM":
208                         return VerticalAlignment.Bottom;
209                     default:
210                         return VerticalAlignment.Top;
211                 }
212             }
213             set
214             {
215                 switch (value)
216                 {
217                     case VerticalAlignment.Top:
218                         {
219                             verticalAlignment = "TOP";
220                             break;
221                         }
222                     case VerticalAlignment.Center:
223                         {
224                             verticalAlignment = "CENTER";
225                             break;
226                         }
227                     case VerticalAlignment.Bottom:
228                         {
229                             verticalAlignment = "BOTTOM";
230                             break;
231                         }
232                     default:
233                         {
234                             verticalAlignment = "TOP";
235                             break;
236                         }
237                 }
238                 UpdateVisual();
239             }
240         }
241
242         /// <summary>
243         /// Gets or sets the color of the text.<br />
244         /// Optional.
245         /// </summary>
246         /// <since_tizen> 3 </since_tizen>
247         public Color TextColor
248         {
249             get
250             {
251                 return textColor;
252             }
253             set
254             {
255                 textColor = value;
256                 UpdateVisual();
257             }
258         }
259
260         /// <summary>
261         /// Gets or sets whether the mark-up processing is enabled.<br />
262         /// Optional.
263         /// </summary>
264         /// <since_tizen> 3 </since_tizen>
265         public bool EnableMarkup
266         {
267             get
268             {
269                 return enableMarkup ?? (false);
270             }
271             set
272             {
273                 enableMarkup = value;
274                 UpdateVisual();
275             }
276         }
277
278         /// <summary>
279         /// Gets or sets the shadow parameters.
280         /// </summary>
281         /// <since_tizen> 5 </since_tizen>
282         public PropertyMap Shadow
283         {
284             get
285             {
286                 return shadow;
287             }
288             set
289             {
290                 shadow = value;
291                 UpdateVisual();
292             }
293         }
294
295         /// <summary>
296         /// Gets or sets the underline parameters.
297         /// </summary>
298         /// <since_tizen> 5 </since_tizen>
299         public PropertyMap Underline
300         {
301             get
302             {
303                 return underline;
304             }
305             set
306             {
307                 underline = value;
308                 UpdateVisual();
309             }
310         }
311
312         /// <summary>
313         /// Gets or sets the outline parameters.
314         /// </summary>
315         /// <since_tizen> 5 </since_tizen>
316         public PropertyMap Outline
317         {
318             get
319             {
320                 return outline;
321             }
322             set
323             {
324                 outline = value;
325                 UpdateVisual();
326             }
327         }
328
329         /// <summary>
330         /// Gets or sets the background parameters.
331         /// </summary>
332         /// <since_tizen> 5 </since_tizen>
333         public PropertyMap Background
334         {
335             get
336             {
337                 return background;
338             }
339             set
340             {
341                 background = value;
342                 UpdateVisual();
343             }
344         }
345
346         /// <summary>
347         /// Compose the out visual map.
348         /// </summary>
349         /// <since_tizen> 3 </since_tizen>
350         protected override void ComposingPropertyMap()
351         {
352             _outputVisualMap = new PropertyMap();
353
354             if (text != null)
355             {
356                 PropertyValue temp = new PropertyValue((int)Visual.Type.Text);
357                 _outputVisualMap.Add(Visual.Property.Type, temp);
358                 temp.Dispose();
359
360                 temp = new PropertyValue(text);
361                 _outputVisualMap.Add(TextVisualProperty.Text, temp);
362                 temp.Dispose();
363
364                 temp = new PropertyValue((float)pointSize);
365                 _outputVisualMap.Add(TextVisualProperty.PointSize, temp);
366                 temp.Dispose();
367
368                 if (fontFamily != null)
369                 {
370                     temp = new PropertyValue(fontFamily);
371                     _outputVisualMap.Add(TextVisualProperty.FontFamily, temp);
372                     temp.Dispose();
373                 }
374                 if (fontStyle != null)
375                 {
376                     temp = new PropertyValue(fontStyle);
377                     _outputVisualMap.Add(TextVisualProperty.FontStyle, temp);
378                     temp.Dispose();
379                 }
380                 if (multiLine != null)
381                 {
382                     temp = new PropertyValue((bool)multiLine);
383                     _outputVisualMap.Add(TextVisualProperty.MultiLine, temp);
384                     temp.Dispose();
385                 }
386                 if (horizontalAlignment != null)
387                 {
388                     temp = new PropertyValue(horizontalAlignment);
389                     _outputVisualMap.Add(TextVisualProperty.HorizontalAlignment, temp);
390                     temp.Dispose();
391                 }
392                 if (verticalAlignment != null)
393                 {
394                     temp = new PropertyValue(verticalAlignment);
395                     _outputVisualMap.Add(TextVisualProperty.VerticalAlignment, temp);
396                     temp.Dispose();
397                 }
398                 if (textColor != null)
399                 {
400                     temp = new PropertyValue(textColor);
401                     _outputVisualMap.Add(TextVisualProperty.TextColor, temp);
402                     temp.Dispose();
403                 }
404                 if (enableMarkup != null)
405                 {
406                     temp = new PropertyValue((bool)enableMarkup);
407                     _outputVisualMap.Add(TextVisualProperty.EnableMarkup, temp);
408                     temp.Dispose();
409                 }
410                 if (shadow != null)
411                 {
412                     temp = new PropertyValue(shadow);
413                     _outputVisualMap.Add(TextVisualProperty.Shadow, temp);
414                     temp.Dispose();
415                 }
416                 if (underline != null)
417                 {
418                     temp = new PropertyValue(underline);
419                     _outputVisualMap.Add(TextVisualProperty.Underline, temp);
420                     temp.Dispose();
421                 }
422                 if (outline != null)
423                 {
424                     temp = new PropertyValue(outline);
425                     _outputVisualMap.Add(TextVisualProperty.Outline, temp);
426                     temp.Dispose();
427                 }
428                 if (background != null)
429                 {
430                     temp = new PropertyValue(background);
431                     _outputVisualMap.Add(TextVisualProperty.Background, temp);
432                     temp.Dispose();
433                 }
434                 base.ComposingPropertyMap();
435             }
436         }
437     }
438 }