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_CLOCK_CLOCK_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CLOCK_CLOCK_THEME_H
18 
19 #include "base/resource/internal_resource.h"
20 #include "core/components/common/properties/color.h"
21 #include "core/components/theme/theme.h"
22 #include "core/components/theme/theme_constants.h"
23 #include "core/components/theme/theme_constants_defines.h"
24 
25 namespace OHOS::Ace {
26 
27 /**
28  * ClockTheme defines styles of ClockComponent. ClockTheme should be built
29  * using ClockTheme::Builder.
30  */
31 class ClockTheme : public virtual Theme {
32     DECLARE_ACE_TYPE(ClockTheme, Theme);
33 
34 public:
35     class Builder {
36     public:
37         Builder() = default;
38         ~Builder() = default;
39 
Build(const RefPtr<ThemeConstants> & themeConstants)40         RefPtr<ClockTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
41         {
42             RefPtr<ClockTheme> theme = AceType::Claim(new ClockTheme());
43             if (!themeConstants) {
44                 return theme;
45             }
46 
47             RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_CLOCK);
48             if (!pattern) {
49                 LOGW("find pattern of clock fail");
50                 return theme;
51             }
52             theme->defaultSize_ = pattern->GetAttr<Dimension>("clock_default_size", 0.0_vp);
53             return theme;
54         }
55     };
56 
57     ~ClockTheme() override = default;
58 
GetDefaultSize()59     const Dimension& GetDefaultSize() const
60     {
61         return defaultSize_;
62     }
63 
64 protected:
65     ClockTheme() = default;
66 
67 private:
68     Dimension defaultSize_;
69 };
70 
71 } // namespace OHOS::Ace
72 
73 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_CLOCK_CLOCK_THEME_H
74