• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
23 namespace OHOS::Ace::NG {
24 namespace {
25     constexpr static int32_t CLICKABLE_AREA_VIEW_INDEX = 2;
26     constexpr static int32_t EXPANDABLE_AREA_VIEW_INDEX = 3;
27 }
28 class ACE_EXPORT MenuItemLayoutAlgorithm : public BoxLayoutAlgorithm {
29     DECLARE_ACE_TYPE(MenuItemLayoutAlgorithm, BoxLayoutAlgorithm);
30 
31 public:
isOption_(isOption)32     MenuItemLayoutAlgorithm(bool isOption = false) : isOption_(isOption) {}
33     ~MenuItemLayoutAlgorithm() override = default;
34 
35     void Measure(LayoutWrapper* layoutWrapper) override;
36     void Layout(LayoutWrapper* layoutWrapper) override;
37 
38 private:
39     void CheckNeedMatchParent(LayoutWrapper* layoutWrapper,
40         std::optional<LayoutConstraintF>& layoutConstraint);
41     void CheckUserHeight(LayoutWrapper* layoutWrapper);
42     void MeasureItemViews(LayoutConstraintF& childConstraint,
43         std::optional<LayoutConstraintF>& layoutConstraint,
44         LayoutWrapper* layoutWrapper);
45     void MeasureRow(LayoutWrapper* layoutWrapper, const RefPtr<LayoutWrapper>& row,
46         const LayoutConstraintF& constraint);
47     void CheckNeedExpandContent(LayoutWrapper* layoutWrapper, LayoutConstraintF& childConstraint);
48     void UpdateSelfSize(LayoutWrapper* layoutWrapper, float width, float itemHeight, float expandableHeight);
49     float GetDividerStroke(LayoutWrapper* layoutWrapper);
50     float GetBordersHeight(LayoutWrapper* layoutWrapper);
51     float GetMenuItemVerticalPadding();
52     std::optional<float> GetIdealWidth(LayoutWrapper* layoutWrapper);
53     void UpdateIconMargin(LayoutWrapper* layoutWrapper);
54     void UpdateIdealSize(LayoutWrapper* layoutWrapper, const RefPtr<LayoutProperty>& props,
55         std::optional<LayoutConstraintF>& layoutConstraint);
56     void MeasureMenuItem(LayoutWrapper* layoutWrapper, const RefPtr<SelectTheme>& selectTheme,
57         const RefPtr<LayoutProperty>& props, std::optional<LayoutConstraintF>& layoutConstraint);
58     void MeasureOption(LayoutWrapper* layoutWrapper, const RefPtr<SelectTheme>& selectTheme,
59         const RefPtr<LayoutProperty>& props, const std::optional<LayoutConstraintF>& layoutConstraint);
60     float CalcRowTopSpace(float rowsHeight, float itemHeight, LayoutWrapper* layoutWrapper,
61         float leftOrRightRowHeight);
62     void LayoutMenuItem(LayoutWrapper* layoutWrapper, const RefPtr<LayoutProperty>& props);
63     void LayoutOption(LayoutWrapper* layoutWrapper, const RefPtr<LayoutProperty>& props);
64     void ExtendTextAndRowNode(const RefPtr<LayoutWrapper>& row, const SizeF& optSize,
65         float intervall, const LayoutConstraintF& constraint);
66     float MeasureExpandableHeight(LayoutConstraintF& childConstraint, LayoutWrapper* layoutWrapper);
67     void InitPadding(const RefPtr<LayoutProperty>& props, std::optional<LayoutConstraintF>& layoutConstraint);
68     float CalcItemHeight(float leftRowHeight, float rightRowHeight);
69     void MeasureClickableArea(LayoutWrapper* layoutWrapper);
70     std::pair<float, float> MeasureRightRow(LayoutWrapper* layoutWrapper, LayoutConstraintF& childConstraint);
71     void CalcContentExpandWidth(std::optional<LayoutConstraintF>& layoutConstraint,
72         float contentWidth, float leftRowWidth, float rightRowWidth);
73 
74     float horInterval_ = 0.0f;
75     float verInterval_ = 0.0f;
76     float idealWidth_ = 0.0f;
77     float userHeight_ = 0.0f;
78     float idealHeight_ = 0.0f;
79     float emptyWidth_ = 0.0f;
80     float maxRowWidth_ = 0.0f;
81     float middleSpace_ = 0.0f;
82     float minRowWidth_ = 0.0f;
83     float minItemHeight_ = 0.0f;
84     double iconSize_ = 0.0f;
85     bool needExpandContent_ = false;
86     bool isOption_ = false;
87     PaddingPropertyF padding_;
88 
89     ACE_DISALLOW_COPY_AND_MOVE(MenuItemLayoutAlgorithm);
90 };
91 } // namespace OHOS::Ace::NG
92 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_MENU_MENU_ITEM_MENU_ITEM_LAYOUT_ALGORITHM_H
93