1 /*
2  * Copyright (c) 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_DECLARATION_SIDE_BAR_DECLARATION_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SIDE_BAR_DECLARATION_H
18 
19 #include "core/components/declaration/common/declaration.h"
20 
21 namespace OHOS::Ace {
22 struct SideBarContainerAttribute : Attribute {
23     bool isShow = true;
24     SideBarContainerType style = SideBarContainerType::EMBED;
25     bool isShowButton = true;
26     double left = 16.0;
27     double top = 48.0;
28     double sidebarWidth = 200.0;
29     double width = 32.0;
30     double height = 32.0;
31     std::string exicon;
32     std::string changing;
33     std::string inicon;
34 };
35 
36 struct RegionEvent : Event {
37     EventMarker clickEventId = EventMarker("-1");
38 };
39 
40 class SideBarDeclaration : public Declaration {
41     DECLARE_ACE_TYPE(SideBarDeclaration, Declaration);
42 
43 public:
44     SideBarDeclaration() = default;
45     ~SideBarDeclaration() override = default;
46 
IsShowSideBar()47     bool IsShowSideBar() const
48     {
49         auto& attribute = static_cast<SideBarContainerAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
50         return attribute.isShow;
51     }
52 
SetShowSideBar(bool isShow)53     void SetShowSideBar(bool isShow)
54     {
55         auto& attribute = MaybeResetAttribute<SideBarContainerAttribute>(AttributeTag::SPECIALIZED_ATTR);
56         attribute.isShow = isShow;
57     }
58 
GetSideBarContainerType()59     SideBarContainerType GetSideBarContainerType() const
60     {
61         auto& attribute = static_cast<SideBarContainerAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
62         return attribute.style;
63     }
64 
SetSideBarContainerType(SideBarContainerType style)65     void SetSideBarContainerType(SideBarContainerType style)
66     {
67         auto& attribute = MaybeResetAttribute<SideBarContainerAttribute>(AttributeTag::SPECIALIZED_ATTR);
68         attribute.style = style;
69     }
70 
IsShowControlButton()71     bool IsShowControlButton() const
72     {
73         auto& attribute = static_cast<SideBarContainerAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
74         return attribute.isShowButton;
75     }
76 
SetShowControlButton(bool isShow)77     void SetShowControlButton(bool isShow)
78     {
79         auto& attribute = MaybeResetAttribute<SideBarContainerAttribute>(AttributeTag::SPECIALIZED_ATTR);
80         attribute.isShowButton = isShow;
81     }
82 
SetImageWidth(double width)83     void SetImageWidth(double width)
84     {
85         auto& attribute = MaybeResetAttribute<SideBarContainerAttribute>(AttributeTag::SPECIALIZED_ATTR);
86         attribute.width = width;
87     }
88 
GetImageWidth()89     double GetImageWidth()
90     {
91         auto& attribute = static_cast<SideBarContainerAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
92         return attribute.width;
93     }
94 
SetImageHeight(double height)95     void SetImageHeight(double height)
96     {
97         auto& attribute = MaybeResetAttribute<SideBarContainerAttribute>(AttributeTag::SPECIALIZED_ATTR);
98         attribute.height = height;
99     }
100 
GetImageHeight()101     double GetImageHeight()
102     {
103         auto& attribute = static_cast<SideBarContainerAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
104         return attribute.height;
105     }
106 
SetShowIcon(const std::string & path)107     void SetShowIcon(const std::string& path)
108     {
109         auto& attribute = MaybeResetAttribute<SideBarContainerAttribute>(AttributeTag::SPECIALIZED_ATTR);
110         attribute.exicon = std::move(path);
111     }
112 
GetShowIcon()113     std::string& GetShowIcon()
114     {
115         auto& attribute = static_cast<SideBarContainerAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
116         return attribute.exicon;
117     }
118 
SetHiddenIcon(const std::string & path)119     void SetHiddenIcon(const std::string& path)
120     {
121         auto& attribute = MaybeResetAttribute<SideBarContainerAttribute>(AttributeTag::SPECIALIZED_ATTR);
122         attribute.inicon = std::move(path);
123     }
124 
GetHiddenIcon()125     std::string& GetHiddenIcon()
126     {
127         auto& attribute = static_cast<SideBarContainerAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
128         return attribute.inicon;
129     }
130 
SetSwitchIcon(const std::string & path)131     void SetSwitchIcon(const std::string& path)
132     {
133         auto& attribute = MaybeResetAttribute<SideBarContainerAttribute>(AttributeTag::SPECIALIZED_ATTR);
134         attribute.changing = std::move(path);
135     }
136 
GetSwitchIcon()137     std::string& GetSwitchIcon()
138     {
139         auto& attribute = static_cast<SideBarContainerAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
140         return attribute.changing;
141     }
142 
GetLeft()143     double GetLeft() const
144     {
145         auto& attribute = static_cast<SideBarContainerAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
146         return attribute.left;
147     }
148 
GetTop()149     double GetTop() const
150     {
151         auto& attribute = static_cast<SideBarContainerAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
152         return attribute.top;
153     }
154 
GetSidebarWidth()155     double GetSidebarWidth() const
156     {
157         auto& attribute = static_cast<SideBarContainerAttribute&>(GetAttribute(AttributeTag::SPECIALIZED_ATTR));
158         return attribute.sidebarWidth;
159     }
160 
SetLeft(double left)161     void SetLeft(double left)
162     {
163         auto& attribute = MaybeResetAttribute<SideBarContainerAttribute>(AttributeTag::SPECIALIZED_ATTR);
164         attribute.left = left;
165     }
166 
SetTop(double top)167     void SetTop(double top)
168     {
169         auto& attribute = MaybeResetAttribute<SideBarContainerAttribute>(AttributeTag::SPECIALIZED_ATTR);
170         attribute.top = top;
171     }
172 
SetSidebarWidth(double width)173     void SetSidebarWidth(double width)
174     {
175         auto& attribute = MaybeResetAttribute<SideBarContainerAttribute>(AttributeTag::SPECIALIZED_ATTR);
176         attribute.sidebarWidth = width;
177     }
178 
GetClickedEventId()179     const EventMarker& GetClickedEventId() const
180     {
181         auto& event = static_cast<RegionEvent&>(GetEvent(EventTag::SPECIALIZED_EVENT));
182         return event.clickEventId;
183     }
184 
SetClickedFunction(std::function<void ()> && callback)185     void SetClickedFunction(std::function<void()>&& callback)
186     {
187         auto& event = MaybeResetEvent<RegionEvent>(EventTag::SPECIALIZED_EVENT);
188         event.clickEventId.SetPreFunction(std::move(callback));
189     }
190 
191 protected:
192     void InitSpecialized() override;
193 };
194 } // namespace OHOS::Ace
195 
196 #endif  // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DECLARATION_SIDE_BAR_DECLARATION_H