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_MARQUEE_MARQUEE_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MARQUEE_MARQUEE_THEME_H 18 19 #include "base/geometry/dimension.h" 20 #include "core/components/common/properties/color.h" 21 #include "core/components/common/properties/text_style.h" 22 #include "core/components/theme/theme.h" 23 #include "core/components/theme/theme_constants.h" 24 #include "core/components/theme/theme_constants_defines.h" 25 26 namespace OHOS::Ace { 27 namespace { 28 constexpr Dimension MARQUEE_FONT_SIZE = 37.5_px; 29 } 30 31 /** 32 * MarqueeTheme defines color and styles of MarqueeComponent. MarqueeTheme should be built 33 * using MarqueeTheme::Builder. 34 */ 35 class MarqueeTheme : public virtual Theme { 36 DECLARE_ACE_TYPE(MarqueeTheme, Theme); 37 38 public: 39 class Builder { 40 public: 41 Builder() = default; 42 ~Builder() = default; 43 Build(const RefPtr<ThemeConstants> & themeConstants)44 RefPtr<MarqueeTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 45 { 46 RefPtr<MarqueeTheme> theme = AceType::Claim(new MarqueeTheme()); 47 if (!themeConstants) { 48 return theme; 49 } 50 51 RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_MARQUEE); 52 if (pattern) { 53 theme->textColor_ = pattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color::BLACK); 54 theme->fontSize_ = pattern->GetAttr<Dimension>("marquee_font_size", MARQUEE_FONT_SIZE); 55 } else { 56 LOGW("find pattern of marquee fail"); 57 } 58 return theme; 59 } 60 }; 61 62 ~MarqueeTheme() override = default; 63 GetTextColor()64 const Color& GetTextColor() const 65 { 66 return textColor_; 67 } 68 GetFontSize()69 const Dimension& GetFontSize() const 70 { 71 return fontSize_; 72 } 73 74 protected: 75 MarqueeTheme() = default; 76 77 private: 78 Color textColor_; 79 Dimension fontSize_; 80 }; 81 82 } // namespace OHOS::Ace 83 84 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_MARQUEE_MARQUEE_THEME_H 85