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_PIECE_PIECE_COMPONENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PIECE_PIECE_COMPONENT_H
18 
19 #include "base/resource/internal_resource.h"
20 #include "core/components_v2/common/common_def.h"
21 #include "core/components/common/properties/border.h"
22 #include "core/components/common/properties/edge.h"
23 #include "core/components/flex/flex_component.h"
24 #include "core/components/piece/piece_element.h"
25 #include "core/components/text/text_component.h"
26 #include "core/pipeline/base/component.h"
27 #include "core/pipeline/base/sole_child_component.h"
28 #include "core/components/declaration/piece/piece_declaration.h"
29 #include "frameworks/core/components/piece/piece_theme.h"
30 
31 namespace OHOS::Ace {
32 
33 enum class IconPosition {
34     Start = 0,
35     End,
36 };
37 
38 class ACE_EXPORT PieceComponent : public SoleChildComponent {
39     DECLARE_ACE_TYPE(PieceComponent, SoleChildComponent);
40 
41 public:
42     PieceComponent();
43     ~PieceComponent() override = default;
44 
45     RefPtr<Element> CreateElement() override;
46     RefPtr<RenderNode> CreateRenderNode() override;
47 
48     RefPtr<Component> BuildChild();
49 
50     const std::string& GetContent() const;
51     void SetContent(const std::string& content);
52 
53     const std::string& GetIcon() const;
54     void SetIcon(const std::string& icon);
55 
56     const TextStyle& GetTextStyle() const;
57     void SetTextStyle(const TextStyle& textStyle);
58 
59     const Dimension& GetInterval() const;
60     void SetInterval(const Dimension& interval);
61 
62     InternalResource::ResourceId GetIconResource() const;
63     void SetIconResource(InternalResource::ResourceId iconResource);
64 
65     const Dimension& GetIconSize() const;
66     void SetIconSize(const Dimension& iconSize);
67 
68     const EventMarker& GetOnDelete() const;
69     void SetOnDelete(const EventMarker& onDelete);
70 
71     bool ShowDelete() const;
72     void SetShowDelete(bool showDelete);
73 
74     const Edge& GetMargin() const;
75     void SetMargin(const Edge& margin);
76 
77     const Border& GetBorder() const;
78     void SetBorder(const Border& border);
79 
80     const Color& GetHoverColor() const;
81     void SetHoverColor(const Color& hoverColor);
82 
83     const Color& GetBackGroundColor() const;
84     void SetBackGroundColor(const Color& hoverColor);
85 
86     void SetDeclaration(const RefPtr<PieceDeclaration>& declaration);
87 
GetIconPosition()88     IconPosition GetIconPosition() const
89     {
90         return iconPosition_;
91     }
SetIconPosition(IconPosition iconPosition)92     void SetIconPosition(IconPosition iconPosition)
93     {
94         iconPosition_ = iconPosition;
95     }
96 
97     void SetImage(RefPtr<RowComponent>& row);
98     void SetText(RefPtr<RowComponent>& row);
99     void InitializeStyle(RefPtr<PieceTheme>& theme);
100 
101 private:
102     IconPosition iconPosition_ = IconPosition::End;
103     RefPtr<PieceDeclaration> declaration_;
104 };
105 
106 } // namespace OHOS::Ace
107 
108 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PIECE_PIECE_COMPONENT_H
109