1 /* 2 * Copyright (c) 2022 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_NG_PATTERNS_MENU_MENU_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_THEME_H 18 19 #include <cstdint> 20 21 #include "core/components/theme/theme.h" 22 #include "frameworks/base/geometry/dimension.h" 23 24 namespace OHOS::Ace::NG { 25 constexpr Dimension GRADIENT_HEIGHT = Dimension(50, DimensionUnit::VP); 26 27 constexpr uint8_t GRADIENT_END_GRADIENT = 255; 28 constexpr uint32_t DEFAULT_BACKGROUND_COLOR = 0xFFFFFFF; 29 constexpr uint32_t MENU_MIN_GRID_COUNTS = 2; 30 constexpr uint32_t MENU_MAX_GRID_COUNTS = 6; 31 constexpr int32_t HOVER_IMAGE_OPACITY_CHANGE_DURATION = 150; 32 constexpr int32_t HOVER_IMAGE_DELAY_DURATION = 200; 33 constexpr int32_t HOVER_IMAGE_CUSTOM_PREVIEW_SCALE_DURATION = 650; 34 constexpr int32_t HOVER_IMAGE_PREVIEW_DISAPPEAR_DURATION = 450; 35 constexpr double OUTBORDER_RADIUS = 19.75; // Default value of outBorderRadius 36 constexpr float MENU_BIG_FONT_SIZE_SCALE = 1.75f; 37 constexpr float MENU_LARGE_FONT_SIZE_SCALE_ = 2.0f; 38 constexpr float MENU_MAX_FONT_SIZE_SCALE = 3.2f; 39 constexpr int32_t MENU_TEXT_MAX_LINES = std::numeric_limits<int32_t>::max(); 40 41 /** 42 * MenuTheme defines styles of menu item. MenuTheme should be built 43 * using MenuTheme::Builder. 44 */ 45 class MenuTheme : public virtual Theme { 46 DECLARE_ACE_TYPE(MenuTheme, Theme); 47 48 public: 49 class Builder { 50 public: 51 Builder() = default; 52 ~Builder() = default; 53 Build(const RefPtr<ThemeConstants> & themeConstants)54 RefPtr<MenuTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 55 { 56 RefPtr<MenuTheme> theme = AceType::Claim(new MenuTheme()); 57 if (!themeConstants) { 58 return theme; 59 } 60 theme->symbolId_ = themeConstants->GetSymbolByName("sys.symbol.checkmark"); 61 ParsePattern(themeConstants->GetThemeStyle(), theme); 62 return theme; 63 } 64 65 private: ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<MenuTheme> & theme)66 void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<MenuTheme>& theme) const 67 { 68 if (!themeStyle) { 69 return; 70 } 71 auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_SELECT, nullptr); 72 if (!pattern) { 73 LOGE("Pattern of menu is null, please check!"); 74 return; 75 } 76 theme->previewMenuMaskColor_ = pattern->GetAttr<Color>("preview_menu_mask_color", Color(0x33182431)); 77 theme->bgBlurEffectEnable_ = 78 StringUtils::StringToInt(pattern->GetAttr<std::string>("menu_bg_blur_effect_enable", "0")); 79 theme->bgEffectSaturation_ = pattern->GetAttr<double>("menu_blur_effect_saturation", 1.0); 80 theme->bgEffectBrightness_ = pattern->GetAttr<double>("menu_blur_effect_brightness", 1.0); 81 theme->bgEffectRadius_ = pattern->GetAttr<Dimension>("menu_blur_effect_radius", 0.0_vp); 82 theme->bgEffectColor_ = pattern->GetAttr<Color>("menu_blur_effect_color", Color::TRANSPARENT); 83 theme->doubleBorderEnable_ = 84 StringUtils::StringToInt(pattern->GetAttr<std::string>("menu_double_border_enable", "0")); 85 theme->outerBorderWidth_ = pattern->GetAttr<double>("menu_outer_border_width", 1.0); 86 theme->outerBorderRadius_ = pattern->GetAttr<double>("menu_outer_border_radius", OUTBORDER_RADIUS); 87 theme->outerBorderColor_ = pattern->GetAttr<Color>("menu_outer_border_color", Color::TRANSPARENT); 88 theme->innerBorderWidth_ = pattern->GetAttr<double>("menu_inner_border_width", 1.0); 89 theme->innerBorderRadius_ = pattern->GetAttr<Dimension>("menu_inner_border_radius", 0.0_vp); 90 theme->innerBorderColor_ = pattern->GetAttr<Color>("menu_inner_border_color", Color::TRANSPARENT); 91 theme->filterAnimationDuration_ = 250; 92 theme->previewAnimationDuration_ = 300; 93 theme->hoverImageSwitchToPreviewOpacityDuration_ = HOVER_IMAGE_OPACITY_CHANGE_DURATION; 94 theme->hoverImageDelayDuration_ = HOVER_IMAGE_DELAY_DURATION; 95 theme->hoverImageCustomPreviewScaleDuration_ = HOVER_IMAGE_CUSTOM_PREVIEW_SCALE_DURATION; 96 theme->hoverImagePreviewDisappearDuration_ = HOVER_IMAGE_PREVIEW_DISAPPEAR_DURATION; 97 theme->previewBeforeAnimationScale_ = 0.95f; 98 theme->previewAfterAnimationScale_ = 1.1f; 99 theme->menuAnimationScale_ = 0.4f; 100 theme->menuDragAnimationScale_ = 0.95f; 101 theme->springMotionResponse_ = 0.416f; 102 theme->springMotionDampingFraction_ = 0.73f; 103 theme->contextMenuAppearDuration_ = 250; 104 theme->disappearDuration_ = 250; 105 theme->previewDisappearSpringMotionResponse_ = 0.304f; 106 theme->previewDisappearSpringMotionDampingFraction_ = 0.97f; 107 theme->filterRadius_ = Dimension(100.0f); 108 theme->previewBorderRadius_ = 16.0_vp; 109 theme->previewMenuScaleNumber_ = 0.95f; 110 std::string hasFilter = pattern->GetAttr<std::string>("menu_has_filter", "true"); 111 theme->hasFilter_ = (hasFilter == "true"); 112 theme->normalLayout_ = pattern->GetAttr<int>("menu_normal_layout", 1); 113 theme->normalPlacement_ = pattern->GetAttr<int>("menu_normal_placement", 1); 114 theme->hasBackBlur_ = pattern->GetAttr<int>("menu_back_blur", 1); 115 theme->bigFontSizeScale_ = MENU_BIG_FONT_SIZE_SCALE; 116 theme->largeFontSizeScale_ = MENU_LARGE_FONT_SIZE_SCALE_; 117 theme->maxFontSizeScale_ = MENU_MAX_FONT_SIZE_SCALE; 118 theme->textMaxLines_ = MENU_TEXT_MAX_LINES; 119 } 120 }; 121 122 ~MenuTheme() override = default; 123 GetSymbolId()124 uint32_t GetSymbolId() const 125 { 126 return symbolId_; 127 } 128 GetFilterAnimationDuration()129 int32_t GetFilterAnimationDuration() const 130 { 131 return filterAnimationDuration_; 132 } 133 GetPreviewAnimationDuration()134 int32_t GetPreviewAnimationDuration() const 135 { 136 return previewAnimationDuration_; 137 } 138 GetHoverImageSwitchToPreviewOpacityDuration()139 int32_t GetHoverImageSwitchToPreviewOpacityDuration() const 140 { 141 return hoverImageSwitchToPreviewOpacityDuration_; 142 } 143 GetHoverImageDelayDuration()144 int32_t GetHoverImageDelayDuration() const 145 { 146 return hoverImageDelayDuration_; 147 } 148 GetHoverImageCustomPreviewScaleDuration()149 int32_t GetHoverImageCustomPreviewScaleDuration() const 150 { 151 return hoverImageCustomPreviewScaleDuration_; 152 } 153 GetHoverImagePreviewDisAppearDuration()154 int32_t GetHoverImagePreviewDisAppearDuration() const 155 { 156 return hoverImagePreviewDisappearDuration_; 157 } 158 GetPreviewBeforeAnimationScale()159 float GetPreviewBeforeAnimationScale() const 160 { 161 return previewBeforeAnimationScale_; 162 } 163 GetPreviewAfterAnimationScale()164 float GetPreviewAfterAnimationScale() const 165 { 166 return previewAfterAnimationScale_; 167 } 168 GetMenuAnimationScale()169 float GetMenuAnimationScale() const 170 { 171 return menuAnimationScale_; 172 } 173 GetMenuDragAnimationScale()174 float GetMenuDragAnimationScale() const 175 { 176 return menuDragAnimationScale_; 177 } 178 GetSpringMotionResponse()179 float GetSpringMotionResponse() const 180 { 181 return springMotionResponse_; 182 } 183 GetSpringMotionDampingFraction()184 float GetSpringMotionDampingFraction() const 185 { 186 return springMotionDampingFraction_; 187 } 188 GetContextMenuAppearDuration()189 int32_t GetContextMenuAppearDuration() const 190 { 191 return contextMenuAppearDuration_; 192 } 193 GetDisappearDuration()194 int32_t GetDisappearDuration() const 195 { 196 return disappearDuration_; 197 } 198 GetPreviewDisappearSpringMotionResponse()199 float GetPreviewDisappearSpringMotionResponse() const 200 { 201 return previewDisappearSpringMotionResponse_; 202 } 203 GetPreviewDisappearSpringMotionDampingFraction()204 float GetPreviewDisappearSpringMotionDampingFraction() const 205 { 206 return previewDisappearSpringMotionDampingFraction_; 207 } 208 GetPreviewMenuScaleNumber()209 float GetPreviewMenuScaleNumber() const 210 { 211 return previewMenuScaleNumber_; 212 } 213 GetFilterRadius()214 Dimension GetFilterRadius() const 215 { 216 return filterRadius_; 217 } 218 GetPreviewBorderRadius()219 Dimension GetPreviewBorderRadius() const 220 { 221 return previewBorderRadius_; 222 } 223 GetPreviewMenuMaskColor()224 Color GetPreviewMenuMaskColor() const 225 { 226 return previewMenuMaskColor_; 227 } 228 GetBgBlurEffectEnable()229 int32_t GetBgBlurEffectEnable() const 230 { 231 return bgBlurEffectEnable_; 232 } 233 GetBgEffectSaturation()234 double GetBgEffectSaturation() const 235 { 236 return bgEffectSaturation_; 237 } 238 GetBgEffectBrightness()239 double GetBgEffectBrightness() const 240 { 241 return bgEffectBrightness_; 242 } 243 GetBgEffectRadius()244 Dimension GetBgEffectRadius() const 245 { 246 return bgEffectRadius_; 247 } 248 GetBgEffectColor()249 Color GetBgEffectColor() const 250 { 251 return bgEffectColor_; 252 } 253 GetDoubleBorderEnable()254 int32_t GetDoubleBorderEnable() const 255 { 256 return doubleBorderEnable_; 257 } 258 GetOuterBorderWidth()259 double GetOuterBorderWidth() const 260 { 261 return outerBorderWidth_; 262 } 263 GetOuterBorderRadius()264 double GetOuterBorderRadius() const 265 { 266 return outerBorderRadius_; 267 } 268 GetOuterBorderColor()269 Color GetOuterBorderColor() const 270 { 271 return outerBorderColor_; 272 } 273 GetInnerBorderWidth()274 double GetInnerBorderWidth() const 275 { 276 return innerBorderWidth_; 277 } 278 GetInnerBorderRadius()279 Dimension GetInnerBorderRadius() const 280 { 281 return innerBorderRadius_; 282 } 283 GetInnerBorderColor()284 Color GetInnerBorderColor() const 285 { 286 return innerBorderColor_; 287 } 288 GetHasFilter()289 bool GetHasFilter() const 290 { 291 return hasFilter_; 292 } 293 GetNormalLayout()294 bool GetNormalLayout() const 295 { 296 return normalLayout_; 297 } 298 GetNormalPlacement()299 bool GetNormalPlacement() const 300 { 301 return normalPlacement_; 302 } 303 GetHasBackBlur()304 bool GetHasBackBlur() const 305 { 306 return hasBackBlur_; 307 } 308 GetBigFontSizeScale()309 float GetBigFontSizeScale() const 310 { 311 return bigFontSizeScale_; 312 } 313 GetLargeFontSizeScale()314 float GetLargeFontSizeScale() const 315 { 316 return largeFontSizeScale_; 317 } 318 GetMaxFontSizeScale()319 float GetMaxFontSizeScale() const 320 { 321 return maxFontSizeScale_; 322 } 323 GetTextMaxLines()324 int32_t GetTextMaxLines() const 325 { 326 return textMaxLines_; 327 } 328 329 protected: 330 MenuTheme() = default; 331 332 private: 333 int32_t filterAnimationDuration_ = 0; 334 int32_t previewAnimationDuration_ = 0; 335 int32_t hoverImageSwitchToPreviewOpacityDuration_ = 0; 336 int32_t hoverImageDelayDuration_ = 0; 337 int32_t hoverImageCustomPreviewScaleDuration_ = 0; 338 int32_t hoverImagePreviewDisappearDuration_ = 0; 339 float previewBeforeAnimationScale_ = 1.0f; 340 float previewAfterAnimationScale_ = 1.0f; 341 float menuAnimationScale_ = 1.0f; 342 float menuDragAnimationScale_ = 1.0f; 343 float springMotionResponse_ = 0.0f; 344 float springMotionDampingFraction_ = 0.0f; 345 int32_t contextMenuAppearDuration_ = 0; 346 int32_t disappearDuration_ = 0; 347 float previewDisappearSpringMotionResponse_ = 0.0f; 348 float previewDisappearSpringMotionDampingFraction_ = 0.0f; 349 float previewMenuScaleNumber_ = 0.0f; 350 Dimension filterRadius_; 351 Dimension previewBorderRadius_; 352 Color previewMenuMaskColor_; 353 int32_t bgBlurEffectEnable_ = 0; 354 double bgEffectSaturation_ = 1.0f; 355 double bgEffectBrightness_ = 1.0f; 356 Dimension bgEffectRadius_; 357 Color bgEffectColor_ = Color::TRANSPARENT; 358 int32_t doubleBorderEnable_ = 0; 359 double outerBorderWidth_ = 1.0f; 360 double outerBorderRadius_ = 19.75f; 361 Color outerBorderColor_ = Color::TRANSPARENT; 362 double innerBorderWidth_ = 1.0f; 363 Dimension innerBorderRadius_; 364 Color innerBorderColor_ = Color::TRANSPARENT; 365 bool hasFilter_ = true; 366 uint32_t symbolId_; 367 bool normalLayout_ = true; 368 bool normalPlacement_ = true; 369 bool hasBackBlur_ = true; 370 float bigFontSizeScale_ = 1.75f; 371 float largeFontSizeScale_ = 2.0f; 372 float maxFontSizeScale_ = 3.2f; 373 int32_t textMaxLines_ = std::numeric_limits<int32_t>::max(); 374 }; 375 376 } // namespace OHOS::Ace::NG 377 378 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_MENU_MENU_THEME_H 379