[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / text / strikethrough-style-properties.h
1 #ifndef DALI_TOOLKIT_TEXT_STRIKETHROUGH_STYLE_PROPERTIES_H
2 #define DALI_TOOLKIT_TEXT_STRIKETHROUGH_STYLE_PROPERTIES_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/math/math-utils.h>
23 #include <dali/public-api/math/vector4.h>
24
25 namespace Dali
26 {
27 namespace Toolkit
28 {
29 namespace Text
30 {
31 /**
32  * @brief Properties of strikethrough style.
33  */
34 struct StrikethroughStyleProperties
35 {
36   // Constructors
37
38   /**
39    * Default constructor to set the default values of bitfields
40    */
41   StrikethroughStyleProperties()
42   : color{Color::BLACK},
43     height{0u},
44     colorDefined{false},
45     heightDefined{false}
46   {
47   }
48
49   StrikethroughStyleProperties(Vector4 color,
50                                float   height,
51                                bool    colorDefined,
52                                bool    heightDefined)
53   : color{color},
54     height{height},
55     colorDefined{colorDefined},
56     heightDefined{heightDefined}
57
58   {
59   }
60
61   // Overloading operators
62
63   bool operator==(const StrikethroughStyleProperties& other) const
64   {
65     //The property is similar when both are not defined or when both are defined and have the same value.
66     return ((!colorDefined && !other.colorDefined) || ((colorDefined && other.colorDefined) && (color == other.color))) &&
67            ((!heightDefined && !other.heightDefined) || ((heightDefined && other.heightDefined) && (Dali::Equals(height, other.height))));
68   }
69
70   bool operator!=(const StrikethroughStyleProperties& other) const
71   {
72     return !(*this == other);
73   }
74
75   bool IsHeightEqualTo(const StrikethroughStyleProperties& other) const
76   {
77     return ((!heightDefined && !other.heightDefined) || ((heightDefined && other.heightDefined) && (Dali::Equals(height, other.height))));
78   }
79
80   StrikethroughStyleProperties& CopyIfNotDefined(const StrikethroughStyleProperties& other)
81   {
82     //Copy only the defined properties in other and not defined in this from other to this
83
84     if(!heightDefined && other.heightDefined)
85     {
86       height        = other.height;
87       heightDefined = true;
88     }
89
90     if(!colorDefined && other.colorDefined)
91     {
92       color        = other.color;
93       colorDefined = true;
94     }
95
96     // to chain this method
97     return *this;
98   }
99
100   StrikethroughStyleProperties& OverrideByDefinedProperties(const StrikethroughStyleProperties& other)
101   {
102     //Copy only the defined properties in other from other to this
103
104     if(other.heightDefined)
105     {
106       height        = other.height;
107       heightDefined = true;
108     }
109
110     if(other.colorDefined)
111     {
112       color        = other.color;
113       colorDefined = true;
114     }
115
116     // to chain this method
117     return *this;
118   }
119
120   //Attributes
121   Vector4 color;  ///< The color of strikethrough.
122   float   height; ///< The height of strikethrough.
123
124   bool colorDefined : 1;  ///< Whether the color is defined.
125   bool heightDefined : 1; ///< Whether the height is defined.
126 };
127
128 } // namespace Text
129
130 } // namespace Toolkit
131
132 } // namespace Dali
133
134 #endif // DALI_TOOLKIT_TEXT_STRIKETHROUGH_STYLE_PROPERTIES_H