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 constexpr float DEFAULT_AMPLITUDE_RATIO = 0.005f; 28 29 /** 30 * AppTheme defines color and styles of whole app. AppTheme should be built 31 * using AppTheme::Builder. 32 */ 33 class AppTheme : public virtual Theme { 34 DECLARE_ACE_TYPE(AppTheme, Theme); 35 36 public: 37 class Builder { 38 public: 39 Builder() = default; 40 ~Builder() = default; 41 42 RefPtr<AppTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const; 43 }; 44 45 ~AppTheme() override = default; 46 GetBackgroundColor()47 const Color& GetBackgroundColor() const 48 { 49 return backgroundColor_; 50 } 51 SetBackgroundColor(const Color & color)52 void SetBackgroundColor(const Color& color) 53 { 54 backgroundColor_ = color; 55 } 56 GetHoverScaleStart()57 float GetHoverScaleStart() const 58 { 59 return hoverScaleStart_; 60 } 61 SetHoverScaleStart(float scale)62 void SetHoverScaleStart(float scale) 63 { 64 hoverScaleStart_ = scale; 65 } 66 GetHoverScaleEnd()67 float GetHoverScaleEnd() const 68 { 69 return hoverScaleEnd_; 70 } 71 SetHoverScaleEnd(float scale)72 void SetHoverScaleEnd(float scale) 73 { 74 hoverScaleEnd_ = scale; 75 } 76 GetHoverHighlightStart()77 const Color& GetHoverHighlightStart() const 78 { 79 return hoverHighlightStart_; 80 } 81 SetHoverHighlightStart(const Color & color)82 void SetHoverHighlightStart(const Color& color) 83 { 84 hoverHighlightStart_ = color; 85 } 86 GetHoverHighlightEnd()87 const Color& GetHoverHighlightEnd() const 88 { 89 return hoverHighlightEnd_; 90 } 91 SetHoverHighlightEnd(const Color & color)92 void SetHoverHighlightEnd(const Color& color) 93 { 94 hoverHighlightEnd_ = color; 95 } 96 GetHoverDuration()97 int32_t GetHoverDuration() const 98 { 99 return hoverDuration_; 100 } 101 SetHoverDuration(int32_t duration)102 void SetHoverDuration(int32_t duration) 103 { 104 hoverDuration_ = duration; 105 } 106 GetFocusColor()107 Color GetFocusColor() const 108 { 109 return focusColor_; 110 } 111 SetFocusColor(const Color & focusColor)112 void SetFocusColor(const Color& focusColor) 113 { 114 focusColor_ = focusColor; 115 } 116 GetFocusWidthVp()117 Dimension GetFocusWidthVp() const 118 { 119 return focusWidthVp_; 120 } 121 SetFocusWidthVp(const Dimension & focusWidthVp)122 void SetFocusWidthVp(const Dimension& focusWidthVp) 123 { 124 focusWidthVp_ = Dimension(focusWidthVp.ConvertToVp(), DimensionUnit::VP); 125 } 126 GetFocusOutPaddingVp()127 Dimension GetFocusOutPaddingVp() const 128 { 129 return focusOutPaddingVp_; 130 } 131 SetFocusOutPaddingVp(const Dimension & focusOutPaddingVp)132 void SetFocusOutPaddingVp(const Dimension& focusOutPaddingVp) 133 { 134 focusOutPaddingVp_ = Dimension(focusOutPaddingVp.ConvertToVp(), DimensionUnit::VP); 135 } 136 IsFocusBoxGlow()137 bool IsFocusBoxGlow() const 138 { 139 return focusBoxGlow_; 140 } 141 NeedFocusActiveByTab()142 bool NeedFocusActiveByTab() const 143 { 144 return focusActiveByTab_; 145 } 146 NeedFocusHandleClick()147 bool NeedFocusHandleClick() const 148 { 149 return focusHandleClick_; 150 } 151 GetPageTransitionAmplitudeRatio()152 float GetPageTransitionAmplitudeRatio() const 153 { 154 return pageTransitionAmplitudeRatio_; 155 } GetDragPanDistanceMouse()156 Dimension GetDragPanDistanceMouse() const 157 { 158 return dragPanDistanceMouse_; 159 } 160 161 protected: 162 AppTheme() = default; 163 164 private: 165 Color backgroundColor_; 166 167 // HoverEffect parameters 168 float hoverScaleStart_ = 1.0f; 169 float hoverScaleEnd_ = 1.05f; // HoverEffect.Scale change from scale rate 1 to 1.05 170 Color hoverHighlightStart_ = Color::TRANSPARENT; 171 Color hoverHighlightEnd_ = 172 Color::FromRGBO(0, 0, 0, 0.05); // HoverEffect.HighLight change transparency from 100% to 5% 173 int32_t hoverDuration_ = 250; // HoverEffect animation duration 174 175 // Focus State parameters 176 Color focusColor_ = Color(0xFF007DFF); // General focus state color 177 Dimension focusWidthVp_ = 2.0_vp; // General focus border width 178 Dimension focusOutPaddingVp_ = 2.0_vp; // General distance between focus border and component border 179 bool focusBoxGlow_ = false; 180 bool focusActiveByTab_ = true; 181 bool focusHandleClick_ = true; 182 float pageTransitionAmplitudeRatio_ = DEFAULT_AMPLITUDE_RATIO; 183 Dimension dragPanDistanceMouse_ = 1.0_vp; // General distance to accept pan gesture for dragging by mouse 184 }; 185 186 } // namespace OHOS::Ace 187 188 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_THEME_APP_THEME_H 189