1 /* 2 * Copyright (c) 2023 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_SHEET_SHEET_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SHEET_SHEET_THEME_H 18 19 #include "core/components/common/properties/color.h" 20 #include "core/components/theme/theme.h" 21 #include "core/components/theme/theme_constants.h" 22 23 namespace OHOS::Ace::NG { 24 namespace { 25 constexpr Dimension SHEET_BLANK_MINI_HEIGHT = 8.0_vp; 26 constexpr Dimension SHEET_BLANK_FLOATING_STATUS_BAR = 32.0_vp; 27 constexpr Dimension SHEET_SPLIT_AI_BAR = 24.0_vp; 28 constexpr Dimension SHEET_SPLIT_STATUS_BAR = 24.0_vp; 29 constexpr Dimension SHEET_OPERATION_AREA_PADDING = 8.0_vp; 30 constexpr Dimension SHEET_OPERATION_AREA_HEIGHT = 56.0_vp; 31 constexpr Dimension SHEET_OPERATION_AREA_HEIGHT_DOUBLE = 72.0_vp; 32 constexpr Dimension SHEET_CLOSE_ICON_WIDTH = 40.0_vp; 33 constexpr Dimension SHEET_CLOSE_ICON_HEIGHT = 40.0_vp; 34 constexpr Dimension SHEET_CLOSE_ICON_IMAGE_HEIGHT = 18.0_vp; 35 constexpr Dimension SHEET_CLOSE_ICON_IMAGE_WIDTH = 18.0_vp; 36 constexpr Dimension SHEET_CLOSE_ICON_TITLE_SPACE = 32.0_vp; 37 constexpr Dimension SHEET_CLOSE_ICON_TITLE_SPACE_NEW = 8.0_vp; 38 constexpr Dimension SHEET_CLOSE_ICON_RADIUS = 20.0_vp; 39 constexpr Dimension SHEET_DRAG_BAR_WIDTH = 64.0_vp; 40 constexpr Dimension SHEET_DRAG_BAR_HEIGHT = 16.0_vp; 41 constexpr Dimension SHEET_LANDSCAPE_WIDTH = 480.0_vp; 42 constexpr Dimension SHEET_POPUP_WIDTH = 360.0_vp; 43 constexpr Dimension SHEET_BIG_WINDOW_WIDTH = 480.0_vp; 44 constexpr Dimension SHEET_BIG_WINDOW_HEIGHT = 560.0_vp; 45 constexpr Dimension SHEET_BIG_WINDOW_MIN_HEIGHT = 320.0_vp; 46 constexpr Dimension SHEET_ARROW_WIDTH = 32.0_vp; 47 constexpr Dimension SHEET_ARROW_HEIGHT = 8.0_vp; 48 constexpr Dimension SHEET_TARGET_SPACE = 8.0_vp; 49 constexpr Dimension SHEET_DEVICE_WIDTH_BREAKPOINT = 600.0_vp; 50 constexpr Dimension SHEET_PC_DEVICE_WIDTH_BREAKPOINT = 840.0_vp; 51 constexpr Dimension SHEET_DOUBLE_TITLE_TOP_PADDING = 16.0_vp; 52 constexpr Dimension SHEET_DOUBLE_TITLE_BOTTON_MARGIN = 4.0_vp; 53 constexpr Dimension SHEET_TITLE_AERA_MARGIN = -8.0_vp; 54 constexpr int32_t SHEET_TITLE_MAX_LINES = 1; 55 } // namespace 56 class SheetTheme : public virtual Theme { 57 DECLARE_ACE_TYPE(SheetTheme, Theme); 58 59 public: 60 class Builder { 61 public: 62 Builder() = default; 63 ~Builder() = default; 64 Build(const RefPtr<ThemeConstants> & themeConstants)65 RefPtr<SheetTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 66 { 67 RefPtr<SheetTheme> theme = AceType::Claim(new SheetTheme()); 68 if (!themeConstants) { 69 return theme; 70 } 71 72 ParsePattern(themeConstants, theme); 73 return theme; 74 } 75 76 private: ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<SheetTheme> & theme)77 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<SheetTheme>& theme) const 78 { 79 RefPtr<ThemeStyle> sheetPattern = themeConstants->GetPatternByName(THEME_PATTERN_SHEET); 80 if (!sheetPattern) { 81 TAG_LOGE(AceLogTag::ACE_SHEET, "sheetPattern is null"); 82 return; 83 } 84 85 theme->sheetRadius_ = sheetPattern->GetAttr<Dimension>("sheet_radius", 32.0_vp); 86 theme->titleTextFontSize_ = sheetPattern->GetAttr<Dimension>("title_text_font_size", 20.0_vp); 87 theme->titleTextMargin_ = sheetPattern->GetAttr<Dimension>("title_text_margin", 16.0_vp); 88 theme->subtitleTextFontSize_ = sheetPattern->GetAttr<Dimension>("subtitle_text_font_size", 14.0_fp); 89 theme->subtitleTextMargin_ = sheetPattern->GetAttr<Dimension>("subtitle_text_margin", 2.0_fp); 90 theme->titleTextFontColor_ = sheetPattern->GetAttr<Color>("title_text_font_color", Color(0xff182431)); 91 theme->subtitleTextFontColor_ = sheetPattern->GetAttr<Color>("subtitle_text_font_color", Color(0x99182431)); 92 theme->sheetBackgoundColor_ = sheetPattern->GetAttr<Color>("sheet_background_color", Color(0xfff1f3f5)); 93 theme->dragBarColor_ = sheetPattern->GetAttr<Color>("drag_bar_color", Color(0x33182431)); 94 theme->sheetType_ = sheetPattern->GetAttr<std::string>("sheet_type", "auto"); 95 theme->sheetBottom_ = sheetPattern->GetAttr<std::string>("sheet_bottom", "auto"); 96 theme->maskColor_ = sheetPattern->GetAttr<Color>("mask_color", Color(0x33182431)); 97 theme->closeIconColor_ = sheetPattern->GetAttr<Color>("close_icon_color", Color(0x0c182431)); 98 theme->closeIconImageColor_ = sheetPattern->GetAttr<Color>("close_icon_image_color", Color(0xff182431)); 99 theme->sheetBackgroundBlurStyle_ = sheetPattern->GetAttr<int>("sheet_background_blur_style", 0); 100 theme->sheetNormalScale_ = sheetPattern->GetAttr<double>("sheet_normal_aging_scale", 1.0f); 101 theme->sheetMaxAgingScale_ = sheetPattern->GetAttr<double>("sheet_max_aging_scale", 1.75f); 102 theme->closeIconSource_ = themeConstants->GetSymbolByName("sys.symbol.xmark"); 103 theme->closeIconSymbolColor_ = sheetPattern->GetAttr<Color>("close_icon_symbol_color", Color(0xff182431)); 104 } 105 }; 106 ~SheetTheme() override = default; 107 GetSheetRadius()108 const Dimension& GetSheetRadius() const 109 { 110 return sheetRadius_; 111 } 112 GetTitleTextFontSize()113 const Dimension& GetTitleTextFontSize() const 114 { 115 return titleTextFontSize_; 116 } 117 GetTitleTextMargin()118 const Dimension& GetTitleTextMargin() const 119 { 120 return titleTextMargin_; 121 } 122 GetSubtitleTextFontSize()123 const Dimension& GetSubtitleTextFontSize() const 124 { 125 return subtitleTextFontSize_; 126 } 127 GetSubtitleTextMargin()128 const Dimension& GetSubtitleTextMargin() const 129 { 130 return subtitleTextMargin_; 131 } 132 GetTitleTextFontColor()133 const Color& GetTitleTextFontColor() const 134 { 135 return titleTextFontColor_; 136 } 137 GetSubtitleTextFontColor()138 const Color& GetSubtitleTextFontColor() const 139 { 140 return subtitleTextFontColor_; 141 } 142 GetSheetBackgoundColor()143 const Color& GetSheetBackgoundColor() const 144 { 145 return sheetBackgoundColor_; 146 } 147 GetDragBarColor()148 const Color& GetDragBarColor() const 149 { 150 return dragBarColor_; 151 } 152 GetMaskColor()153 const Color& GetMaskColor() const 154 { 155 return maskColor_; 156 } 157 GetCloseIconColor()158 const Color& GetCloseIconColor() const 159 { 160 return closeIconColor_; 161 } 162 GetCloseIconImageColor()163 const Color& GetCloseIconImageColor() const 164 { 165 return closeIconImageColor_; 166 } 167 IsOnlyBottom()168 bool IsOnlyBottom() const 169 { 170 return sheetBottom_ == "bottom"; 171 } 172 GetSheetType()173 const std::string& GetSheetType() const 174 { 175 return sheetType_; 176 } 177 GetSheetBackgroundBlurStyle()178 const int& GetSheetBackgroundBlurStyle() const 179 { 180 return sheetBackgroundBlurStyle_; 181 } 182 GetSheetNormalScale()183 const double& GetSheetNormalScale() const 184 { 185 return sheetNormalScale_; 186 } 187 GetSheetMaxAgingScale()188 const double& GetSheetMaxAgingScale() const 189 { 190 return sheetMaxAgingScale_; 191 } 192 GetCloseIconSymbolColor()193 const Color& GetCloseIconSymbolColor() const 194 { 195 return closeIconSymbolColor_; 196 } 197 GetCloseIconSource()198 const uint32_t& GetCloseIconSource() const 199 { 200 return closeIconSource_; 201 } 202 203 protected: 204 SheetTheme() = default; 205 206 private: 207 Dimension sheetRadius_; 208 Dimension titleTextFontSize_; 209 Dimension titleTextMargin_; 210 Dimension subtitleTextFontSize_; 211 Dimension subtitleTextMargin_; 212 Color titleTextFontColor_; 213 Color subtitleTextFontColor_; 214 Color sheetBackgoundColor_; 215 Color dragBarColor_; 216 Color maskColor_; 217 Color closeIconColor_; 218 Color closeIconImageColor_; 219 Color closeIconSymbolColor_; 220 std::string sheetBottom_; 221 std::string sheetType_; 222 int sheetBackgroundBlurStyle_; 223 double sheetNormalScale_; 224 double sheetMaxAgingScale_; 225 uint32_t closeIconSource_ = 0; 226 }; 227 } // namespace OHOS::Ace::NG 228 229 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SHEET_SHEET_THEME_H 230