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_DRAG_BAR_DRAG_BAR_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DRAG_BAR_DRAG_BAR_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 { 25 26 class DragBarTheme : public virtual Theme { 27 DECLARE_ACE_TYPE(DragBarTheme, Theme); 28 29 public: 30 class Builder { 31 public: 32 Builder() = default; 33 ~Builder() = default; 34 Build(const RefPtr<ThemeConstants> & themeConstants)35 RefPtr<DragBarTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 36 { 37 RefPtr<DragBarTheme> theme = AceType::Claim(new DragBarTheme()); 38 if (!themeConstants) { 39 return theme; 40 } 41 theme->barColor_ = themeConstants->GetColor(THEME_DRAG_BAR_COLOR); 42 ParsePattern(themeConstants, theme); 43 auto themeStyle = themeConstants->GetThemeStyle(); 44 if (!themeStyle) { 45 return theme; 46 } 47 RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_DRAG_BAR); 48 if (pattern) { 49 theme->dragBarColor_ = pattern->GetAttr<Color>("drag_bar_bg_color", Color::WHITE); 50 theme->panelBgColor_ = pattern->GetAttr<Color>("panel_bg_color", Color::WHITE); 51 } else { 52 LOGW("find pattern of tab fail"); 53 } 54 return theme; 55 } 56 private: ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<DragBarTheme> & theme)57 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<DragBarTheme>& theme) const 58 { 59 RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_DRAG_BAR); 60 if (!pattern) { 61 LOGW("find pattern of drag bar fail"); 62 return; 63 } 64 theme->barColor_ = pattern->GetAttr<Color>(DRAG_BAR_COLOR, Color()); 65 } 66 }; 67 ~DragBarTheme() override = default; 68 GetBarColor()69 const Color& GetBarColor() const 70 { 71 return barColor_; 72 } 73 GetDragBarColor()74 const Color& GetDragBarColor() const 75 { 76 return dragBarColor_; 77 } 78 GetPanelBgColor()79 const Color& GetPanelBgColor() const 80 { 81 return panelBgColor_; 82 } 83 84 protected: 85 DragBarTheme() = default; 86 87 private: 88 Color barColor_; 89 Color dragBarColor_; 90 Color panelBgColor_; 91 }; 92 93 } // namespace OHOS::Ace 94 95 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DRAG_BAR_DRAG_BAR_THEME_H 96