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 #include "core/components/theme/theme_constants_defines.h" 23 24 namespace OHOS::Ace::NG { 25 namespace { 26 constexpr Dimension SHEET_BLANK_MINI_HEIGHT = 8.0_vp; 27 constexpr Dimension SHEET_OPERATION_AREA_PADDING = 8.0_vp; 28 constexpr Dimension SHEET_OPERATION_AREA_HEIGHT = 56.0_vp; 29 constexpr Dimension SHEET_OPERATION_AREA_HEIGHT_DOUBLE = 72.0_vp; 30 constexpr Dimension SHEET_CLOSE_ICON_WIDTH = 40.0_vp; 31 constexpr Dimension SHEET_CLOSE_ICON_HEIGHT = 40.0_vp; 32 constexpr Dimension SHEET_CLOSE_ICON_IMAGE_HEIGHT = 18.0_vp; 33 constexpr Dimension SHEET_CLOSE_ICON_IMAGE_WIDTH = 18.0_vp; 34 constexpr Dimension SHEET_CLOSE_ICON_TITLE_SPACE = 32.0_vp; 35 constexpr Dimension SHEET_CLOSE_ICON_RADIUS = 20.0_vp; 36 constexpr Dimension SHEET_DRAG_BAR_WIDTH = 64.0_vp; 37 constexpr Dimension SHEET_DRAG_BAR_HEIGHT = 16.0_vp; 38 constexpr Dimension SHEET_LANDSCAPE_WIDTH = 480.0_vp; 39 constexpr Dimension SHEET_POPUP_WIDTH = 360.0_vp; 40 constexpr Dimension SHEET_BIG_WINDOW_WIDTH = 480.0_vp; 41 constexpr Dimension SHEET_BIG_WINDOW_HEIGHT = 560.0_vp; 42 constexpr Dimension SHEET_BIG_WINDOW_MIN_HEIGHT = 320.0_vp; 43 constexpr Dimension SHEET_ARROW_WIDTH = 32.0_vp; 44 constexpr Dimension SHEET_ARROW_HEIGHT = 8.0_vp; 45 constexpr Dimension SHEET_TARGET_SPACE = 8.0_vp; 46 constexpr Dimension SHEET_DEVICE_WIDTH_BREAKPOINT = 600.0_vp; 47 constexpr Dimension SHEET_PC_DEVICE_WIDTH_BREAKPOINT = 840.0_vp; 48 constexpr Dimension SHEET_DOUBLE_TITLE_TOP_PADDING = 15.0_vp; 49 constexpr Dimension SHEET_DOUBLE_TITLE_BOTTON_PADDING = 8.0_vp; 50 constexpr Dimension SHEET_TITLE_AERA_MARGIN = -8.0_vp; 51 } // namespace 52 class SheetTheme : public virtual Theme { 53 DECLARE_ACE_TYPE(SheetTheme, Theme); 54 55 public: 56 class Builder { 57 public: 58 Builder() = default; 59 ~Builder() = default; 60 Build(const RefPtr<ThemeConstants> & themeConstants)61 RefPtr<SheetTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 62 { 63 RefPtr<SheetTheme> theme = AceType::Claim(new SheetTheme()); 64 if (!themeConstants) { 65 return theme; 66 } 67 68 ParsePattern(themeConstants, theme); 69 return theme; 70 } 71 72 private: ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<SheetTheme> & theme)73 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<SheetTheme>& theme) const 74 { 75 RefPtr<ThemeStyle> sheetPattern = themeConstants->GetPatternByName(THEME_PATTERN_SHEET); 76 if (!sheetPattern) { 77 LOGE("sheetPattern is null"); 78 return; 79 } 80 81 theme->sheetRadius_ = sheetPattern->GetAttr<Dimension>("sheet_radius", 32.0_vp); 82 theme->titleTextFontSize_ = sheetPattern->GetAttr<Dimension>("title_text_font_size", 20.0_vp); 83 theme->titleTextMargin_ = sheetPattern->GetAttr<Dimension>("title_text_margin", 16.0_vp); 84 theme->subtitleTextFontSize_ = sheetPattern->GetAttr<Dimension>("subtitle_text_font_size", 14.0_fp); 85 theme->subtitleTextMargin_ = sheetPattern->GetAttr<Dimension>("subtitle_text_margin", 2.0_fp); 86 theme->titleTextFontColor_ = sheetPattern->GetAttr<Color>("title_text_font_color", Color(0xff182431)); 87 theme->subtitleTextFontColor_ = sheetPattern->GetAttr<Color>("subtitle_text_font_color", Color(0x99182431)); 88 theme->sheetBackgoundColor_ = sheetPattern->GetAttr<Color>("sheet_background_color", Color(0xfff1f3f5)); 89 theme->dragBarColor_ = sheetPattern->GetAttr<Color>("drag_bar_color", Color(0x33182431)); 90 theme->sheetType_ = sheetPattern->GetAttr<std::string>("sheet_type", "auto"); 91 theme->maskColor_ = sheetPattern->GetAttr<Color>("mask_color", Color(0x33182431)); 92 theme->closeIconColor_ = sheetPattern->GetAttr<Color>("close_icon_color", Color(0x0c182431)); 93 theme->closeIconImageColor_ = sheetPattern->GetAttr<Color>("close_icon_image_color", Color(0xff182431)); 94 } 95 }; 96 ~SheetTheme() override = default; 97 GetSheetRadius()98 const Dimension& GetSheetRadius() const 99 { 100 return sheetRadius_; 101 } 102 GetTitleTextFontSize()103 const Dimension& GetTitleTextFontSize() const 104 { 105 return titleTextFontSize_; 106 } 107 GetTitleTextMargin()108 const Dimension& GetTitleTextMargin() const 109 { 110 return titleTextMargin_; 111 } 112 GetSubtitleTextFontSize()113 const Dimension& GetSubtitleTextFontSize() const 114 { 115 return subtitleTextFontSize_; 116 } 117 GetSubtitleTextMargin()118 const Dimension& GetSubtitleTextMargin() const 119 { 120 return subtitleTextMargin_; 121 } 122 GetTitleTextFontColor()123 const Color& GetTitleTextFontColor() const 124 { 125 return titleTextFontColor_; 126 } 127 GetSubtitleTextFontColor()128 const Color& GetSubtitleTextFontColor() const 129 { 130 return subtitleTextFontColor_; 131 } 132 GetSheetBackgoundColor()133 const Color& GetSheetBackgoundColor() const 134 { 135 return sheetBackgoundColor_; 136 } 137 GetDragBarColor()138 const Color& GetDragBarColor() const 139 { 140 return dragBarColor_; 141 } 142 GetMaskColor()143 const Color& GetMaskColor() const 144 { 145 return maskColor_; 146 } 147 GetCloseIconColor()148 const Color& GetCloseIconColor() const 149 { 150 return closeIconColor_; 151 } 152 GetCloseIconImageColor()153 const Color& GetCloseIconImageColor() const 154 { 155 return closeIconImageColor_; 156 } 157 GetSheetType()158 const std::string& GetSheetType() const 159 { 160 return sheetType_; 161 } 162 163 protected: 164 SheetTheme() = default; 165 166 private: 167 Dimension sheetRadius_; 168 Dimension titleTextFontSize_; 169 Dimension titleTextMargin_; 170 Dimension subtitleTextFontSize_; 171 Dimension subtitleTextMargin_; 172 Color titleTextFontColor_; 173 Color subtitleTextFontColor_; 174 Color sheetBackgoundColor_; 175 Color dragBarColor_; 176 Color maskColor_; 177 Color closeIconColor_; 178 Color closeIconImageColor_; 179 std::string sheetType_; 180 }; 181 } // namespace OHOS::Ace::NG 182 183 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SHEET_SHEET_THEME_H 184