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 /* text style */ 179 uint8_t textOpa_; 180 uint16_t font_; 181 int8_t lineSpace_; 182 int16_t letterSpace_; 183 int16_t lineHeight_; 184 ColorType textColor_; 185 /* line style */ 186 ColorType lineColor_; 187 uint8_t lineOpa_; 188 uint8_t lineCap_; 189 int16_t lineWidth_; 190 }; 191 192 /** 193 * @brief Define some default style for {@link UIView}. 194 * 195 * @since 1.0 196 * @version 1.0 197 */ 198 class StyleDefault : public HeapBase { 199 public: 200 /** 201 * @brief A constructor used to create a <b>StyleDefault</b> instance. 202 * 203 * @since 1.0 204 * @version 1.0 205 */ StyleDefault()206 StyleDefault() {} 207 208 /** 209 * @brief A destructor used to delete the <b>StyleDefault</b> instance. 210 * 211 * @since 1.0 212 * @version 1.0 213 */ ~StyleDefault()214 ~StyleDefault() {} 215 216 static void Init(); 217 218 /** 219 * @brief Obtains the default style. 220 * 221 * @return Returns the default style. 222 * @since 1.0 223 * @version 1.0 224 */ GetDefaultStyle()225 static Style& GetDefaultStyle() 226 { 227 return defaultStyle_; 228 } 229 230 /** 231 * @brief Obtains the bright style. 232 * 233 * @return Returns the bright style. 234 * @since 1.0 235 * @version 1.0 236 */ GetBrightStyle()237 static Style& GetBrightStyle() 238 { 239 return brightStyle_; 240 } 241 242 /** 243 * @brief Obtains the bright color style. 244 * 245 * @return Returns the bright color style. 246 * @since 1.0 247 * @version 1.0 248 */ GetBrightColorStyle()249 static Style& GetBrightColorStyle() 250 { 251 return brightColorStyle_; 252 } 253 254 /** 255 * @brief Obtains the button pressed style. 256 * 257 * @return Returns the button pressed style. 258 * @since 1.0 259 * @version 1.0 260 */ GetButtonPressedStyle()261 static Style& GetButtonPressedStyle() 262 { 263 return buttonPressedStyle_; 264 } 265 266 /** 267 * @brief Obtains the button released style. 268 * 269 * @return Returns the button released style. 270 * @since 1.0 271 * @version 1.0 272 */ GetButtonReleasedStyle()273 static Style& GetButtonReleasedStyle() 274 { 275 return buttonReleasedStyle_; 276 } 277 278 /** 279 * @brief Obtains the button inactive style. 280 * 281 * @return Returns the button inactive style. 282 * @since 1.0 283 * @version 1.0 284 */ GetButtonInactiveStyle()285 static Style& GetButtonInactiveStyle() 286 { 287 return buttonInactiveStyle_; 288 } 289 290 /** 291 * @brief Obtains the label style. 292 * 293 * @return Returns the label style. 294 * @since 1.0 295 * @version 1.0 296 */ GetLabelStyle()297 static Style& GetLabelStyle() 298 { 299 return labelStyle_; 300 } 301 302 /** 303 * @brief Obtains the edit text style. 304 * 305 * @return Returns the edit text style. 306 * @since 1.0 307 * @version 1.0 308 */ GetEditTextStyle()309 static Style& GetEditTextStyle() 310 { 311 return editTextStyle_; 312 } 313 314 /** 315 * @brief Obtains the background transparent style. 316 * 317 * @return Returns the background transparent style. 318 * @since 1.0 319 * @version 1.0 320 */ GetBackgroundTransparentStyle()321 static Style& GetBackgroundTransparentStyle() 322 { 323 return backgroundTransparentStyle_; 324 } 325 326 /** 327 * @brief Obtains the progress background style. 328 * 329 * @return Returns the progress background style. 330 * @since 1.0 331 * @version 1.0 332 */ GetProgressBackgroundStyle()333 static Style& GetProgressBackgroundStyle() 334 { 335 return progressBackgroundStyle_; 336 } 337 338 /** 339 * @brief Obtains the progress foreground style. 340 * 341 * @return Returns the progress foreground style. 342 * @since 1.0 343 * @version 1.0 344 */ GetProgressForegroundStyle()345 static Style& GetProgressForegroundStyle() 346 { 347 return progressForegroundStyle_; 348 } 349 350 /** 351 * @brief Obtains the slider knob style. 352 * 353 * @return Returns the slider knob style. 354 * @since 1.0 355 * @version 1.0 356 */ GetSliderKnobStyle()357 static Style& GetSliderKnobStyle() 358 { 359 return sliderKnobStyle_; 360 } 361 362 /** 363 * @brief Obtains the picker background style. 364 * 365 * @return Returns the picker background style. 366 * @since 1.0 367 * @version 1.0 368 */ GetPickerBackgroundStyle()369 static Style& GetPickerBackgroundStyle() 370 { 371 return pickerBackgroundStyle_; 372 } 373 374 /** 375 * @brief Obtains the picker highlight style. 376 * 377 * @return Returns the picker highlight style. 378 * @since 1.0 379 * @version 1.0 380 */ GetPickerHighlightStyle()381 static Style& GetPickerHighlightStyle() 382 { 383 return pickerHighlightStyle_; 384 } 385 386 /** 387 * @brief Obtains the scroll bar background style. 388 * 389 * @return Returns the scroll bar background style. 390 * @since 6 391 */ GetScrollBarBackgroundStyle()392 static Style& GetScrollBarBackgroundStyle() 393 { 394 return scrollBarBackgroundStyle_; 395 } 396 397 /** 398 * @brief Obtains the scroll bar foreground style. 399 * 400 * @return Returns the scroll bar foreground style. 401 * @since 6 402 */ GetScrollBarForegroundStyle()403 static Style& GetScrollBarForegroundStyle() 404 { 405 return scrollBarForegroundStyle_; 406 } 407 408 private: 409 static Style defaultStyle_; 410 static Style brightStyle_; 411 static Style brightColorStyle_; 412 413 static Style buttonPressedStyle_; 414 static Style buttonReleasedStyle_; 415 static Style buttonInactiveStyle_; 416 static Style labelStyle_; 417 static Style editTextStyle_; 418 static Style backgroundTransparentStyle_; 419 static Style progressBackgroundStyle_; 420 static Style progressForegroundStyle_; 421 static Style sliderKnobStyle_; 422 423 static Style pickerBackgroundStyle_; 424 static Style pickerHighlightStyle_; 425 426 static Style scrollBarBackgroundStyle_; 427 static Style scrollBarForegroundStyle_; 428 429 static void InitStyle(); 430 static void InitButtonStyle(); 431 static void InitLabelStyle(); 432 static void InitEditTextStyle(); 433 static void InitBackgroundTransparentStyle(); 434 static void InitProgressStyle(); 435 static void InitPickerStyle(); 436 static void InitScrollBarStyle(); 437 }; 438 } // namespace OHOS 439 #endif // GRAPHIC_LITE_STYLE_H 440