1 /*
2  * Copyright (c) 2021-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_COUNTER_COUNTER_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_COUNTER_COUNTER_COMPONENT_H
18 
19 #include <string>
20 
21 #include "base/utils/utils.h"
22 #include "core/components/box/box_component.h"
23 #include "core/components/button/button_component.h"
24 #include "core/components/common/properties/color.h"
25 #include "core/components/counter/counter_theme.h"
26 #include "core/components/display/display_component.h"
27 #include "core/components/divider/divider_component.h"
28 #include "core/components/flex/flex_component.h"
29 #include "core/components/padding/padding_component.h"
30 #include "core/components/text/text_component.h"
31 #include "core/components_v2/common/common_def.h"
32 #include "core/pipeline/base/component_group.h"
33 #include "core/pipeline/base/element.h"
34 #include "core/pipeline/base/sole_child_component.h"
35 #include "core/pipeline/pipeline_context.h"
36 
37 namespace OHOS::Ace {
38 
39 class ACE_EXPORT CounterComponent : public ComponentGroup {
40     DECLARE_ACE_TYPE(CounterComponent, ComponentGroup);
41 
42 public:
CounterComponent(const std::list<RefPtr<Component>> & children)43     explicit CounterComponent(const std::list<RefPtr<Component>>& children) : ComponentGroup(children) {}
44 
45     ~CounterComponent() override = default;
46 
47     RefPtr<RenderNode> CreateRenderNode() override;
48 
49     RefPtr<Element> CreateElement() override;
50 
51     RefPtr<Component> BuildChild(const RefPtr<ThemeManager>& themeManager);
52 
53     RefPtr<DividerComponent> BuildDivider();
54 
55     void BuildControl(const RefPtr<CounterTheme>& counterTheme, const RefPtr<RowComponent>& row,
56         RefPtr<ButtonComponent>& button, std::string content, bool isLeft);
57 
58     void BuildContent(
59         const RefPtr<CounterTheme>& counterTheme, const RefPtr<RowComponent>& row, RefPtr<BoxComponent>& box);
60 
61     ACE_DEFINE_COMPONENT_PROP(ControlRadius, Dimension, 4.0_vp);
62     ACE_DEFINE_COMPONENT_PROP(ControlWidth, Dimension, 32.0_vp);
63     ACE_DEFINE_COMPONENT_PROP(Width, Dimension, 100.0_vp);
64     ACE_DEFINE_COMPONENT_PROP(Height, Dimension, 32.0_vp);
65     ACE_DEFINE_COMPONENT_PROP(State, bool, true);
66     ACE_DEFINE_COMPONENT_PROP(BackgroundColor, Color, Color::WHITE);
67 
68     ACE_DEFINE_COMPONENT_EVENT(OnInc, void());
69     ACE_DEFINE_COMPONENT_EVENT(OnDec, void());
70 
71 private:
72     RefPtr<ButtonComponent> increButtonComponent_;
73     RefPtr<ButtonComponent> decreButtonComponent_;
74     RefPtr<TextComponent> textComponent_;
75     RefPtr<DisplayComponent> displayComponent_;
76     RefPtr<CounterTheme> counterTheme_;
77     ACE_DISALLOW_COPY_AND_MOVE(CounterComponent);
78 };
79 
80 } // namespace OHOS::Ace
81 
82 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_COUNTER_COUNTER_COMPONENT_H
83