1 /* 2 * Copyright (c) 2020-2022 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 CAP_ROUND_UNSHOW, 112 }; 113 114 /** 115 * @brief Defines the basic attributes and functions of a style. You can use this class to set different styles. 116 * 117 * @since 1.0 118 * @version 1.0 119 */ 120 class Style : public HeapBase { 121 public: 122 /** 123 * @brief A constructor used to create a <b>Style</b> instance. 124 * 125 * @since 1.0 126 * @version 1.0 127 */ 128 Style(); 129 130 /** 131 * @brief A destructor used to delete the <b>Style</b> instance. 132 * 133 * @since 1.0 134 * @version 1.0 135 */ ~Style()136 virtual ~Style() {} 137 138 /** 139 * @brief Sets a style. 140 * 141 * @param key Indicates the key of the style to set. 142 * @param value Indicates the value matching the key. 143 * @since 1.0 144 * @version 1.0 145 */ 146 void SetStyle(uint8_t key, int64_t value); 147 148 /** 149 * @brief Obtains the value of a style. 150 * 151 * @param key Indicates the key of the style. 152 * @return Returns the value of the style. 153 * @since 1.0 154 * @version 1.0 155 */ 156 int64_t GetStyle(uint8_t key) const; 157 158 /* background style */ 159 ColorType bgColor_; 160 uint8_t bgOpa_; 161 /* border style */ 162 uint8_t borderOpa_; 163 int16_t borderWidth_; 164 int16_t borderRadius_; 165 ColorType borderColor_; 166 /* padding style */ 167 uint16_t paddingLeft_; 168 uint16_t paddingRight_; 169 uint16_t paddingTop_; 170 uint16_t paddingBottom_; 171 /* margin style */ 172 int16_t marginLeft_; 173 int16_t marginRight_; 174 int16_t marginTop_; 175 int16_t marginBottom_; 176 /* image style */ 177 uint8_t imageOpa_; 178 /* 179 * text style 180 * style.lineSpace_ can be negative, and shall not be enabled with only one line. 181 */ 182 uint8_t textOpa_; 183 uint16_t font_; 184 int8_t lineSpace_; 185 int16_t letterSpace_; 186 int16_t lineHeight_; 187 ColorType textColor_; 188 /* line style */ 189 ColorType lineColor_; 190 uint8_t lineOpa_; 191 uint8_t lineCap_; 192 int16_t lineWidth_; 193 }; 194 195 /** 196 * @brief Define some default style for {@link UIView}. 197 * 198 * @since 1.0 199 * @version 1.0 200 */ 201 class StyleDefault : public HeapBase { 202 public: 203 /** 204 * @brief A constructor used to create a <b>StyleDefault</b> instance. 205 * 206 * @since 1.0 207 * @version 1.0 208 */ StyleDefault()209 StyleDefault() {} 210 211 /** 212 * @brief A destructor used to delete the <b>StyleDefault</b> instance. 213 * 214 * @since 1.0 215 * @version 1.0 216 */ ~StyleDefault()217 ~StyleDefault() {} 218 219 static void Init(); 220 221 /** 222 * @brief Obtains the default style. 223 * 224 * @return Returns the default style. 225 * @since 1.0 226 * @version 1.0 227 */ GetDefaultStyle()228 static Style& GetDefaultStyle() 229 { 230 return defaultStyle_; 231 } 232 233 /** 234 * @brief Obtains the bright style. 235 * 236 * @return Returns the bright style. 237 * @since 1.0 238 * @version 1.0 239 */ GetBrightStyle()240 static Style& GetBrightStyle() 241 { 242 return brightStyle_; 243 } 244 245 /** 246 * @brief Obtains the bright color style. 247 * 248 * @return Returns the bright color style. 249 * @since 1.0 250 * @version 1.0 251 */ GetBrightColorStyle()252 static Style& GetBrightColorStyle() 253 { 254 return brightColorStyle_; 255 } 256 257 /** 258 * @brief Obtains the button pressed style. 259 * 260 * @return Returns the button pressed style. 261 * @since 1.0 262 * @version 1.0 263 */ GetButtonPressedStyle()264 static Style& GetButtonPressedStyle() 265 { 266 return buttonPressedStyle_; 267 } 268 269 /** 270 * @brief Obtains the button released style. 271 * 272 * @return Returns the button released style. 273 * @since 1.0 274 * @version 1.0 275 */ GetButtonReleasedStyle()276 static Style& GetButtonReleasedStyle() 277 { 278 return buttonReleasedStyle_; 279 } 280 281 /** 282 * @brief Obtains the button inactive style. 283 * 284 * @return Returns the button inactive style. 285 * @since 1.0 286 * @version 1.0 287 */ GetButtonInactiveStyle()288 static Style& GetButtonInactiveStyle() 289 { 290 return buttonInactiveStyle_; 291 } 292 293 /** 294 * @brief Obtains the label style. 295 * 296 * @return Returns the label style. 297 * @since 1.0 298 * @version 1.0 299 */ GetLabelStyle()300 static Style& GetLabelStyle() 301 { 302 return labelStyle_; 303 } 304 305 /** 306 * @brief Obtains the edit text style. 307 * 308 * @return Returns the edit text style. 309 * @since 1.0 310 * @version 1.0 311 */ GetEditTextStyle()312 static Style& GetEditTextStyle() 313 { 314 return editTextStyle_; 315 } 316 317 /** 318 * @brief Obtains the background transparent style. 319 * 320 * @return Returns the background transparent style. 321 * @since 1.0 322 * @version 1.0 323 */ GetBackgroundTransparentStyle()324 static Style& GetBackgroundTransparentStyle() 325 { 326 return backgroundTransparentStyle_; 327 } 328 329 /** 330 * @brief Obtains the progress background style. 331 * 332 * @return Returns the progress background style. 333 * @since 1.0 334 * @version 1.0 335 */ GetProgressBackgroundStyle()336 static Style& GetProgressBackgroundStyle() 337 { 338 return progressBackgroundStyle_; 339 } 340 341 /** 342 * @brief Obtains the progress foreground style. 343 * 344 * @return Returns the progress foreground style. 345 * @since 1.0 346 * @version 1.0 347 */ GetProgressForegroundStyle()348 static Style& GetProgressForegroundStyle() 349 { 350 return progressForegroundStyle_; 351 } 352 353 /** 354 * @brief Obtains the slider knob style. 355 * 356 * @return Returns the slider knob style. 357 * @since 1.0 358 * @version 1.0 359 */ GetSliderKnobStyle()360 static Style& GetSliderKnobStyle() 361 { 362 return sliderKnobStyle_; 363 } 364 365 /** 366 * @brief Obtains the picker background style. 367 * 368 * @return Returns the picker background style. 369 * @since 1.0 370 * @version 1.0 371 */ GetPickerBackgroundStyle()372 static Style& GetPickerBackgroundStyle() 373 { 374 return pickerBackgroundStyle_; 375 } 376 377 /** 378 * @brief Obtains the picker highlight style. 379 * 380 * @return Returns the picker highlight style. 381 * @since 1.0 382 * @version 1.0 383 */ GetPickerHighlightStyle()384 static Style& GetPickerHighlightStyle() 385 { 386 return pickerHighlightStyle_; 387 } 388 389 /** 390 * @brief Obtains the scroll bar background style. 391 * 392 * @return Returns the scroll bar background style. 393 * @since 6 394 */ GetScrollBarBackgroundStyle()395 static Style& GetScrollBarBackgroundStyle() 396 { 397 return scrollBarBackgroundStyle_; 398 } 399 400 /** 401 * @brief Obtains the scroll bar foreground style. 402 * 403 * @return Returns the scroll bar foreground style. 404 * @since 6 405 */ GetScrollBarForegroundStyle()406 static Style& GetScrollBarForegroundStyle() 407 { 408 return scrollBarForegroundStyle_; 409 } 410 411 private: 412 static Style defaultStyle_; 413 static Style brightStyle_; 414 static Style brightColorStyle_; 415 416 static Style buttonPressedStyle_; 417 static Style buttonReleasedStyle_; 418 static Style buttonInactiveStyle_; 419 static Style labelStyle_; 420 static Style editTextStyle_; 421 static Style backgroundTransparentStyle_; 422 static Style progressBackgroundStyle_; 423 static Style progressForegroundStyle_; 424 static Style sliderKnobStyle_; 425 426 static Style pickerBackgroundStyle_; 427 static Style pickerHighlightStyle_; 428 429 static Style scrollBarBackgroundStyle_; 430 static Style scrollBarForegroundStyle_; 431 432 static void InitStyle(); 433 static void InitButtonStyle(); 434 static void InitLabelStyle(); 435 static void InitEditTextStyle(); 436 static void InitBackgroundTransparentStyle(); 437 static void InitProgressStyle(); 438 static void InitPickerStyle(); 439 static void InitScrollBarStyle(); 440 }; 441 } // namespace OHOS 442 #endif // GRAPHIC_LITE_STYLE_H 443