1/*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17import {TransformMatrix} from 'common/geometry_types';
18import {UiRect} from './types2d';
19
20export class UiRectBuilder {
21  x: number | undefined;
22  y: number | undefined;
23  w: number | undefined;
24  h: number | undefined;
25  label: string | undefined;
26  transform: TransformMatrix | undefined;
27  isVisible: boolean | undefined;
28  isDisplay: boolean | undefined;
29  id: string | undefined;
30  groupId: number | undefined;
31  isVirtual: boolean | undefined;
32  isClickable: boolean | undefined;
33  cornerRadius: number | undefined;
34  depth: number | undefined;
35  hasContent: boolean | undefined;
36  opacity: number | undefined;
37
38  setX(value: number) {
39    this.x = value;
40    return this;
41  }
42
43  setY(value: number) {
44    this.y = value;
45    return this;
46  }
47
48  setWidth(value: number) {
49    this.w = value;
50    return this;
51  }
52
53  setHeight(value: number) {
54    this.h = value;
55    return this;
56  }
57
58  setLabel(value: string) {
59    this.label = value;
60    return this;
61  }
62
63  setTransform(value: TransformMatrix) {
64    this.transform = value;
65    return this;
66  }
67
68  setIsVisible(value: boolean) {
69    this.isVisible = value;
70    return this;
71  }
72
73  setIsDisplay(value: boolean) {
74    this.isDisplay = value;
75    return this;
76  }
77
78  setId(value: string) {
79    this.id = value;
80    return this;
81  }
82
83  setGroupId(value: number) {
84    this.groupId = value;
85    return this;
86  }
87
88  setIsVirtual(value: boolean) {
89    this.isVirtual = value;
90    return this;
91  }
92
93  setIsClickable(value: boolean) {
94    this.isClickable = value;
95    return this;
96  }
97
98  setCornerRadius(value: number) {
99    this.cornerRadius = value;
100    return this;
101  }
102
103  setDepth(value: number) {
104    this.depth = value;
105    return this;
106  }
107
108  setHasContent(value: boolean) {
109    this.hasContent = value;
110    return this;
111  }
112
113  setOpacity(value: number | undefined) {
114    this.opacity = value;
115    return this;
116  }
117
118  build(): UiRect {
119    if (this.x === undefined) {
120      throw Error('x not set');
121    }
122
123    if (this.y === undefined) {
124      throw Error('y not set');
125    }
126
127    if (this.w === undefined) {
128      throw Error('width not set');
129    }
130
131    if (this.h === undefined) {
132      throw Error('height not set');
133    }
134
135    if (this.label === undefined) {
136      throw Error('label not set');
137    }
138
139    if (this.isVisible === undefined) {
140      throw Error('isVisible not set');
141    }
142
143    if (this.isDisplay === undefined) {
144      throw Error('isDisplay not set');
145    }
146
147    if (this.id === undefined) {
148      throw Error('id not set');
149    }
150
151    if (this.groupId === undefined) {
152      throw Error('groupId not set');
153    }
154
155    if (this.isVirtual === undefined) {
156      throw Error('isVirtual not set');
157    }
158
159    if (this.isClickable === undefined) {
160      throw Error('isClickable not set');
161    }
162
163    if (this.cornerRadius === undefined) {
164      throw Error('cornerRadius not set');
165    }
166
167    if (this.depth === undefined) {
168      throw Error('depth not set');
169    }
170
171    return new UiRect(
172      this.x,
173      this.y,
174      this.w,
175      this.h,
176      this.label,
177      this.isVisible,
178      this.isDisplay,
179      this.id,
180      this.groupId,
181      this.isVirtual,
182      this.isClickable,
183      this.cornerRadius,
184      this.transform,
185      this.depth,
186      this.hasContent,
187      this.opacity,
188    );
189  }
190}
191