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_DIVIDER_DIVIDER_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DIVIDER_DIVIDER_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 DividerTheme : public virtual Theme {
27     DECLARE_ACE_TYPE(DividerTheme, Theme);
28 
29 public:
30     class Builder {
31     public:
32         Builder() = default;
33         ~Builder() = default;
34 
Build(const RefPtr<ThemeConstants> & themeConstants)35         RefPtr<DividerTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
36         {
37             RefPtr<DividerTheme> theme = AceType::Claim(new DividerTheme());
38             if (!themeConstants) {
39                 return theme;
40             }
41             RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_DIVIDER);
42             if (pattern) {
43                 theme->color_ = pattern->GetAttr<Color>("divider_color", Color::BLACK);
44                 theme->stokeWidth_ = pattern->GetAttr<Dimension>("divider_stroke_width", 1.0_vp);
45             } else {
46                 LOGW("find pattern of divider fail");
47             }
48             return theme;
49         }
50     };
51 
52     ~DividerTheme() override = default;
53 
GetColor()54     const Color& GetColor() const
55     {
56         return color_;
57     }
58 
GetStokeWidth()59     const Dimension& GetStokeWidth() const
60     {
61         return stokeWidth_;
62     }
63 
64 protected:
65     DividerTheme() = default;
66 
67 private:
68     Color color_;
69     Dimension stokeWidth_;
70 };
71 
72 } // namespace OHOS::Ace
73 
74 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DIVIDER_DIVIDER_THEME_H
75