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_NG_PATTERN_SIDE_BAR_SIDE_BAR_CONTAINER_LAYOUT_ALGORITHM_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SIDE_BAR_SIDE_BAR_CONTAINER_LAYOUT_ALGORITHM_H 18 19 #include "base/memory/referenced.h" 20 #include "core/components_ng/layout/layout_algorithm.h" 21 #include "core/components_ng/layout/layout_wrapper.h" 22 #include "core/components_ng/pattern/side_bar/side_bar_container_layout_property.h" 23 24 namespace OHOS::Ace::NG { 25 26 class ACE_EXPORT SideBarContainerLayoutAlgorithm : public LayoutAlgorithm { 27 DECLARE_ACE_TYPE(SideBarContainerLayoutAlgorithm, LayoutAlgorithm); 28 29 public: 30 SideBarContainerLayoutAlgorithm() = default; 31 ~SideBarContainerLayoutAlgorithm() override = default; 32 OnReset()33 void OnReset() override {} 34 void Measure(LayoutWrapper* layoutWrapper) override; 35 void Layout(LayoutWrapper* layoutWrapper) override; 36 SetCurrentOffset(float offset)37 void SetCurrentOffset(float offset) 38 { 39 currentOffset_ = offset; 40 } 41 SetSideBarStatus(SideBarStatus sideBarStatus)42 void SetSideBarStatus(SideBarStatus sideBarStatus) 43 { 44 sideBarStatus_ = sideBarStatus; 45 } 46 SetRealSideBarWidth(float realSideBarWidth)47 void SetRealSideBarWidth(float realSideBarWidth) 48 { 49 realSideBarWidth_ = realSideBarWidth; 50 } 51 GetRealSideBarWidth()52 float GetRealSideBarWidth() const 53 { 54 return realSideBarWidth_; 55 } 56 SetNeedInitRealSideBarWidth(bool needInitRealSideBarWidth)57 void SetNeedInitRealSideBarWidth(bool needInitRealSideBarWidth) 58 { 59 needInitRealSideBarWidth_ = needInitRealSideBarWidth; 60 } 61 GetRealSideBarHeight()62 float GetRealSideBarHeight() const 63 { 64 return realSideBarHeight_; 65 } 66 GetSideBarOffset()67 OffsetF GetSideBarOffset() const 68 { 69 return sideBarOffset_; 70 } 71 72 private: 73 void MeasureControlButton(const RefPtr<SideBarContainerLayoutProperty>& layoutProperty, 74 const RefPtr<LayoutWrapper>& buttonLayoutWrapper, float parentWidth); 75 void MeasureSideBar(const RefPtr<SideBarContainerLayoutProperty>& layoutProperty, 76 const RefPtr<LayoutWrapper>& sideBarLayoutWrapper); 77 void MeasureSideBarContent(const RefPtr<SideBarContainerLayoutProperty>& layoutProperty, 78 const RefPtr<LayoutWrapper>& contentLayoutWrapper, float parentWidth); 79 void LayoutControlButton(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& buttonLayoutWrapper); 80 void LayoutSideBar(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& sideBarLayoutWrapper); 81 void LayoutSideBarContent(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& contentLayoutWrapper); 82 void InitRealSideBarWidth(LayoutWrapper* layoutWrapper, float parentWidth); 83 84 float currentOffset_ = 0.0f; 85 float realSideBarWidth_ = 0.0f; 86 float realSideBarHeight_ = 0.0f; 87 SideBarStatus sideBarStatus_ = SideBarStatus::SHOW; 88 bool needInitRealSideBarWidth_ = true; 89 OffsetF sideBarOffset_; 90 91 ACE_DISALLOW_COPY_AND_MOVE(SideBarContainerLayoutAlgorithm); 92 }; 93 94 } // namespace OHOS::Ace::NG 95 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_SIDE_BAR_SIDE_BAR_CONTAINER_LAYOUT_ALGORITHM_H 96