1 /* 2 * Copyright (c) 2021 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_LIST_GRID_LAYOUT_MANAGER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_GRID_LAYOUT_MANAGER_H 18 19 #include "core/components/list/layout_manager.h" 20 #include "core/components/list/render_list.h" 21 #include "core/components/scroll/scrollable.h" 22 23 namespace OHOS::Ace { 24 25 typedef std::map<KeyDirection, int32_t> RelationMap; 26 typedef std::map<int32_t, RelationMap> ChildRelationsMap; 27 28 class GridLayoutManager : public LayoutManager { 29 DECLARE_ACE_TYPE(GridLayoutManager, LayoutManager); 30 31 public: 32 explicit GridLayoutManager(RenderList& renderList); 33 ~GridLayoutManager() override = default; 34 35 void Update() override; 36 37 void RefreshLayout() override; 38 39 void PerformLayout() override; 40 41 int32_t focusMove(KeyDirection direction) override; 42 43 void MoveItemToViewPort(double position) override; 44 45 void LayoutToItem(int32_t toIndex) override; 46 47 void LayoutMore(double incDistance) override; 48 49 private: 50 LayoutParam MakeInnerLayoutParam(int32_t columnSpan) const; 51 52 void CalculateAxisSize(); 53 54 // Sets child position, the mainAxis does not contain the offset. 55 void SetChildPosition(const RefPtr<RenderNode>& child, double mainSize, int32_t gridPos, int32_t columnSpan); 56 57 bool CalculateStartPosition(double& start); 58 59 void ShowItemFocusAnimation(); 60 61 void CalculateCachedRange( 62 int32_t viewBegin, int32_t viewEnd, int32_t cachedCount, int32_t& cachedBegin, int32_t& cachedEnd) override; 63 64 void RequestMoreItemsIfNeeded(int32_t viewBegin, int32_t viewEnd) override; 65 66 int32_t cachedCount_ = 1; 67 int32_t maxCount_ = 0; 68 69 Offset offset_; 70 RefPtr<Scrollable> scrollable_; 71 72 double mainSize_ = 0.0; 73 double crossSize_ = 0.0; 74 double gridLen_ = 0.0; 75 double gridWidth_ = -1.0; 76 double gridHeight_ = -1.0; 77 int32_t columnCount_ = 0; 78 int32_t columnExtent_ = 0; 79 bool updateFlag_ = false; 80 81 RenderList& renderList_; 82 }; 83 84 } // namespace OHOS::Ace 85 86 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_LIST_GRID_LAYOUT_MANAGER_H 87