• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2023-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
16const TAG = 'GridRowManager';
17
18/**
19 * GridRowManager.
20 */
21export default class GridRowManager {
22  private columns: number = 0;
23  private gutterX: number = 0;
24  private gridWidth: number = 0;
25
26  constructor(columns: number, gutterX: number, gridWidth: number) {
27    this.columns = columns;
28    this.gutterX = gutterX;
29    this.gridWidth = gridWidth;
30  }
31
32  /**
33   * get Span Width
34   *
35   * @param span span
36   */
37  getSpanWidth(span: number): number {
38    if (span < 1) {
39      return 0;
40    }
41    if (span === 1) {
42      return this.getSingleColumnWidth();
43    }
44    if (span >= this.columns) {
45      return this.gridWidth;
46    }
47    return span * this.getSingleColumnWidth() + (span - 1) * this.gutterX;
48  }
49
50  /**
51   * getSingleColumnWidth
52   */
53  getSingleColumnWidth(): number {
54    return (this.gridWidth - (this.columns - 1) * this.gutterX) / this.columns;
55  }
56
57  /**
58   * getColumns
59   */
60  getColumns(): number {
61    return this.columns;
62  }
63
64  /**
65   * getGutterX
66   */
67  getGutterX(): number {
68    return this.gutterX;
69  }
70}