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