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_INDEXER_INDEXER_LAYOUT_ALGORITHM_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_INDEXER_INDEXER_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/indexer/indexer_layout_property.h"
23 #include "core/components_ng/property/measure_property.h"
24 
25 namespace OHOS::Ace::NG {
26 class PipelineContext;
27 
28 class ACE_EXPORT IndexerLayoutAlgorithm : public LayoutAlgorithm {
29     DECLARE_ACE_TYPE(IndexerLayoutAlgorithm, LayoutAlgorithm);
30 
31 public:
IndexerLayoutAlgorithm(int32_t itemCount_)32     IndexerLayoutAlgorithm(int32_t itemCount_) : itemCount_(itemCount_) {}
33 
GetItemHeight()34     float GetItemHeight() const
35     {
36         return itemHeight_;
37     }
38 
GetMaxContentHeight()39     float GetMaxContentHeight() const
40     {
41         return maxContentHeight_;
42     }
43 
44     void Measure(LayoutWrapper* layoutWrapper) override;
45 
46     void Layout(LayoutWrapper* layoutWrapper) override;
47 
48 private:
49     void InitializeIndexer(LayoutWrapper* layoutWrapper);
50     OffsetT<Dimension> GetPositionOfPopupNode(const RefPtr<IndexerLayoutProperty>& layoutProperty, float indexerWidth);
51     bool IsPopupAtLeft(const RefPtr<IndexerLayoutProperty>& layoutProperty, NG::AlignStyle alignment) const;
52     float GetMaxItemWidth(LayoutWrapper* layoutWrapper);
53     void MeasurePopup(LayoutWrapper* layoutWrapper, uint32_t childCount);
54     uint32_t popupSize_ = 0;
55     int32_t itemCount_ = 0;
56     float itemSize_ = 0.0f;
57     float itemWidth_ = 0.0f;
58     float itemHeight_ = 0.0f;
59     float maxContentHeight_ = 0.0f;
60 };
61 } // namespace OHOS::Ace::NG
62 
63 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_INDEXER_INDEXER_LAYOUT_ALGORITHM_H
64