1 /* 2 * Copyright (c) 2024 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_SKELETON_PARAMS_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_SKELETON_PARAMS_H 18 19 #include "form_constants.h" 20 21 namespace OHOS::Ace::NG { 22 namespace { 23 constexpr int32_t MARGIN_DOUBLE = 2; 24 25 constexpr int32_t FORM_DIMENSION_HEIGHT_1 = 1; 26 constexpr int32_t FORM_DIMENSION_HEIGHT_2 = 2; 27 28 constexpr uint32_t CONTENT_BG_COLOR_DARK = 0xE62E3033; 29 constexpr uint32_t CONTENT_BG_COLOR_LIGHT = 0xE6FFFFFF; 30 constexpr uint32_t CONTENT_BG_COLOR_DARK_WITHOUT_BLUR = 0xFF2E3033; 31 constexpr uint32_t CONTENT_BG_COLOR_LIGHT_WITHOUT_BLUR = 0xFFFFFFFF; 32 constexpr double CONTENT_BG_OPACITY = 0.9; 33 constexpr uint32_t LINE_COLOR_LIGHT = 0xFF000000; 34 constexpr uint32_t LINE_COLOR_DARK = 0xFFFFFFFF; 35 constexpr double TITLE_LINE_OPACITY_LIGHT = 0.1; 36 constexpr double TITLE_LINE_OPACITY_DARK = 0.11; 37 constexpr double CONTENT_LINE_OPACITY_LIGHT = 0.05; 38 constexpr double CONTENT_LINE_OPACITY_DARK = 0.07; 39 40 constexpr float TITLE_LINE_WIDTH_RATIO_COMMON = 0.25f; 41 constexpr float TITLE_LINE_WIDTH_RATIO_1_1 = 0.37f; 42 constexpr float ENDING_LINE_WIDTH_RATIO = 0.5f; 43 constexpr float CONTENT_HEIGHT_ONE_THIRD = 0.33f; 44 constexpr float CONTENT_HEIGHT_TWO_THIRDS = 0.67f; 45 46 const Dimension LINE_HEIGHT_COMMON = 12.0_vp; 47 const Dimension LINE_HEIGHT_1_N = 8.0_vp; 48 const Dimension LINE_OFFSET = 16.0_vp; 49 const Dimension TITLE_MARGIN_TOP = LINE_OFFSET; 50 const Dimension TITLE_CONTENT_MARGINS_COMMON = LINE_OFFSET; 51 const Dimension TITLE_CONTENT_MARGINS_1_N = 6.0_vp; 52 const Dimension CONTENT_MARGINS_COMMON = 8.0_vp; 53 const Dimension ENDING_MARGIN_BOTTOM_COMMON = 24.0_vp; 54 const Dimension ENDING_MARGIN_BOTTOM_2_N = LINE_OFFSET; 55 const Dimension LINE_MARGIN_LEFT_COMMON = LINE_OFFSET; 56 const Dimension LINE_MARGIN_LEFT_1_N = 12.0_vp; 57 const Dimension RECT_RADIUS = 16.0_vp; 58 } 59 60 class FormSkeletonParams { 61 public: FormSkeletonParams(double cardWidth,double cardHeight,int32_t dimension,int32_t dimensionHeight,bool isDarkMode)62 FormSkeletonParams(double cardWidth, double cardHeight, int32_t dimension, int32_t dimensionHeight, 63 bool isDarkMode) : cardWidth_(cardWidth), cardHeight_(cardHeight), dimension_(dimension), 64 dimensionHeight_(dimensionHeight) 65 { 66 titleMarginTop_ = static_cast<float>(TITLE_MARGIN_TOP.ConvertToPx()); 67 contentMargins_ = static_cast<float>(CONTENT_MARGINS_COMMON.ConvertToPx()); 68 if (dimensionHeight == FORM_DIMENSION_HEIGHT_1) { 69 SetLineParamsOfHeight1(); 70 } else { 71 SetLineParamsCommon(); 72 } 73 fillColor_ = isDarkMode ? LINE_COLOR_DARK : LINE_COLOR_LIGHT; 74 titleOpacity_ = isDarkMode ? TITLE_LINE_OPACITY_DARK : TITLE_LINE_OPACITY_LIGHT; 75 contentOpacity_ = isDarkMode ? CONTENT_LINE_OPACITY_DARK : CONTENT_LINE_OPACITY_LIGHT; 76 } 77 ~FormSkeletonParams()78 ~FormSkeletonParams() {}; 79 SetLineParamsOfHeight1()80 void SetLineParamsOfHeight1() 81 { 82 lineWidth_ = static_cast<float>(cardWidth_ - LINE_MARGIN_LEFT_1_N.ConvertToPx() * MARGIN_DOUBLE); 83 lineHeight_ = static_cast<float>(LINE_HEIGHT_1_N.ConvertToPx()); 84 titleContentMargins_ = static_cast<float>(TITLE_CONTENT_MARGINS_1_N.ConvertToPx()); 85 lineMarginLeft_ = static_cast<float>(LINE_MARGIN_LEFT_1_N.ConvertToPx()); 86 if (dimension_ == static_cast<int32_t>(OHOS::AppExecFwk::Constants::Dimension::DIMENSION_1_1)) { 87 titleLineWidth_ = static_cast<float>(cardWidth_ * TITLE_LINE_WIDTH_RATIO_1_1); 88 } else { 89 titleLineWidth_ = static_cast<float>(cardWidth_ * TITLE_LINE_WIDTH_RATIO_COMMON); 90 } 91 contentLineNum_ = 1; 92 } 93 SetLineParamsCommon()94 void SetLineParamsCommon() 95 { 96 lineWidth_ = static_cast<float>(cardWidth_ - LINE_MARGIN_LEFT_COMMON.ConvertToPx() * MARGIN_DOUBLE); 97 lineHeight_ = static_cast<float>(LINE_HEIGHT_COMMON.ConvertToPx()); 98 titleContentMargins_ = static_cast<float>(TITLE_CONTENT_MARGINS_COMMON.ConvertToPx()); 99 lineMarginLeft_ = static_cast<float>(LINE_MARGIN_LEFT_COMMON.ConvertToPx()); 100 titleLineWidth_ = static_cast<float>(cardWidth_ * TITLE_LINE_WIDTH_RATIO_COMMON); 101 endingLineWidth_ = static_cast<float>(cardWidth_ * ENDING_LINE_WIDTH_RATIO); 102 float contentHeightRatio; 103 float endingMarginBottom; 104 if (dimensionHeight_ == FORM_DIMENSION_HEIGHT_2) { 105 contentHeightRatio = CONTENT_HEIGHT_TWO_THIRDS; 106 endingMarginBottom = static_cast<float>(ENDING_MARGIN_BOTTOM_2_N.ConvertToPx()); 107 } else { 108 contentHeightRatio = CONTENT_HEIGHT_ONE_THIRD; 109 endingMarginBottom = static_cast<float>(ENDING_MARGIN_BOTTOM_COMMON.ConvertToPx()); 110 } 111 float titleContentAreaHeight = static_cast<float>(cardHeight_) * contentHeightRatio; 112 float titleAreaHeight = titleMarginTop_ + lineHeight_ + titleContentMargins_; 113 float contentAreaHeight = titleContentAreaHeight - titleAreaHeight; 114 if (lineHeight_ + contentMargins_ > 0) { 115 contentLineNum_ = static_cast<int32_t>(contentAreaHeight / (lineHeight_ + contentMargins_)); 116 } 117 endingLineMarginTop_ = static_cast<float>(cardHeight_ - (titleAreaHeight + 118 (lineHeight_ + contentMargins_) * contentLineNum_ - contentMargins_ + 119 lineHeight_ + endingMarginBottom)); 120 } 121 GetLineWidth()122 float GetLineWidth() const 123 { 124 return lineWidth_; 125 } 126 GetLineHeight()127 float GetLineHeight() const 128 { 129 return lineHeight_; 130 } 131 GetTitleContentMargins()132 float GetTitleContentMargins() const 133 { 134 return titleContentMargins_; 135 } 136 GetLineMarginLeft()137 float GetLineMarginLeft() const 138 { 139 return lineMarginLeft_; 140 } 141 GetTitleLineWidth()142 float GetTitleLineWidth() const 143 { 144 return titleLineWidth_; 145 } 146 GetTitleMarginTop()147 float GetTitleMarginTop() const 148 { 149 return titleMarginTop_; 150 } 151 GetContentMargins()152 float GetContentMargins() const 153 { 154 return contentMargins_; 155 } 156 GetEndingLineWidth()157 float GetEndingLineWidth() const 158 { 159 return endingLineWidth_; 160 } 161 GetEndingLineMarginTop()162 float GetEndingLineMarginTop() const 163 { 164 return endingLineMarginTop_; 165 } 166 GetContentLineNum()167 int32_t GetContentLineNum() const 168 { 169 return contentLineNum_; 170 } 171 GetFillColor()172 uint32_t GetFillColor() const 173 { 174 return fillColor_; 175 } 176 GetTitleOpacity()177 double GetTitleOpacity() const 178 { 179 return titleOpacity_; 180 } 181 GetContentOpacity()182 double GetContentOpacity() const 183 { 184 return contentOpacity_; 185 } 186 187 private: 188 double cardWidth_ = 0.0; 189 double cardHeight_ = 0.0; 190 int32_t dimension_ = 0; 191 int32_t dimensionHeight_ = 0; 192 193 float lineWidth_ = 0.0f; 194 float lineHeight_ = 0.0f; 195 float titleContentMargins_ = 0.0f; 196 float lineMarginLeft_ = 0.0f; 197 float titleLineWidth_ = 0.0f; 198 float titleMarginTop_ = 0.0f; 199 float contentMargins_ = 0.0f; 200 float endingLineWidth_ = 0.0f; 201 float endingLineMarginTop_ = 0.0f; 202 int32_t contentLineNum_ = 0; 203 uint32_t fillColor_; 204 double titleOpacity_; 205 double contentOpacity_; 206 }; 207 } // namespace OHOS::Ace::NG 208 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_FORM_FORM_SKELETON_PARAMS_H 209