1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup UI_Utils 18 * @{ 19 * 20 * @brief Defines basic UI utils. 21 * 22 * @since 1.0 23 * @version 1.0 24 */ 25 26 /** 27 * @file style.h 28 * 29 * @brief Defines the attributes and common functions of style. 30 * 31 * @since 1.0 32 * @version 1.0 33 */ 34 35 #ifndef GRAPHIC_LITE_STYLE_H 36 #define GRAPHIC_LITE_STYLE_H 37 38 #include "gfx_utils/color.h" 39 40 namespace OHOS { 41 /** 42 * @brief Enumerates keys of styles. 43 * 44 * @since 1.0 45 * @version 1.0 46 */ 47 enum : uint8_t { 48 /** Background color */ 49 STYLE_BACKGROUND_COLOR, 50 /** Background opacity */ 51 STYLE_BACKGROUND_OPA, 52 /** Border radius */ 53 STYLE_BORDER_RADIUS, 54 /** Border color */ 55 STYLE_BORDER_COLOR, 56 /** Border opacity */ 57 STYLE_BORDER_OPA, 58 /** Border width */ 59 STYLE_BORDER_WIDTH, 60 /** Left padding */ 61 STYLE_PADDING_LEFT, 62 /** Right padding */ 63 STYLE_PADDING_RIGHT, 64 /** Top padding */ 65 STYLE_PADDING_TOP, 66 /** Bottom padding */ 67 STYLE_PADDING_BOTTOM, 68 /** Left margin */ 69 STYLE_MARGIN_LEFT, 70 /** Right margin */ 71 STYLE_MARGIN_RIGHT, 72 /** Top margin */ 73 STYLE_MARGIN_TOP, 74 /** Bottom margin */ 75 STYLE_MARGIN_BOTTOM, 76 /** Image opacity */ 77 STYLE_IMAGE_OPA, 78 /** Text color */ 79 STYLE_TEXT_COLOR, 80 /** Text font */ 81 STYLE_TEXT_FONT, 82 /** line space */ 83 STYLE_LINE_SPACE, 84 /** Letter spacing */ 85 STYLE_LETTER_SPACE, 86 /** Line height */ 87 STYLE_LINE_HEIGHT, 88 /** Text opacity */ 89 STYLE_TEXT_OPA, 90 /** Line color */ 91 STYLE_LINE_COLOR, 92 /** Line width */ 93 STYLE_LINE_WIDTH, 94 /** Line opacity */ 95 STYLE_LINE_OPA, 96 /** Line cap style */ 97 STYLE_LINE_CAP 98 }; 99 100 /** 101 * @brief Enumerates cap styles. 102 * 103 * @since 1.0 104 * @version 1.0 105 */ 106 enum CapType : uint8_t { 107 /** No cap style */ 108 CAP_NONE, 109 /** Round cap style */ 110 CAP_ROUND, 111 }; 112 113 /** 114 * @brief Defines the basic attributes and functions of a style. You can use this class to set different styles. 115 * 116 * @since 1.0 117 * @version 1.0 118 */ 119 class Style : public HeapBase { 120 public: 121 /** 122 * @brief A constructor used to create a <b>Style</b> instance. 123 * 124 * @since 1.0 125 * @version 1.0 126 */ 127 Style(); 128 129 /** 130 * @brief A destructor used to delete the <b>Style</b> instance. 131 * 132 * @since 1.0 133 * @version 1.0 134 */ ~Style()135 virtual ~Style() {} 136 137 /** 138 * @brief Sets a style. 139 * 140 * @param key Indicates the key of the style to set. 141 * @param value Indicates the value matching the key. 142 * @since 1.0 143 * @version 1.0 144 */ 145 void SetStyle(uint8_t key, int64_t value); 146 147 /** 148 * @brief Obtains the value of a style. 149 * 150 * @param key Indicates the key of the style. 151 * @return Returns the value of the style. 152 * @since 1.0 153 * @version 1.0 154 */ 155 int64_t GetStyle(uint8_t key) const; 156 157 /* background style */ 158 ColorType bgColor_; 159 uint8_t bgOpa_; 160 /* border style */ 161 uint8_t borderOpa_; 162 int16_t borderWidth_; 163 int16_t borderRadius_; 164 ColorType borderColor_; 165 /* padding style */ 166 uint16_t paddingLeft_; 167 uint16_t paddingRight_; 168 uint16_t paddingTop_; 169 uint16_t paddingBottom_; 170 /* margin style */ 171 int16_t marginLeft_; 172 int16_t marginRight_; 173 int16_t marginTop_; 174 int16_t marginBottom_; 175 /* image style */ 176 uint8_t imageOpa_; 177 /* text style */ 178 uint8_t textOpa_; 179 uint8_t font_; 180 int8_t lineSpace_; 181 int16_t letterSpace_; 182 int16_t lineHeight_; 183 ColorType textColor_; 184 /* line style */ 185 ColorType lineColor_; 186 uint8_t lineOpa_; 187 uint8_t lineCap_; 188 int16_t lineWidth_; 189 }; 190 191 /** 192 * @brief Define some default style for {@link UIView}. 193 * 194 * @since 1.0 195 * @version 1.0 196 */ 197 class StyleDefault : public HeapBase { 198 public: 199 /** 200 * @brief A constructor used to create a <b>StyleDefault</b> instance. 201 * 202 * @since 1.0 203 * @version 1.0 204 */ StyleDefault()205 StyleDefault(){}; 206 207 /** 208 * @brief A destructor used to delete the <b>StyleDefault</b> instance. 209 * 210 * @since 1.0 211 * @version 1.0 212 */ ~StyleDefault()213 ~StyleDefault(){}; 214 215 static void Init(); 216 217 /** 218 * @brief Obtains the default style. 219 * 220 * @return Returns the default style. 221 * @since 1.0 222 * @version 1.0 223 */ GetDefaultStyle()224 static Style& GetDefaultStyle() 225 { 226 return defaultStyle_; 227 } 228 229 /** 230 * @brief Obtains the bright style. 231 * 232 * @return Returns the bright style. 233 * @since 1.0 234 * @version 1.0 235 */ GetBrightStyle()236 static Style& GetBrightStyle() 237 { 238 return brightStyle_; 239 } 240 241 /** 242 * @brief Obtains the bright color style. 243 * 244 * @return Returns the bright color style. 245 * @since 1.0 246 * @version 1.0 247 */ GetBrightColorStyle()248 static Style& GetBrightColorStyle() 249 { 250 return brightColorStyle_; 251 } 252 253 /** 254 * @brief Obtains the button pressed style. 255 * 256 * @return Returns the button pressed style. 257 * @since 1.0 258 * @version 1.0 259 */ GetButtonPressedStyle()260 static Style& GetButtonPressedStyle() 261 { 262 return buttonPressedStyle_; 263 } 264 265 /** 266 * @brief Obtains the button released style. 267 * 268 * @return Returns the button released style. 269 * @since 1.0 270 * @version 1.0 271 */ GetButtonReleasedStyle()272 static Style& GetButtonReleasedStyle() 273 { 274 return buttonReleasedStyle_; 275 } 276 277 /** 278 * @brief Obtains the button inactive style. 279 * 280 * @return Returns the button inactive style. 281 * @since 1.0 282 * @version 1.0 283 */ GetButtonInactiveStyle()284 static Style& GetButtonInactiveStyle() 285 { 286 return buttonInactiveStyle_; 287 } 288 289 /** 290 * @brief Obtains the label style. 291 * 292 * @return Returns the label style. 293 * @since 1.0 294 * @version 1.0 295 */ GetLabelStyle()296 static Style& GetLabelStyle() 297 { 298 return labelStyle_; 299 } 300 301 /** 302 * @brief Obtains the background transparent style. 303 * 304 * @return Returns the background transparent style. 305 * @since 1.0 306 * @version 1.0 307 */ GetBackgroundTransparentStyle()308 static Style& GetBackgroundTransparentStyle() 309 { 310 return backgroundTransparentStyle_; 311 } 312 313 /** 314 * @brief Obtains the progress background style. 315 * 316 * @return Returns the progress background style. 317 * @since 1.0 318 * @version 1.0 319 */ GetProgressBackgroundStyle()320 static Style& GetProgressBackgroundStyle() 321 { 322 return progressBackgroundStyle_; 323 } 324 325 /** 326 * @brief Obtains the progress foreground style. 327 * 328 * @return Returns the progress foreground style. 329 * @since 1.0 330 * @version 1.0 331 */ GetProgressForegroundStyle()332 static Style& GetProgressForegroundStyle() 333 { 334 return progressForegroundStyle_; 335 } 336 337 /** 338 * @brief Obtains the slider knob style. 339 * 340 * @return Returns the slider knob style. 341 * @since 1.0 342 * @version 1.0 343 */ GetSliderKnobStyle()344 static Style& GetSliderKnobStyle() 345 { 346 return sliderKnobStyle_; 347 } 348 349 /** 350 * @brief Obtains the picker background style. 351 * 352 * @return Returns the picker background style. 353 * @since 1.0 354 * @version 1.0 355 */ GetPickerBackgroundStyle()356 static Style& GetPickerBackgroundStyle() 357 { 358 return pickerBackgroundStyle_; 359 } 360 361 /** 362 * @brief Obtains the picker highlight style. 363 * 364 * @return Returns the picker highlight style. 365 * @since 1.0 366 * @version 1.0 367 */ GetPickerHighlightStyle()368 static Style& GetPickerHighlightStyle() 369 { 370 return pickerHighlightStyle_; 371 } 372 373 /** 374 * @brief Obtains the scroll bar backgound style. 375 * 376 * @return Returns the scroll bar backgound style. 377 * @since 6 378 */ GetScrollBarBackgroundStyle()379 static Style& GetScrollBarBackgroundStyle() 380 { 381 return scrollBarBackgroundStyle_; 382 } 383 384 /** 385 * @brief Obtains the scroll bar foregound style. 386 * 387 * @return Returns the scroll bar foregound style. 388 * @since 6 389 */ GetScrollBarForegroundStyle()390 static Style& GetScrollBarForegroundStyle() 391 { 392 return scrollBarForegroundStyle_; 393 } 394 395 private: 396 static Style defaultStyle_; 397 static Style brightStyle_; 398 static Style brightColorStyle_; 399 400 static Style buttonPressedStyle_; 401 static Style buttonReleasedStyle_; 402 static Style buttonInactiveStyle_; 403 static Style labelStyle_; 404 static Style backgroundTransparentStyle_; 405 static Style progressBackgroundStyle_; 406 static Style progressForegroundStyle_; 407 static Style sliderKnobStyle_; 408 409 static Style pickerBackgroundStyle_; 410 static Style pickerHighlightStyle_; 411 412 static Style scrollBarBackgroundStyle_; 413 static Style scrollBarForegroundStyle_; 414 415 static void InitStyle(); 416 static void InitButtonStyle(); 417 static void InitLabelStyle(); 418 static void InitBackgroundTransparentStyle(); 419 static void InitProgressStyle(); 420 static void InitPickerStyle(); 421 static void InitScrollBarStyle(); 422 }; 423 } // namespace OHOS 424 #endif // GRAPHIC_LITE_STYLE_H