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