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_PANEL_PANEL_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PANEL_PANEL_COMPONENT_H 18 19 #include <functional> 20 21 #include "core/components/box/box_component.h" 22 #include "core/event/ace_event_handler.h" 23 #include "core/pipeline/base/composed_component.h" 24 25 namespace OHOS::Ace { 26 27 using BuildPanelImpl = std::function<void()>; 28 29 // PanelController is used in PanelElement to build a panel 30 class PanelController : public virtual AceType { 31 DECLARE_ACE_TYPE(PanelController, AceType); 32 33 public: ShowPanel()34 void ShowPanel() 35 { 36 if (showPanelImpl_) { 37 showPanelImpl_(); 38 } 39 } 40 ClosePanel()41 void ClosePanel() 42 { 43 if (closePanelImpl_) { 44 closePanelImpl_(); 45 } 46 } 47 SetShowPanelImpl(const BuildPanelImpl & showPanelImpl)48 void SetShowPanelImpl(const BuildPanelImpl& showPanelImpl) 49 { 50 showPanelImpl_ = showPanelImpl; 51 } 52 SetClosePanelImpl(const BuildPanelImpl & closePanelImpl)53 void SetClosePanelImpl(const BuildPanelImpl& closePanelImpl) 54 { 55 closePanelImpl_ = closePanelImpl; 56 } 57 58 private: 59 BuildPanelImpl showPanelImpl_; 60 BuildPanelImpl closePanelImpl_; 61 }; 62 63 class ACE_EXPORT PanelComponent : public ComposedComponent { 64 DECLARE_ACE_TYPE(PanelComponent, ComposedComponent); 65 66 public: PanelComponent(const ComposeId & id,const std::string & name,const RefPtr<Component> & child)67 PanelComponent(const ComposeId& id, const std::string& name, const RefPtr<Component>& child) 68 : ComposedComponent(id, name, child) 69 { 70 panelController_ = AceType::MakeRefPtr<PanelController>(); 71 } 72 PanelComponent(const ComposeId & id,const std::string & name)73 PanelComponent(const ComposeId& id, const std::string& name) : ComposedComponent(id, name) 74 { 75 panelController_ = AceType::MakeRefPtr<PanelController>(); 76 } 77 78 ~PanelComponent() override = default; 79 80 RefPtr<Element> CreateElement() override; 81 GetPanelController()82 const RefPtr<PanelController>& GetPanelController() const 83 { 84 return panelController_; 85 } 86 GetOnSizeChanged()87 const EventMarker& GetOnSizeChanged() const 88 { 89 return onSizeChanged_; 90 } 91 SetOnSizeChanged(const EventMarker & value)92 void SetOnSizeChanged(const EventMarker& value) 93 { 94 onSizeChanged_ = value; 95 } 96 GetPanelMode()97 PanelMode GetPanelMode() const 98 { 99 return mode_; 100 } 101 SetPanelMode(PanelMode mode)102 void SetPanelMode(PanelMode mode) 103 { 104 mode_ = mode; 105 } 106 GetPanelType()107 PanelType GetPanelType() const 108 { 109 return type_; 110 } 111 SetPanelType(PanelType type)112 void SetPanelType(PanelType type) 113 { 114 type_ = type; 115 } 116 SetBoxStyle(const RefPtr<BoxComponent> & style)117 void SetBoxStyle(const RefPtr<BoxComponent>& style) 118 { 119 boxStyle_ = style; 120 } 121 GetBoxStyle()122 RefPtr<BoxComponent> GetBoxStyle() const 123 { 124 return boxStyle_; 125 } 126 HasBoxStyle()127 bool HasBoxStyle() const 128 { 129 return hasBoxStyle_; 130 } 131 SetHasBoxStyle(bool hasBoxStyle)132 void SetHasBoxStyle(bool hasBoxStyle) 133 { 134 hasBoxStyle_ = hasBoxStyle; 135 } 136 HasDecorationStyle()137 bool HasDecorationStyle() const 138 { 139 return hasDecorationStyle_; 140 } 141 SetHasDecorationStyle(bool hasDecorationStyle)142 void SetHasDecorationStyle(bool hasDecorationStyle) 143 { 144 hasDecorationStyle_ = hasDecorationStyle; 145 } 146 HasDragBar()147 bool HasDragBar() const 148 { 149 return hasDragBar_; 150 } 151 SetHasDragBar(bool hasDragBar)152 void SetHasDragBar(bool hasDragBar) 153 { 154 hasDragBar_ = hasDragBar; 155 } 156 HasBackgroundColor()157 bool HasBackgroundColor() const 158 { 159 return hasBackgroundColor_; 160 } 161 SetHasBackgroundColor(bool hasBackground)162 void SetHasBackgroundColor(bool hasBackground) 163 { 164 hasBackgroundColor_ = hasBackground; 165 } 166 HasBorderStyle()167 bool HasBorderStyle() const 168 { 169 return hasBorderStyle_; 170 } 171 SetHasBorderStyle(bool borderStyle)172 void SetHasBorderStyle(bool borderStyle) 173 { 174 hasBorderStyle_ = borderStyle; 175 } 176 GetMiniHeight()177 const std::pair<Dimension, bool>& GetMiniHeight() const 178 { 179 return miniHeight_; 180 } 181 SetMiniHeight(const std::pair<Dimension,bool> & miniHeight)182 void SetMiniHeight(const std::pair<Dimension, bool>& miniHeight) 183 { 184 miniHeight_ = miniHeight; 185 } 186 GetHalfHeight()187 const std::pair<Dimension, bool>& GetHalfHeight() const 188 { 189 return halfHeight_; 190 } 191 SetHalfHeight(const std::pair<Dimension,bool> & halfHeight)192 void SetHalfHeight(const std::pair<Dimension, bool>& halfHeight) 193 { 194 halfHeight_ = halfHeight; 195 } 196 GetFullHeight()197 const std::pair<Dimension, bool>& GetFullHeight() const 198 { 199 return fullHeight_; 200 } 201 SetFullHeight(const std::pair<Dimension,bool> & fullHeight)202 void SetFullHeight(const std::pair<Dimension, bool>& fullHeight) 203 { 204 fullHeight_ = fullHeight; 205 } 206 207 private: 208 PanelType type_ = PanelType::FOLDABLE_BAR; 209 PanelMode mode_ = PanelMode::FULL; 210 RefPtr<PanelController> panelController_; 211 EventMarker onSizeChanged_; 212 213 RefPtr<BoxComponent> boxStyle_; 214 bool hasBoxStyle_ = false; 215 bool hasDecorationStyle_ = false; 216 bool hasDragBar_ = true; 217 bool hasBackgroundColor_ = false; 218 bool hasBorderStyle_ = false; 219 std::pair<Dimension, bool> miniHeight_ = { 0.0_vp, false }; 220 std::pair<Dimension, bool> halfHeight_ = { 0.0_vp, false }; 221 std::pair<Dimension, bool> fullHeight_ = { 0.0_vp, false }; 222 }; 223 224 } // namespace OHOS::Ace 225 226 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PANEL_PANEL_COMPONENT_H 227