1 /* 2 * Copyright (c) 2021 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_THEME_APP_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_THEME_APP_THEME_H 18 19 #include <unordered_map> 20 21 #include "core/components/common/properties/color.h" 22 #include "core/components/theme/theme.h" 23 #include "core/components/theme/theme_constants.h" 24 25 namespace OHOS::Ace { 26 27 /** 28 * AppTheme defines color and styles of whole app. AppTheme should be built 29 * using AppTheme::Builder. 30 */ 31 class AppTheme : public virtual Theme { 32 DECLARE_ACE_TYPE(AppTheme, Theme); 33 34 public: 35 class Builder { 36 public: 37 Builder() = default; 38 ~Builder() = default; 39 40 RefPtr<AppTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const; 41 }; 42 43 ~AppTheme() override = default; 44 GetBackgroundColor()45 const Color& GetBackgroundColor() const 46 { 47 return backgroundColor_; 48 } 49 SetBackgroundColor(const Color & color)50 void SetBackgroundColor(const Color& color) 51 { 52 backgroundColor_ = color; 53 } 54 GetHoverScaleStart()55 float GetHoverScaleStart() const 56 { 57 return hoverScaleStart_; 58 } 59 SetHoverScaleStart(float scale)60 void SetHoverScaleStart(float scale) 61 { 62 hoverScaleStart_ = scale; 63 } 64 GetHoverScaleEnd()65 float GetHoverScaleEnd() const 66 { 67 return hoverScaleEnd_; 68 } 69 SetHoverScaleEnd(float scale)70 void SetHoverScaleEnd(float scale) 71 { 72 hoverScaleEnd_ = scale; 73 } 74 GetHoverHighlightStart()75 const Color& GetHoverHighlightStart() const 76 { 77 return hoverHighlightStart_; 78 } 79 SetHoverHighlightStart(const Color & color)80 void SetHoverHighlightStart(const Color& color) 81 { 82 hoverHighlightStart_ = color; 83 } 84 GetHoverHighlightEnd()85 const Color& GetHoverHighlightEnd() const 86 { 87 return hoverHighlightEnd_; 88 } 89 SetHoverHighlightEnd(const Color & color)90 void SetHoverHighlightEnd(const Color& color) 91 { 92 hoverHighlightEnd_ = color; 93 } 94 GetHoverDuration()95 int32_t GetHoverDuration() const 96 { 97 return hoverDuration_; 98 } 99 SetHoverDuration(int32_t duration)100 void SetHoverDuration(int32_t duration) 101 { 102 hoverDuration_ = duration; 103 } 104 GetFocusColor()105 Color GetFocusColor() const 106 { 107 return focusColor_; 108 } 109 SetFocusColor(const Color & focusColor)110 void SetFocusColor(const Color& focusColor) 111 { 112 focusColor_ = focusColor; 113 } 114 GetFocusWidthVp()115 Dimension GetFocusWidthVp() const 116 { 117 return focusWidthVp_; 118 } 119 SetFocusWidthVp(const Dimension & focusWidthVp)120 void SetFocusWidthVp(const Dimension& focusWidthVp) 121 { 122 focusWidthVp_ = Dimension(focusWidthVp.ConvertToVp(), DimensionUnit::VP); 123 } 124 GetFocusOutPaddingVp()125 Dimension GetFocusOutPaddingVp() const 126 { 127 return focusOutPaddingVp_; 128 } 129 SetFocusOutPaddingVp(const Dimension & focusOutPaddingVp)130 void SetFocusOutPaddingVp(const Dimension& focusOutPaddingVp) 131 { 132 focusOutPaddingVp_ = Dimension(focusOutPaddingVp.ConvertToVp(), DimensionUnit::VP); 133 } 134 135 protected: 136 AppTheme() = default; 137 138 private: 139 Color backgroundColor_; 140 141 // HoverEffect parameters 142 float hoverScaleStart_ = 1.0f; 143 float hoverScaleEnd_ = 1.05f; // HoverEffect.Scale change from scale rate 1 to 1.05 144 Color hoverHighlightStart_ = Color::TRANSPARENT; 145 Color hoverHighlightEnd_ = 146 Color::FromRGBO(0, 0, 0, 0.05); // HoverEffect.HighLight change transparency from 100% to 5% 147 int32_t hoverDuration_ = 250; // HoverEffect animation duration 148 149 // Focus State parameters 150 Color focusColor_ = Color(0xFF007DFF); // General focus state color 151 Dimension focusWidthVp_ = 2.0_vp; // General focus border width 152 Dimension focusOutPaddingVp_ = 2.0_vp; // General distance between focus border and component border 153 }; 154 155 } // namespace OHOS::Ace 156 157 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_THEME_APP_THEME_H 158