1 /* 2 * Copyright (c) 2023 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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MENU_MENU_ITEM_MENU_ITEM_LAYOUT_ALGORITHM_H 16 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MENU_MENU_ITEM_MENU_ITEM_LAYOUT_ALGORITHM_H 17 18 #include "base/memory/referenced.h" 19 #include "core/components/select/select_theme.h" 20 #include "core/components_ng/layout/box_layout_algorithm.h" 21 #include "core/components_ng/layout/layout_wrapper.h" 22 #include "core/components_ng/pattern/select/select_model.h" 23 24 namespace OHOS::Ace::NG { 25 namespace { 26 constexpr static int32_t CLICKABLE_AREA_VIEW_INDEX = 2; 27 constexpr static int32_t EXPANDABLE_AREA_VIEW_INDEX = 3; 28 } 29 class ACE_EXPORT MenuItemLayoutAlgorithm : public BoxLayoutAlgorithm { 30 DECLARE_ACE_TYPE(MenuItemLayoutAlgorithm, BoxLayoutAlgorithm); 31 32 public: isOption_(isOption)33 MenuItemLayoutAlgorithm(bool isOption = false) : isOption_(isOption) {} MenuItemLayoutAlgorithm(bool isOption,bool show)34 MenuItemLayoutAlgorithm(bool isOption, bool show) 35 : isOption_(isOption), showDefaultSelectedIcon_(show) 36 {} 37 ~MenuItemLayoutAlgorithm() override = default; 38 39 void Measure(LayoutWrapper* layoutWrapper) override; 40 void Layout(LayoutWrapper* layoutWrapper) override; 41 42 private: 43 void RemoveParentRestrictionsForFixIdeal( 44 const RefPtr<LayoutProperty> layoutProperty, LayoutConstraintF& childConstraint); 45 void CheckNeedMatchParent(LayoutWrapper* layoutWrapper, 46 std::optional<LayoutConstraintF>& layoutConstraint); 47 void CheckUserHeight(LayoutWrapper* layoutWrapper); 48 void MeasureItemViews(LayoutConstraintF& childConstraint, 49 std::optional<LayoutConstraintF>& layoutConstraint, 50 LayoutWrapper* layoutWrapper); 51 void MeasureRow(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& row, 52 const LayoutConstraintF& constraint); 53 void CheckNeedExpandContent(LayoutWrapper* layoutWrapper, LayoutConstraintF& childConstraint); 54 void UpdateSelfSize(LayoutWrapper* layoutWrapper, float width, float itemHeight, float expandableHeight); 55 float GetDividerStroke(LayoutWrapper* layoutWrapper); 56 float GetBordersHeight(LayoutWrapper* layoutWrapper); 57 float GetMenuItemVerticalPadding(LayoutWrapper* layoutWrapper); 58 std::optional<float> GetIdealWidth(LayoutWrapper* layoutWrapper); 59 void UpdateIconMargin(LayoutWrapper* layoutWrapper); 60 void UpdateIdealSize(LayoutWrapper* layoutWrapper, const RefPtr<LayoutProperty>& props, 61 std::optional<LayoutConstraintF>& layoutConstraint); 62 void MeasureMenuItem(LayoutWrapper* layoutWrapper, const RefPtr<SelectTheme>& selectTheme, 63 const RefPtr<LayoutProperty>& props, std::optional<LayoutConstraintF>& layoutConstraint); 64 void MeasureOption(LayoutWrapper* layoutWrapper, const RefPtr<SelectTheme>& selectTheme, 65 const RefPtr<LayoutProperty>& props, const std::optional<LayoutConstraintF>& layoutConstraint); 66 float CalcRowTopSpace(float rowsHeight, float itemHeight, LayoutWrapper* layoutWrapper, 67 float leftOrRightRowHeight); 68 void LayoutMenuItem(LayoutWrapper* layoutWrapper, const RefPtr<LayoutProperty>& props); 69 void LayoutOption(LayoutWrapper* layoutWrapper, const RefPtr<LayoutProperty>& props); 70 void ExtendTextAndRowNode(const RefPtr<LayoutWrapper>& row, const SizeF& optSize, 71 float intervall, const LayoutConstraintF& constraint); 72 float MeasureExpandableHeight(LayoutConstraintF& childConstraint, LayoutWrapper* layoutWrapper); 73 void InitPadding(const RefPtr<LayoutProperty>& props, std::optional<LayoutConstraintF>& layoutConstraint); 74 float CalcItemHeight(float leftRowHeight, float rightRowHeight); 75 void MeasureClickableArea(LayoutWrapper* layoutWrapper); 76 std::pair<float, float> MeasureRightRow(LayoutWrapper* layoutWrapper, LayoutConstraintF& childConstraint); 77 void CalcContentExpandWidth(std::optional<LayoutConstraintF>& layoutConstraint, 78 float contentWidth, float leftRowWidth, float rightRowWidth); 79 float CalcSelfHeight(float itemHeight, float bordersHeight); 80 81 float horInterval_ = 0.0f; 82 float verInterval_ = 0.0f; 83 float idealWidth_ = 0.0f; 84 float userHeight_ = 0.0f; 85 float idealHeight_ = 0.0f; 86 float emptyWidth_ = 0.0f; 87 float maxRowWidth_ = 0.0f; 88 float middleSpace_ = 0.0f; 89 float minRowWidth_ = 0.0f; 90 float minItemHeight_ = 0.0f; 91 double iconSize_ = 0.0f; 92 bool needExpandContent_ = false; 93 bool isOption_ = false; 94 bool showDefaultSelectedIcon_ = false; 95 PaddingPropertyF padding_; 96 97 ACE_DISALLOW_COPY_AND_MOVE(MenuItemLayoutAlgorithm); 98 }; 99 } // namespace OHOS::Ace::NG 100 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MENU_MENU_ITEM_MENU_ITEM_LAYOUT_ALGORITHM_H 101