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_SIDE_BAR_CONTAINER_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SIDE_BAR_CONTAINER_COMPONENT_H 18 19 #include "base/geometry/dimension.h" 20 #include "core/components/stack/stack_component.h" 21 #include "core/components/declaration/side_bar/side_bar_declaration.h" 22 #include "core/components_v2/common/common_def.h" 23 24 namespace OHOS::Ace { 25 enum class SideStatus { 26 SHOW, 27 HIDDEN, 28 CHANGING, 29 AUTO, 30 }; 31 32 class ACE_EXPORT SideBarContainerComponent : public StackComponent { 33 DECLARE_ACE_TYPE(SideBarContainerComponent, StackComponent); 34 public: 35 ACE_DEFINE_COMPONENT_EVENT(OnChange, void(bool)); 36 37 explicit SideBarContainerComponent(const std::list<RefPtr<Component>>& children); 38 ~SideBarContainerComponent() override = default; 39 40 RefPtr<RenderNode> CreateRenderNode() override; 41 RefPtr<Element> CreateElement() override; 42 void Build(); 43 SetShowSideBar(bool isShow)44 void SetShowSideBar(bool isShow) 45 { 46 if (isShow) { 47 sideStatus_ = SideStatus::SHOW; 48 } else { 49 sideStatus_ = SideStatus::HIDDEN; 50 } 51 isShow_ = isShow; 52 } 53 GetSideBarStatus()54 SideStatus GetSideBarStatus() const 55 { 56 return sideStatus_; 57 } 58 SetSideBarContainerType(SideBarContainerType style)59 void SetSideBarContainerType(SideBarContainerType style) 60 { 61 declaration_->SetSideBarContainerType(style); 62 } 63 GetSideBarContainerType()64 SideBarContainerType GetSideBarContainerType() 65 { 66 return declaration_->GetSideBarContainerType(); 67 } 68 SetShowControlButton(bool isShow)69 void SetShowControlButton(bool isShow) 70 { 71 declaration_->SetShowControlButton(isShow); 72 } 73 GetShowControlButton()74 bool GetShowControlButton() 75 { 76 return declaration_->IsShowControlButton(); 77 } 78 79 void SetButtonWidth(double width); 80 81 void SetButtonHeight(double height); 82 83 double GetButtonWidth() const; 84 85 double GetButtonHeight() const; 86 87 double GetButtonTop() const; 88 89 double GetButtonLeft() const; 90 91 void SetShowIcon(const std::string& path); 92 93 std::string& GetShowIcon() const; 94 95 void SetHiddenIcon(const std::string& path); 96 97 std::string& GetHiddenIcon() const; 98 99 void SetSwitchIcon(const std::string& path); 100 101 std::string& GetSwitchIcon() const; 102 103 void SetButtonLeft(double left); 104 105 void SetButtonTop(double top); 106 107 void SetClickedFunction(std::function<void()>&& clickCallback); 108 SetSideBarMaxWidth(const Dimension & max)109 void SetSideBarMaxWidth(const Dimension& max) 110 { 111 sidebarMaxWidth_ = max; 112 } 113 SetSideBarMinWidth(const Dimension & min)114 void SetSideBarMinWidth(const Dimension& min) 115 { 116 sidebarMinWidth_ = min; 117 } 118 GetSideBarMaxWidth()119 const Dimension& GetSideBarMaxWidth() 120 { 121 return sidebarMaxWidth_; 122 } 123 GetSideBarMinWidth()124 const Dimension& GetSideBarMinWidth() 125 { 126 return sidebarMinWidth_; 127 } 128 SetSideBarWidth(const Dimension & width)129 void SetSideBarWidth(const Dimension& width) 130 { 131 isCustomDefineWidth_ = true; 132 sidebarWidth_ = width; 133 } 134 GetSideBarWidth()135 const Dimension& GetSideBarWidth() 136 { 137 return sidebarWidth_; 138 } 139 IsSideBarwidthDefined()140 bool IsSideBarwidthDefined() 141 { 142 return isCustomDefineWidth_; 143 } 144 GetIsShow()145 bool GetIsShow() const 146 { 147 return isShow_; 148 } 149 SetAutoHide(bool autoHide)150 void SetAutoHide(bool autoHide) 151 { 152 autoHide_ = autoHide; 153 } 154 GetAutoHide()155 bool GetAutoHide() const 156 { 157 return autoHide_; 158 } 159 SetSideBarPosition(SideBarPosition sideBarPosition)160 void SetSideBarPosition(SideBarPosition sideBarPosition) 161 { 162 sideBarPosition_ = sideBarPosition; 163 } 164 GetSideBarPositon()165 SideBarPosition GetSideBarPositon() const 166 { 167 return sideBarPosition_; 168 } 169 170 private: 171 RefPtr<Component> BuildButton(); 172 173 std::function<void()> buttonClick_; 174 RefPtr<SideBarDeclaration> declaration_; 175 Dimension sidebarWidth_ = 200.0_vp; 176 Dimension sidebarMinWidth_ = 200.0_vp; 177 Dimension sidebarMaxWidth_ = 280.0_vp; 178 bool isCustomDefineWidth_ = false; 179 bool isShow_ = true; 180 SideStatus sideStatus_ = SideStatus::AUTO; 181 bool autoHide_ = true; 182 SideBarPosition sideBarPosition_ = SideBarPosition::START; 183 }; 184 185 } // namespace OHOS::Ace 186 187 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_SIDE_BAR_CONTAINER_COMPONENT_H