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_MENU_MENU_LAYOUT_ALGORITHM_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MENU_MENU_LAYOUT_ALGORITHM_H 18 19 #include <list> 20 21 #include "base/geometry/ng/offset_t.h" 22 #include "base/memory/referenced.h" 23 #include "core/components_ng/layout/box_layout_algorithm.h" 24 #include "core/components_ng/layout/layout_algorithm.h" 25 26 namespace OHOS::Ace::NG { 27 class MenuLayoutAlgorithm : public BoxLayoutAlgorithm { 28 DECLARE_ACE_TYPE(MenuLayoutAlgorithm, BoxLayoutAlgorithm) 29 public: 30 MenuLayoutAlgorithm() = default; 31 ~MenuLayoutAlgorithm() override = default; 32 33 // override measureSelf and measureChildren. 34 void Measure(LayoutWrapper* layoutWrapper) override; 35 36 void Layout(LayoutWrapper* layoutWrapper) override; 37 38 protected: 39 float VerticalLayout(const SizeF& size, float clickPosition); 40 float HorizontalLayout(const SizeF& size, float clickPosition, bool IsSelectMenu = false); 41 42 OffsetF position_; 43 44 private: 45 void Initialize(LayoutWrapper* layoutWrapper); 46 LayoutConstraintF CreateChildConstraint(LayoutWrapper* layoutWrapper); 47 void UpdateConstraintWidth(LayoutWrapper* layoutWrapper, LayoutConstraintF& constraint); 48 void UpdateConstraintHeight(LayoutWrapper* layoutWrapper, LayoutConstraintF& constraint); 49 void UpdateConstraintBaseOnOptions(LayoutWrapper* layoutWrapper, LayoutConstraintF& constraint); 50 void UpdateOptionConstraint(std::list<RefPtr<LayoutWrapper>>& options, float width); 51 void UpdateConstraintBaseOnMenuItems(LayoutWrapper* layoutWrapper, LayoutConstraintF& constraint); 52 53 void LayoutSubMenu(LayoutWrapper* layoutWrapper); 54 float VerticalLayoutSubMenu(const SizeF& size, float position, const SizeF& menuItemSize); 55 float HorizontalLayoutSubMenu(const SizeF& size, float position, const SizeF& menuItemSize); 56 57 float GetChildrenMaxWidth(LayoutWrapper* layoutWrapper, const LayoutConstraintF& layoutConstraint); 58 59 // get option LayoutWrapper for measure get max width 60 std::list<RefPtr<LayoutWrapper>> GetOptionsLayoutWrappper(LayoutWrapper* layoutWrapper); 61 62 SizeF wrapperSize_; 63 64 // current page offset relative to window. 65 OffsetF pageOffset_; 66 float topSpace_ = 0.0f; 67 float bottomSpace_ = 0.0f; 68 float leftSpace_ = 0.0f; 69 float rightSpace_ = 0.0f; 70 71 float margin_ = 0.0f; 72 float optionPadding_ = 0.0f; 73 74 ACE_DISALLOW_COPY_AND_MOVE(MenuLayoutAlgorithm); 75 }; 76 } // namespace OHOS::Ace::NG 77 78 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MENU_MENU_LAYOUT_ALGORITHM_H 79