xref: /aosp_15_r20/development/tools/winscope/src/viewers/components/rects/ui_rect_builder.ts (revision 90c8c64db3049935a07c6143d7fd006e26f8ecca)
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 {Region} from 'common/geometry/region';
18import {TransformMatrix} from 'common/geometry/transform_matrix';
19import {UiRect} from './ui_rect';
20
21export class UiRectBuilder {
22  x: number | undefined;
23  y: number | undefined;
24  w: number | undefined;
25  h: number | undefined;
26  label: string | undefined;
27  transform: TransformMatrix | undefined;
28  isVisible: boolean | undefined;
29  isDisplay: boolean | undefined;
30  isActiveDisplay: boolean | undefined;
31  id: string | undefined;
32  groupId: number | undefined;
33  isClickable: boolean | undefined;
34  cornerRadius: number | undefined;
35  depth: number | undefined;
36  hasContent: boolean | undefined;
37  opacity: number | undefined;
38  fillRegion: Region | undefined;
39
40  setX(value: number) {
41    this.x = value;
42    return this;
43  }
44
45  setY(value: number) {
46    this.y = value;
47    return this;
48  }
49
50  setWidth(value: number) {
51    this.w = value;
52    return this;
53  }
54
55  setHeight(value: number) {
56    this.h = value;
57    return this;
58  }
59
60  setLabel(value: string) {
61    this.label = value;
62    return this;
63  }
64
65  setTransform(value: TransformMatrix) {
66    this.transform = value;
67    return this;
68  }
69
70  setIsVisible(value: boolean) {
71    this.isVisible = value;
72    return this;
73  }
74
75  setIsDisplay(value: boolean) {
76    this.isDisplay = value;
77    return this;
78  }
79
80  setIsActiveDisplay(value: boolean) {
81    this.isActiveDisplay = value;
82    return this;
83  }
84
85  setId(value: string) {
86    this.id = value;
87    return this;
88  }
89
90  setGroupId(value: number) {
91    this.groupId = value;
92    return this;
93  }
94
95  setIsClickable(value: boolean) {
96    this.isClickable = value;
97    return this;
98  }
99
100  setCornerRadius(value: number) {
101    this.cornerRadius = value;
102    return this;
103  }
104
105  setDepth(value: number) {
106    this.depth = value;
107    return this;
108  }
109
110  setHasContent(value: boolean) {
111    this.hasContent = value;
112    return this;
113  }
114
115  setOpacity(value: number | undefined) {
116    this.opacity = value;
117    return this;
118  }
119
120  setFillRegion(region: Region | undefined) {
121    this.fillRegion = region;
122    return this;
123  }
124
125  build(): UiRect {
126    if (this.x === undefined) {
127      throw new Error('x not set');
128    }
129
130    if (this.y === undefined) {
131      throw new Error('y not set');
132    }
133
134    if (this.w === undefined) {
135      throw new Error('width not set');
136    }
137
138    if (this.h === undefined) {
139      throw new Error('height not set');
140    }
141
142    if (this.label === undefined) {
143      throw new Error('label not set');
144    }
145
146    if (this.isVisible === undefined) {
147      throw new Error('isVisible not set');
148    }
149
150    if (this.isDisplay === undefined) {
151      throw new Error('isDisplay not set');
152    }
153
154    if (this.isActiveDisplay === undefined) {
155      throw new Error('isActiveDisplay not set');
156    }
157
158    if (this.id === undefined) {
159      throw new Error('id not set');
160    }
161
162    if (this.groupId === undefined) {
163      throw new Error('groupId not set');
164    }
165
166    if (this.isClickable === undefined) {
167      throw new Error('isClickable not set');
168    }
169
170    if (this.cornerRadius === undefined) {
171      throw new Error('cornerRadius not set');
172    }
173
174    if (this.depth === undefined) {
175      throw new Error('depth not set');
176    }
177
178    return new UiRect(
179      this.x,
180      this.y,
181      this.w,
182      this.h,
183      this.label,
184      this.isVisible,
185      this.isDisplay,
186      this.isActiveDisplay,
187      this.id,
188      this.groupId,
189      this.isClickable,
190      this.cornerRadius,
191      this.transform,
192      this.depth,
193      this.hasContent,
194      this.opacity,
195      this.fillRegion,
196    );
197  }
198}
199