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_V2_GRID_LAYOUT_RENDER_GRID_ROW_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_GRID_LAYOUT_RENDER_GRID_ROW_H 18 19 #include "core/components_v2/grid_layout/grid_container_util_class.h" 20 #include "core/pipeline/base/component.h" 21 #include "core/pipeline/base/render_node.h" 22 23 namespace OHOS::Ace::V2 { 24 25 class RenderGridRow : public RenderNode { 26 DECLARE_ACE_TYPE(RenderGridRow, RenderNode); 27 28 struct NewLineOffset { 29 bool isValid = false; 30 int32_t newLineCount = 0; 31 int32_t offset = 0; 32 }; 33 34 public: 35 ~RenderGridRow() override = default; 36 37 static RefPtr<RenderNode> Create(); 38 static void ParseNewLineForLargeOffset(int32_t childSpan, int32_t childOffset, int32_t restColumnNum, 39 int32_t totalColumnNum, NewLineOffset& newLineOffset); 40 41 void Update(const RefPtr<Component>& component) override; 42 void PerformLayout() override; 43 void LayoutEachChild(double childWidthLimit, double childHeightLimit, double xGetter, GridSizeType sizeType, 44 int32_t columnNum); 45 46 void CalculateOffsetOfNewline(const RefPtr<RenderNode>& node, int32_t currentChildSpan, int32_t restColumnNum, 47 int32_t totalColumnNum, GridSizeType sizeType, NewLineOffset& newLineOffset) const; 48 inline int32_t GetRelativeOffset(const RefPtr<RenderNode>& node, GridSizeType sizeType) const; 49 inline int32_t GetGridColSpan(const RefPtr<RenderNode>& node, GridSizeType sizeType) const; 50 void FindGridColChild(RefPtr<RenderNode>& node) const; GetCurrentSizeType()51 GridSizeType GetCurrentSizeType() 52 { 53 return currentSizeType_; 54 } 55 56 GridRowDirection GetDirection() const; 57 RefPtr<BreakPoints> GetBreakPoints() const; 58 int32_t GetTotalCol() const; 59 std::pair<double, double> GetGutter() const; 60 61 private: 62 RefPtr<Component> gridRowComponent_; 63 std::list<RefPtr<RenderNode>> gridColChildren_; 64 GridSizeType currentSizeType_ = GridSizeType::UNDEFINED; 65 }; 66 } // namespace OHOS::Ace::V2 67 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_GRID_LAYOUT_RENDER_GRID_ROW_H