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 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GRID_GRID_LAYOUT_OPTIONS_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GRID_GRID_LAYOUT_OPTIONS_H 18 19 #include <set> 20 21 namespace OHOS::Ace { 22 struct GridItemSize { 23 int32_t rows = 1; 24 int32_t columns = 1; 25 bool operator==(const GridItemSize& itemSize) const 26 { 27 return (rows == itemSize.rows) && (columns == itemSize.columns); 28 } GetCrossSizeGridItemSize29 int32_t GetCrossSize(Axis axis) const 30 { 31 return axis == Axis::VERTICAL ? columns : rows; 32 } 33 }; 34 35 struct GridItemRect { 36 int32_t rowStart = -1; 37 int32_t rowSpan = 1; 38 int32_t columnStart = -1; 39 int32_t columnSpan = 1; 40 bool operator==(const GridItemRect& itemRect) const 41 { 42 return (rowStart == itemRect.rowStart) && (rowSpan == itemRect.rowSpan) && 43 (columnStart == itemRect.columnStart) && (columnSpan == itemRect.columnSpan); 44 } GetCrossSizeGridItemRect45 int32_t GetCrossSize(Axis axis) const 46 { 47 return axis == Axis::VERTICAL ? columnSpan : rowSpan; 48 } 49 // [rowStart, columnStart, rowSpan, columnSpan] 50 enum GridItemRectProperty { ROW_START, COLUMN_START, ROW_SPAN, COLUMN_SPAN }; 51 }; 52 53 using GetSizeByIndex = std::function<GridItemSize(int32_t)>; 54 using GetRectByIndex = std::function<GridItemRect(int32_t)>; 55 56 struct GridLayoutOptions { 57 GridItemSize regularSize; 58 std::set<int32_t> irregularIndexes; 59 GetSizeByIndex getSizeByIndex; // irregular sizes 60 GetRectByIndex getRectByIndex; 61 bool operator==(const GridLayoutOptions& options) const 62 { 63 return (regularSize == options.regularSize) && (irregularIndexes == options.irregularIndexes) && 64 (!getSizeByIndex && !options.getSizeByIndex) && (!getRectByIndex && !options.getRectByIndex); 65 } 66 67 bool operator!=(const GridLayoutOptions& options) const 68 { 69 return !operator==(options); 70 } 71 }; 72 } // namespace OHOS::Ace 73 74 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_GRID_GRID_LAYOUT_OPTIONS_H 75