• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Graphics
2
3The **Graphics** module provides APIs for defining attributes of a custom node.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9## Modules to Import
10
11```ts
12import { DrawContext, Size, Offset, Position, Pivot, Scale, Translation, Matrix4, Rotation, Frame, LengthMetricsUnit } from "@kit.ArkUI";
13```
14
15## Size
16
17Returns the width and height of the component. The default unit is vp, but APIs that use the Size type may specify a different unit, in which case the unit specified by the API takes precedence.
18
19**Atomic service API**: This API can be used in atomic services since API version 12.
20
21**System capability**: SystemCapability.ArkUI.ArkUI.Full
22
23| Name  | Type  | Readable| Writable| Description                  |
24| ------ | ------ | ---- | ---- | ---------------------- |
25| width  | number | Yes  | Yes  | Width of the component.<br>Unit: vp<br>Value range: [0, +∞)|
26| height | number | Yes  | Yes  | Height of the component.<br>Unit: vp<br>Value range: [0, +∞)|
27
28## Position
29
30type Position = Vector2
31
32Sets or returns the position of the component.
33
34**Atomic service API**: This API can be used in atomic services since API version 12.
35
36**System capability**: SystemCapability.ArkUI.ArkUI.Full
37
38| Type               | Description                               |
39| ------------------- | ----------------------------------- |
40| [Vector2](#vector2) | A vector that contains two values: x and y.<br>Unit: vp|
41
42## PositionT<sup>12+</sup>
43
44type PositionT\<T> = Vector2T\<T>
45
46Sets or returns the position of the component.
47
48**Atomic service API**: This API can be used in atomic services since API version 12.
49
50**System capability**: SystemCapability.ArkUI.ArkUI.Full
51
52| Type                        | Description                               |
53| ---------------------------- | ----------------------------------- |
54| [Vector2T\<T>](#vector2tt12) | A vector that contains two values: x and y.<br>Unit: vp|
55
56## Frame
57
58Sets or returns the layout size and position of the component.
59
60**Atomic service API**: This API can be used in atomic services since API version 12.
61
62**System capability**: SystemCapability.ArkUI.ArkUI.Full
63
64| Name  | Type  | Read Only| Optional| Description                       |
65| ------ | ------ | ---- | ---- | --------------------------- |
66| x      | number | Yes  | Yes  | Horizontal position.<br>Unit: vp<br>Value range: (-∞, +∞)|
67| y      | number | Yes  | Yes  | Vertical position.<br>Unit: vp<br>Value range: (-∞, +∞)|
68| width  | number | Yes  | Yes  | Component width.<br>Unit: vp<br>Value range: [0, +∞)  |
69| height | number | Yes  | Yes  | Component height.<br>Unit: vp<br>Value range: [0, +∞)  |
70
71## Pivot
72
73type Pivot = Vector2
74
75Sets the pivot of the component. As the rotation or scaling center of the component, the pivot affects the rotation and scaling effects.
76
77**Atomic service API**: This API can be used in atomic services since API version 12.
78
79**System capability**: SystemCapability.ArkUI.ArkUI.Full
80
81| Type               | Description                                                        |
82| ------------------- | ------------------------------------------------------------ |
83| [Vector2](#vector2) | X and Y coordinates of the pivot. The value is a floating point number in the range [0.0, 1.0], and the default value is **0.5**.|
84
85## Scale
86
87type Scale = Vector2
88
89Sets the scale factor of the component.
90
91**Atomic service API**: This API can be used in atomic services since API version 12.
92
93**System capability**: SystemCapability.ArkUI.ArkUI.Full
94
95| Type               | Description                                           |
96| ------------------- | ----------------------------------------------- |
97| [Vector2](#vector2) | Scale factor along the x- and y-axis. The value is a floating point number, and the default value is **1.0**.|
98
99## Translation
100
101type Translation = Vector2
102
103Sets the translation amount of the component.
104
105**Atomic service API**: This API can be used in atomic services since API version 12.
106
107**System capability**: SystemCapability.ArkUI.ArkUI.Full
108
109| Type               | Description                         |
110| ------------------- | ----------------------------- |
111| [Vector2](#vector2) | Translation amount along the x- and y-axis.<br>Unit: px|
112
113## Rotation
114
115type Rotation = Vector3
116
117Sets the rotation angle of the component.
118
119**Atomic service API**: This API can be used in atomic services since API version 12.
120
121**System capability**: SystemCapability.ArkUI.ArkUI.Full
122
123| Type               | Description                                  |
124| ------------------- | -------------------------------------- |
125| [Vector3](#vector3) | Rotation angle along the x- and y-axis.<br>Unit: degree|
126
127## Offset
128
129type Offset = Vector2
130
131Sets the offset of the component or effect.
132
133**Atomic service API**: This API can be used in atomic services since API version 12.
134
135**System capability**: SystemCapability.ArkUI.ArkUI.Full
136
137| Type               | Description                             |
138| ------------------- | --------------------------------- |
139| [Vector2](#vector2) | Offset along the x- and y-axis.<br>Unit: vp|
140
141## Matrix4
142
143type Matrix4 = [number,number,number,number,number,number,number,number,number,number,number,number,number,number,number,number]
144
145Sets a 4x4 matrix.
146
147**Atomic service API**: This API can be used in atomic services since API version 12.
148
149**System capability**: SystemCapability.ArkUI.ArkUI.Full
150
151| Type                                                        | Description                                |
152| ------------------------------------------------------------ | ------------------------------------ |
153| [number,number,number,number,<br>number,number,number,number,<br>number,number,number,number,<br>number,number,number,number] | A 16-element array representing a 4x4 matrix.<br>Value range of each number: (-∞, +∞)|
154
155The **Matrix4** type is used to set transformation information for components. The following is an example:
156```ts
157const transform: Matrix4 = [
158  1, 0, 45, 0,
159  0, 1,  0, 0,
160  0, 0,  1, 0,
161  0, 0,  0, 1
162]
163```
164
165## Vector2
166
167Defines a vector that contains the x and y coordinate values.
168
169**Atomic service API**: This API can be used in atomic services since API version 12.
170
171**System capability**: SystemCapability.ArkUI.ArkUI.Full
172
173| Name| Type  | Read Only| Optional| Description             |
174| ---- | ------ | ---- | ---- | ----------------- |
175| x    | number | No  | No  | X coordinate value of the vector.<br>Value range: (-∞, +∞)|
176| y    | number | No  | No  | Y coordinate value of the vector.<br>Value range: (-∞, +∞)|
177
178## Vector3
179
180Represents a vector including three values: x, y, and z.
181
182**Atomic service API**: This API can be used in atomic services since API version 12.
183
184**System capability**: SystemCapability.ArkUI.ArkUI.Full
185
186| Name| Type  | Read Only| Optional| Description               |
187| ---- | ------ | ---- | ---- | ------------------- |
188| x    | number | No  | No  | Rotation angle along the x-axis.<br>Value range: (-∞, +∞)|
189| y    | number | No  | No  | Rotation angle along the y-axis.<br>Value range: (-∞, +∞)|
190| z    | number | No  | No  | Rotation angle along the z-axis.<br>Value range: (-∞, +∞)|
191
192## Vector2T\<T><sup>12+</sup>
193
194Represents a vector of the T type that contains two values: x and y.
195
196**Atomic service API**: This API can be used in atomic services since API version 12.
197
198**System capability**: SystemCapability.ArkUI.ArkUI.Full
199
200| Name| Type  | Read Only| Optional| Description             |
201| ---- | ------ | ---- | ---- | ----------------- |
202| x    | T | No | No | X coordinate value of the vector.|
203| y    | T | No | No | Y coordinate value of the vector.|
204
205## DrawContext
206
207Graphics drawing context, which provides the canvas width and height required for drawing.
208
209### size
210
211get size(): Size
212
213Obtains the width and height of the canvas.
214
215**Atomic service API**: This API can be used in atomic services since API version 12.
216
217**System capability**: SystemCapability.ArkUI.ArkUI.Full
218
219**Return value**
220
221| Type         | Description            |
222| ------------- | ---------------- |
223| [Size](#size) | Width and height of the canvas.|
224
225### sizeInPixel<sup>12+</sup>
226
227get sizeInPixel(): Size
228
229Obtains the width and height of the canvas in px.
230
231**Atomic service API**: This API can be used in atomic services since API version 12.
232
233**System capability**: SystemCapability.ArkUI.ArkUI.Full
234
235**Return value**
236
237| Type         | Description            |
238| ------------- | ---------------- |
239| [Size](#size) | Width and height of the canvas, in px.|
240
241### canvas
242
243get canvas(): drawing.Canvas
244
245Obtains the canvas used for drawing.
246
247**Atomic service API**: This API can be used in atomic services since API version 12.
248
249**System capability**: SystemCapability.ArkUI.ArkUI.Full
250
251**Return value**
252
253| Type         | Description            |
254| ------------- | ---------------- |
255| [drawing.Canvas](../apis-arkgraphics2d/js-apis-graphics-drawing.md#canvas) | Canvas for drawing.|
256
257**Example**
258
259```ts
260import { RenderNode, FrameNode, NodeController, DrawContext } from "@kit.ArkUI";
261
262class MyRenderNode extends RenderNode {
263  flag: boolean = false;
264
265  draw(context: DrawContext) {
266    const size = context.size;
267    const canvas = context.canvas;
268    const sizeInPixel = context.sizeInPixel;
269  }
270}
271
272const renderNode = new MyRenderNode();
273renderNode.frame = { x: 0, y: 0, width: 100, height: 100 };
274renderNode.backgroundColor = 0xffff0000;
275
276class MyNodeController extends NodeController {
277  private rootNode: FrameNode | null = null;
278
279  makeNode(uiContext: UIContext): FrameNode | null {
280    this.rootNode = new FrameNode(uiContext);
281
282    const rootRenderNode = this.rootNode.getRenderNode();
283    if (rootRenderNode !== null) {
284      rootRenderNode.appendChild(renderNode);
285    }
286
287    return this.rootNode;
288  }
289}
290
291@Entry
292@Component
293struct Index {
294  private myNodeController: MyNodeController = new MyNodeController();
295
296  build() {
297    Row() {
298      NodeContainer(this.myNodeController)
299    }
300  }
301}
302```
303
304## Edges\<T><sup>12+</sup>
305
306Describes the edges.
307
308**Atomic service API**: This API can be used in atomic services since API version 12.
309
310**System capability**: SystemCapability.ArkUI.ArkUI.Full
311
312| Name  | Type| Readable| Writable| Description            |
313| ------ | ---- | ---- | ---- | ---------------- |
314| left   | T    | Yes  | Yes  | Left edge.|
315| top    | T    | Yes  | Yes  | Top edge.|
316| right  | T    | Yes  | Yes  | Right edge.|
317| bottom | T    | Yes  | Yes  | Bottom edge.|
318
319## LengthUnit<sup>12+</sup>
320
321Enumerates length units.
322
323**Atomic service API**: This API can be used in atomic services since API version 12.
324
325**System capability**: SystemCapability.ArkUI.ArkUI.Full
326
327| Name| Value| Description|
328| -------- | -------- | -------- |
329| [PX](arkui-ts/ts-types.md#px10) | 0 | Length in px.|
330| [VP](arkui-ts/ts-types.md#vp10) | 1 | Length in vp.|
331| [FP](arkui-ts/ts-types.md#fp10) | 2 | Length in fp.|
332| [PERCENT](arkui-ts/ts-types.md#percentage10) | 3 | Length in percentage.|
333| [LPX](arkui-ts/ts-types.md#lpx10) | 4 | Length in lpx.|
334
335## SizeT\<T><sup>12+</sup>
336
337Sets the width and height attributes.
338
339**Atomic service API**: This API can be used in atomic services since API version 12.
340
341**System capability**: SystemCapability.ArkUI.ArkUI.Full
342
343| Name  | Type| Readable| Writable| Description            |
344| ------ | ---- | ---- | ---- | ---------------- |
345| width   | T    | Yes  | Yes  | Width.|
346| height    | T    | Yes  | Yes  | Height.|
347
348## LengthMetricsUnit<sup>12+</sup>
349
350Enumerates length units.
351
352**Atomic service API**: This API can be used in atomic services since API version 12.
353
354**System capability**: SystemCapability.ArkUI.ArkUI.Full
355
356| Name| Value| Description|
357| -------- | -------- | -------- |
358| DEFAULT | 0 | Length in vp.|
359| PX | 1 | Length in px.|
360
361## LengthMetrics<sup>12+</sup>
362
363Sets the metrics of length. When the length unit is [PERCENT](arkui-ts/ts-types.md#percentage10), the value **1** indicates 100%.
364
365### Properties
366
367**Atomic service API**: This API can be used in atomic services since API version 12.
368
369**System capability**: SystemCapability.ArkUI.ArkUI.Full
370
371| Name  | Type| Readable| Writable| Description            |
372| ------------ | ---------------------------------------- | ---- | ---- | ------ |
373| value       | number | Yes  | Yes  | Value of the length attribute.  |
374| unit | [LengthUnit](#lengthunit12)                                   | Yes  | Yes  | Unit of the length attribute. The default value is vp.|
375
376### constructor<sup>12+</sup>
377
378constructor(value: number, unit?: LengthUnit)
379
380Constructor used to create a **LengthMetrics** instance. If the **unit** parameter is not set or is set to **undefined**, the default unit VP is used. If the **unit** parameter is set to a value that is not of the LengthUnit type, the default value 0 VP is used.
381
382**Atomic service API**: This API can be used in atomic services since API version 12.
383
384**System capability**: SystemCapability.ArkUI.ArkUI.Full
385
386**Parameters**
387
388| Name| Type         | Mandatory| Description        |
389| ------ | ------------- | ---- | ------------ |
390| value   | number | Yes  | Value of the length attribute.<br>Value range: [0, +∞)|
391| unit   | [LengthUnit](#lengthunit12) | No  | Unit of the length attribute.|
392
393### px<sup>12+</sup>
394
395static px(value: number): LengthMetrics
396
397Creates a length attribute in px.
398
399**Atomic service API**: This API can be used in atomic services since API version 12.
400
401**System capability**: SystemCapability.ArkUI.ArkUI.Full
402
403**Parameters**
404
405| Name| Type         | Mandatory| Description        |
406| ------ | ------------- | ---- | ------------ |
407| value   | number | Yes  | Value of the length attribute.<br>Value range: (-∞, +∞)|
408
409**Return value**
410
411| Type         | Description            |
412| ------------- | ---------------- |
413| [LengthMetrics](#lengthmetrics12) | Instance of the **LengthMetrics** class.|
414
415### vp<sup>12+</sup>
416
417static vp(value: number): LengthMetrics
418
419Creates a length attribute in vp.
420
421**Atomic service API**: This API can be used in atomic services since API version 12.
422
423**System capability**: SystemCapability.ArkUI.ArkUI.Full
424
425**Parameters**
426
427| Name| Type         | Mandatory| Description        |
428| ------ | ------------- | ---- | ------------ |
429| value   | number | Yes  | Value of the length attribute.<br>Value range: (-∞, +∞)|
430
431**Return value**
432
433| Type         | Description            |
434| ------------- | ---------------- |
435| [LengthMetrics](#lengthmetrics12) | Instance of the **LengthMetrics** class.|
436
437### fp<sup>12+</sup>
438
439static fp(value: number): LengthMetrics
440
441Creates a length attribute in fp.
442
443**Atomic service API**: This API can be used in atomic services since API version 12.
444
445**System capability**: SystemCapability.ArkUI.ArkUI.Full
446
447**Parameters**
448
449| Name| Type         | Mandatory| Description        |
450| ------ | ------------- | ---- | ------------ |
451| value   | number | Yes  | Value of the length attribute.<br>Value range: (-∞, +∞)|
452
453**Return value**
454
455| Type         | Description            |
456| ------------- | ---------------- |
457| [LengthMetrics](#lengthmetrics12) | Instance of the **LengthMetrics** class.|
458
459### percent<sup>12+</sup>
460
461static percent(value: number): LengthMetrics
462
463Creates a length attribute in percentage.
464
465**Atomic service API**: This API can be used in atomic services since API version 12.
466
467**System capability**: SystemCapability.ArkUI.ArkUI.Full
468
469**Parameters**
470
471| Name| Type         | Mandatory| Description        |
472| ------ | ------------- | ---- | ------------ |
473| value   | number | Yes  | Value of the length attribute.<br>Value range: [0, 100]|
474
475**Return value**
476
477| Type         | Description            |
478| ------------- | ---------------- |
479| [LengthMetrics](#lengthmetrics12) | Instance of the **LengthMetrics** class.|
480
481### lpx<sup>12+</sup>
482
483static lpx(value: number): LengthMetrics
484
485Creates a length attribute in lpx.
486
487**Atomic service API**: This API can be used in atomic services since API version 12.
488
489**System capability**: SystemCapability.ArkUI.ArkUI.Full
490
491**Parameters**
492
493| Name| Type         | Mandatory| Description        |
494| ------ | ------------- | ---- | ------------ |
495| value   | number | Yes  | Value of the length attribute.<br>Value range: (-∞, +∞)|
496
497**Return value**
498
499| Type         | Description            |
500| ------------- | ---------------- |
501| [LengthMetrics](#lengthmetrics12) | Instance of the **LengthMetrics** class.|
502
503### resource<sup>12+</sup>
504
505static resource(value: Resource): LengthMetrics
506
507Represents the length of a resource of the Resource type.
508
509**Atomic service API**: This API can be used in atomic services since API version 12.
510
511**System capability**: SystemCapability.ArkUI.ArkUI.Full
512
513**Parameters**
514
515| Name| Type         | Mandatory| Description        |
516| ------ | ------------- | ---- | ------------ |
517| value   | Resource | Yes  | Value of the length attribute.|
518
519**Return value**
520
521| Type         | Description            |
522| ------------- | ---------------- |
523| [LengthMetrics](#lengthmetrics12) | Instance of the **LengthMetrics** class.|
524
525**Error codes**
526
527For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [System Resource Error Codes](errorcode-system-resource.md).
528
529| ID| Error Message                                  |
530| -------- | ------------------------------------------ |
531| 180001   | System resources does not exist.           |
532| 180002   | The type of system resources is incorrect. |
533
534## ColorMetrics<sup>12+</sup>
535
536Used to mix colors.
537
538**System capability**: SystemCapability.ArkUI.ArkUI.Full
539
540### numeric<sup>12+</sup>
541
542static numeric(value: number): ColorMetrics
543
544Instantiates the **ColorMetrics** class using colors in HEX format.
545
546**Atomic service API**: This API can be used in atomic services since API version 12.
547
548**System capability**: SystemCapability.ArkUI.ArkUI.Full
549
550**Parameters**
551
552| Name| Type         | Mandatory| Description        |
553| ------ | ------------- | ---- | ------------ |
554| value   | number | Yes  | Color in hexadecimal notation. RGB and ARGB are supported.|
555
556**Return value**
557
558| Type         | Description            |
559| ------------- | ---------------- |
560| [ColorMetrics](#colormetrics12) | Instance of the **ColorMetrics** class.|
561
562### rgba<sup>12+</sup>
563
564static rgba(red: number, green: number, blue: number, alpha?: number): ColorMetrics
565
566Instantiates the **ColorMetrics** class using colors in RGB or RGBA format.
567
568**Atomic service API**: This API can be used in atomic services since API version 12.
569
570**System capability**: SystemCapability.ArkUI.ArkUI.Full
571
572**Parameters**
573
574| Name| Type         | Mandatory| Description        |
575| ------ | ------------- | ---- | ------------ |
576| red   | number | Yes  | Red component of the color. The value is an integer ranging from 0 to 255.|
577| green | number | Yes  | Green component of the color. The value is an integer ranging from 0 to 255.|
578| blue  | number | Yes  | Blue component of the color. The value is an integer ranging from 0 to 255.|
579| alpha | number | No  | Alpha component of the color. The value is a floating point number ranging from 0.0 to 1.0. The default value is **1.0** (fully opaque).|
580
581**Return value**
582
583| Type         | Description            |
584| ------------- | ---------------- |
585| [ColorMetrics](#colormetrics12) | Instance of the **ColorMetrics** class.|
586
587### resourceColor<sup>12+</sup>
588
589static resourceColor(color: ResourceColor): ColorMetrics
590
591Instantiates the **ColorMetrics** class using a color in resource reference format.
592
593**Atomic service API**: This API can be used in atomic services since API version 12.
594
595**System capability**: SystemCapability.ArkUI.ArkUI.Full
596
597**Parameters**
598
599| Name| Type         | Mandatory| Description        |
600| ------ | ------------- | ---- | ------------ |
601| color | [ResourceColor](arkui-ts/ts-types.md#resourcecolor) | Yes| Color in resource reference format.|
602
603**Return value**
604
605| Type         | Description            |
606| ------------- | ---------------- |
607| [ColorMetrics](#colormetrics12) | Instance of the **ColorMetrics** class.|
608
609**Error codes**
610
611For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [System Resource Error Codes](errorcode-system-resource.md).
612
613| ID| Error Message|
614| -------- | ---------------------------------------- |
615| 401   | Parameter error. Possible cause:1.The type of the input color parameter is not ResourceColor;2.The format of the input color string is not RGB or RGBA.             |
616| 180003   | Failed to obtain the color resource.         |
617
618### blendColor<sup>12+</sup>
619
620blendColor(overlayColor: ColorMetrics): ColorMetrics
621
622Blends colors.
623
624**Atomic service API**: This API can be used in atomic services since API version 12.
625
626**System capability**: SystemCapability.ArkUI.ArkUI.Full
627
628**Parameters**
629
630| Name| Type         | Mandatory| Description        |
631| ------ | ------------- | ---- | ------------ |
632| overlayColor | [ColorMetrics](#colormetrics12) | Yes| Instance of the **ColorMetrics** class for overlaying colors.|
633
634**Return value**
635
636| Type         | Description            |
637| ------------- | ---------------- |
638| [ColorMetrics](#colormetrics12) | Instance of the **ColorMetrics** class after color blending.|
639
640**Error codes**
641
642For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
643
644| ID| Error Message|
645| -------- | ---------------------------------------- |
646| 401   | Parameter error. The type of the input parameter is not ColorMetrics.                |
647
648### color<sup>12+</sup>
649
650get color(): string
651
652Obtains the color of **ColorMetrics**. The return value is a string indicating an RGBA color value.
653
654**Atomic service API**: This API can be used in atomic services since API version 12.
655
656**System capability**: SystemCapability.ArkUI.ArkUI.Full
657
658**Return value**
659
660| Type         | Description            |
661| ------------- | ---------------- |
662| string | String indicating an RGBA color value. Example: **'rgba(255, 100, 255, 0.5)'**|
663
664### red<sup>12+</sup>
665
666get red(): number
667
668Obtains the red component of the ColorMetrics color.
669
670**Atomic service API**: This API can be used in atomic services since API version 12.
671
672**System capability**: SystemCapability.ArkUI.ArkUI.Full
673
674**Return value**
675
676| Type         | Description            |
677| ------------- | ---------------- |
678| number | Red component of the color. The value is an integer ranging from 0 to 255.|
679
680### green<sup>12+</sup>
681
682get green(): number
683
684Obtains the green component of the ColorMetrics color.
685
686**Atomic service API**: This API can be used in atomic services since API version 12.
687
688**System capability**: SystemCapability.ArkUI.ArkUI.Full
689
690**Return value**
691
692| Type         | Description            |
693| ------------- | ---------------- |
694| number | Green component of the color. The value is an integer ranging from 0 to 255.|
695
696### blue<sup>12+</sup>
697
698get blue(): number
699
700Obtains the blue component of the ColorMetrics color.
701
702**Atomic service API**: This API can be used in atomic services since API version 12.
703
704**System capability**: SystemCapability.ArkUI.ArkUI.Full
705
706**Return value**
707
708| Type         | Description            |
709| ------------- | ---------------- |
710| number | Blue component of the color. The value is an integer ranging from 0 to 255.|
711
712### alpha<sup>12+</sup>
713
714get alpha(): number
715
716Obtains the alpha component of the ColorMetrics color.
717
718**Atomic service API**: This API can be used in atomic services since API version 12.
719
720**System capability**: SystemCapability.ArkUI.ArkUI.Full
721
722**Return value**
723
724| Type         | Description            |
725| ------------- | ---------------- |
726| number | Alpha component of the color. The value is an integer ranging from 0 to 255.|
727
728**Example**
729
730```ts
731import { ColorMetrics } from '@kit.ArkUI';
732import { BusinessError } from '@kit.BasicServicesKit';
733
734function getBlendColor(baseColor: ResourceColor): ColorMetrics {
735  let sourceColor: ColorMetrics;
736  try {
737    // When resourceColor and blendColor of ColorMetrics are used, add exception handling.
738    // Error codes 401 and 180003 of the ArkUI subsystem may be returned.
739    sourceColor = ColorMetrics.resourceColor(baseColor).blendColor(ColorMetrics.resourceColor("#19000000"));
740  } catch (error) {
741    console.log("getBlendColor failed, code = " + (error as BusinessError).code + ", message = " +
742    (error as BusinessError).message);
743    sourceColor = ColorMetrics.resourceColor("#19000000");
744  }
745  return sourceColor;
746}
747
748@Entry
749@Component
750struct ColorMetricsSample {
751  build() {
752    Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
753      Button("ColorMetrics")
754        .width('80%')
755        .align(Alignment.Center)
756        .height(50)
757        .backgroundColor(getBlendColor(Color.Red).color)
758    }
759    .width('100%')
760    .height('100%')
761  }
762}
763```
764## Corners\<T><sup>12+</sup>
765
766Describes the four corners.
767
768**Atomic service API**: This API can be used in atomic services since API version 12.
769
770**System capability**: SystemCapability.ArkUI.ArkUI.Full
771
772| Name       | Type| Readable| Writable| Description                  |
773| ----------- | ---- | ---- | ---- | ---------------------- |
774| topLeft     | T    | Yes  | Yes  | Radius of the upper left corner.  |
775| topRight    | T    | Yes  | Yes  | Radius of the upper right corner.|
776| bottomLeft  | T    | Yes  | Yes  | Radius of the lower left corner.  |
777| bottomRight | T    | Yes  | Yes  | Radius of the lower right corner.  |
778
779## CornerRadius<sup>12+</sup>
780
781type CornerRadius = Corners\<Vector2>
782
783Sets the radius for the four corners.
784
785**Atomic service API**: This API can be used in atomic services since API version 12.
786
787**System capability**: SystemCapability.ArkUI.ArkUI.Full
788
789| Type                                        | Description              |
790| -------------------------------------------- | ------------------ |
791| [Corners](#cornerst12)[\<Vector2>](#vector2) | Radius of the four corners.|
792
793## BorderRadiuses<sup>12+</sup>
794
795type BorderRadiuses = Corners\<number>
796
797Sets the radius for the four border corners.
798
799**Atomic service API**: This API can be used in atomic services since API version 12.
800
801**System capability**: SystemCapability.ArkUI.ArkUI.Full
802
803| Type                           | Description              |
804| ------------------------------- | ------------------ |
805| [Corners\<number>](#cornerst12) | Radius of the four border corners.|
806
807## Rect<sup>12+</sup>
808
809type Rect = common2D.Rect
810
811Describes a rectangle.
812
813**Atomic service API**: This API can be used in atomic services since API version 12.
814
815**System capability**: SystemCapability.ArkUI.ArkUI.Full
816
817| Type                                                        | Description      |
818| ------------------------------------------------------------ | ---------- |
819| [common2D.Rect](../apis-arkgraphics2d/js-apis-graphics-common2D.md#rect) | Rectangle.|
820
821## RoundRect<sup>12+</sup>
822
823Describes a rectangle with rounded corners.
824
825**Atomic service API**: This API can be used in atomic services since API version 12.
826
827**System capability**: SystemCapability.ArkUI.ArkUI.Full
828
829| Name   | Type                         | Readable| Writable| Description            |
830| ------- | ----------------------------- | ---- | ---- | ---------------- |
831| rect    | [Rect](#rect12)                 | Yes  | Yes  | Attributes of the rectangle.|
832| corners | [CornerRadius](#cornerradius12) | Yes  | Yes  | Attributes of rounded corners.|
833
834## Circle<sup>12+</sup>
835
836Describes a circle.
837
838**Atomic service API**: This API can be used in atomic services since API version 12.
839
840**System capability**: SystemCapability.ArkUI.ArkUI.Full
841
842| Name   | Type  | Readable| Writable| Description                     |
843| ------- | ------ | ---- | ---- | ------------------------- |
844| centerX | number | Yes  | Yes  | X coordinate of the center of the circle, in px.|
845| centerY | number | Yes  | Yes  | Y coordinate of the center of the circle, in px.|
846| radius  | number | Yes  | Yes  | Radius of the circle, in px.   |
847
848## CommandPath<sup>12+</sup>
849
850Describes the command for drawing a path.
851
852**Atomic service API**: This API can be used in atomic services since API version 12.
853
854**System capability**: SystemCapability.ArkUI.ArkUI.Full
855
856| Name                                                        | Type  | Readable| Writable| Description                                                        |
857| ------------------------------------------------------------ | ------ | ---- | ---- | ------------------------------------------------------------ |
858| [commands](./arkui-ts/ts-drawing-components-path.md#commands-1) | string | Yes  | Yes  | Commands for drawing a path. For details about how to convert the pixel unit, see [Pixel Unit Conversion](./arkui-ts/ts-pixel-units.md#pixel-unit-conversion).<br>Unit: px|
859
860## ShapeMask<sup>12+</sup>
861
862Describes the shape mask.
863
864### constructor<sup>12+</sup>
865
866constructor()
867
868A constructor used to create a **ShapeMask** instance.
869
870**Atomic service API**: This API can be used in atomic services since API version 12.
871
872**System capability**: SystemCapability.ArkUI.ArkUI.Full
873
874### setRectShape<sup>12+</sup>
875
876setRectShape(rect: Rect): void
877
878Sets a rectangle mask.
879
880**Atomic service API**: This API can be used in atomic services since API version 12.
881
882**System capability**: SystemCapability.ArkUI.ArkUI.Full
883
884**Parameters**
885
886| Name| Type         | Mandatory| Description        |
887| ------ | ------------- | ---- | ------------ |
888| rect   | [Rect](#rect12) | Yes  | Shape of the rectangle.|
889
890**Example**
891
892```ts
893import { RenderNode, FrameNode, NodeController, ShapeMask } from '@kit.ArkUI';
894
895const mask = new ShapeMask();
896mask.setRectShape({ left: 0, right: vp2px(150), top: 0, bottom: vp2px(150) });
897mask.fillColor = 0X55FF0000;
898
899const renderNode = new RenderNode();
900renderNode.frame = { x: 0, y: 0, width: 150, height: 150 };
901renderNode.backgroundColor = 0XFF00FF00;
902renderNode.shapeMask = mask;
903
904
905class MyNodeController extends NodeController {
906  private rootNode: FrameNode | null = null;
907
908  makeNode(uiContext: UIContext): FrameNode | null {
909    this.rootNode = new FrameNode(uiContext);
910
911    const rootRenderNode = this.rootNode.getRenderNode();
912    if (rootRenderNode !== null) {
913      rootRenderNode.appendChild(renderNode);
914    }
915
916    return this.rootNode;
917  }
918}
919
920@Entry
921@Component
922struct Index {
923  private myNodeController: MyNodeController = new MyNodeController();
924
925  build() {
926    Row() {
927      NodeContainer(this.myNodeController)
928    }
929  }
930}
931```
932
933### setRoundRectShape<sup>12+</sup>
934
935setRoundRectShape(roundRect: RoundRect): void
936
937Sets the mask in the shape of a rectangle with rounded corners.
938
939**Atomic service API**: This API can be used in atomic services since API version 12.
940
941**System capability**: SystemCapability.ArkUI.ArkUI.Full
942
943**Parameters**
944
945| Name   | Type                   | Mandatory| Description            |
946| --------- | ----------------------- | ---- | ---------------- |
947| roundRect | [RoundRect](#roundrect12) | Yes  | Shape of the rectangle with rounded corners.|
948
949**Example**
950
951```ts
952import { RenderNode, FrameNode, NodeController, ShapeMask,RoundRect} from '@kit.ArkUI';
953
954const mask = new ShapeMask();
955const roundRect: RoundRect = {
956  rect: { left: 0, top: 0, right: vp2px(150), bottom: vp2px(150) },
957  corners: {
958    topLeft: { x: 32, y: 32 },
959    topRight: { x: 32, y: 32 },
960    bottomLeft: { x: 32, y: 32 },
961    bottomRight: { x: 32, y: 32 }
962  }
963}
964mask.setRoundRectShape(roundRect);
965mask.fillColor = 0X55FF0000;
966
967const renderNode = new RenderNode();
968renderNode.frame = { x: 0, y: 0, width: 150, height: 150 };
969renderNode.backgroundColor = 0XFF00FF00;
970renderNode.shapeMask = mask;
971
972
973class MyNodeController extends NodeController {
974  private rootNode: FrameNode | null = null;
975
976  makeNode(uiContext: UIContext): FrameNode | null {
977    this.rootNode = new FrameNode(uiContext);
978
979    const rootRenderNode = this.rootNode.getRenderNode();
980    if (rootRenderNode !== null) {
981      rootRenderNode.appendChild(renderNode);
982    }
983
984    return this.rootNode;
985  }
986}
987
988@Entry
989@Component
990struct Index {
991  private myNodeController: MyNodeController = new MyNodeController();
992
993  build() {
994    Row() {
995      NodeContainer(this.myNodeController)
996    }
997  }
998}
999```
1000
1001### setCircleShape<sup>12+</sup>
1002
1003setCircleShape(circle: Circle): void
1004
1005Sets a round mask.
1006
1007**Atomic service API**: This API can be used in atomic services since API version 12.
1008
1009**System capability**: SystemCapability.ArkUI.ArkUI.Full
1010
1011**Parameters**
1012
1013| Name| Type             | Mandatory| Description        |
1014| ------ | ----------------- | ---- | ------------ |
1015| circle | [Circle](#circle12) | Yes  | Round shape.|
1016
1017**Example**
1018
1019```ts
1020import { RenderNode, FrameNode, NodeController, ShapeMask } from '@kit.ArkUI';
1021
1022const mask = new ShapeMask();
1023mask.setCircleShape({ centerY: vp2px(75), centerX: vp2px(75), radius: vp2px(75) });
1024mask.fillColor = 0X55FF0000;
1025
1026const renderNode = new RenderNode();
1027renderNode.frame = { x: 0, y: 0, width: 150, height: 150 };
1028renderNode.backgroundColor = 0XFF00FF00;
1029renderNode.shapeMask = mask;
1030
1031
1032class MyNodeController extends NodeController {
1033  private rootNode: FrameNode | null = null;
1034
1035  makeNode(uiContext: UIContext): FrameNode | null {
1036    this.rootNode = new FrameNode(uiContext);
1037
1038    const rootRenderNode = this.rootNode.getRenderNode();
1039    if (rootRenderNode !== null) {
1040      rootRenderNode.appendChild(renderNode);
1041    }
1042
1043    return this.rootNode;
1044  }
1045}
1046
1047@Entry
1048@Component
1049struct Index {
1050  private myNodeController: MyNodeController = new MyNodeController();
1051
1052  build() {
1053    Row() {
1054      NodeContainer(this.myNodeController)
1055    }
1056  }
1057}
1058```
1059
1060### setOvalShape<sup>12+</sup>
1061
1062setOvalShape(oval: Rect): void
1063
1064Sets an oval mask.
1065
1066**Atomic service API**: This API can be used in atomic services since API version 12.
1067
1068**System capability**: SystemCapability.ArkUI.ArkUI.Full
1069
1070**Parameters**
1071
1072| Name| Type         | Mandatory| Description          |
1073| ------ | ------------- | ---- | -------------- |
1074| oval   | [Rect](#rect12) | Yes  | Oval shape.|
1075
1076**Example**
1077
1078```ts
1079import { RenderNode, FrameNode, NodeController, ShapeMask } from '@kit.ArkUI';
1080
1081const mask = new ShapeMask();
1082mask.setOvalShape({ left: 0, right: vp2px(150), top: 0, bottom: vp2px(100) });
1083mask.fillColor = 0X55FF0000;
1084
1085const renderNode = new RenderNode();
1086renderNode.frame = { x: 0, y: 0, width: 150, height: 150 };
1087renderNode.backgroundColor = 0XFF00FF00;
1088renderNode.shapeMask = mask;
1089
1090
1091class MyNodeController extends NodeController {
1092  private rootNode: FrameNode | null = null;
1093
1094  makeNode(uiContext: UIContext): FrameNode | null {
1095    this.rootNode = new FrameNode(uiContext);
1096
1097    const rootRenderNode = this.rootNode.getRenderNode();
1098    if (rootRenderNode !== null) {
1099      rootRenderNode.appendChild(renderNode);
1100    }
1101
1102    return this.rootNode;
1103  }
1104}
1105
1106@Entry
1107@Component
1108struct Index {
1109  private myNodeController: MyNodeController = new MyNodeController();
1110
1111  build() {
1112    Row() {
1113      NodeContainer(this.myNodeController)
1114    }
1115  }
1116}
1117```
1118
1119### setCommandPath<sup>12+</sup>
1120
1121setCommandPath(path: CommandPath): void
1122
1123Sets the command for drawing a path.
1124
1125**Atomic service API**: This API can be used in atomic services since API version 12.
1126
1127**System capability**: SystemCapability.ArkUI.ArkUI.Full
1128
1129**Parameters**
1130
1131| Name| Type                       | Mandatory| Description          |
1132| ------ | --------------------------- | ---- | -------------- |
1133| path   | [CommandPath](#commandpath12) | Yes  | Command for drawing a path.|
1134
1135**Example**
1136
1137```ts
1138import { RenderNode, FrameNode, NodeController, ShapeMask } from '@kit.ArkUI';
1139
1140const mask = new ShapeMask();
1141mask.setCommandPath({ commands: "M100 0 L0 100 L50 200 L150 200 L200 100 Z" });
1142mask.fillColor = 0X55FF0000;
1143
1144const renderNode = new RenderNode();
1145renderNode.frame = { x: 0, y: 0, width: 150, height: 150 };
1146renderNode.backgroundColor = 0XFF00FF00;
1147renderNode.shapeMask = mask;
1148
1149
1150class MyNodeController extends NodeController {
1151  private rootNode: FrameNode | null = null;
1152
1153  makeNode(uiContext: UIContext): FrameNode | null {
1154    this.rootNode = new FrameNode(uiContext);
1155
1156    const rootRenderNode = this.rootNode.getRenderNode();
1157    if (rootRenderNode !== null) {
1158      rootRenderNode.appendChild(renderNode);
1159    }
1160
1161    return this.rootNode;
1162  }
1163}
1164
1165@Entry
1166@Component
1167struct Index {
1168  private myNodeController: MyNodeController = new MyNodeController();
1169
1170  build() {
1171    Row() {
1172      NodeContainer(this.myNodeController)
1173    }
1174  }
1175}
1176```
1177
1178### fillColor<sup>12+</sup>
1179
1180fillColor: number
1181
1182Describes the fill color of the mask, in ARGB format. The default value is **0XFF000000**.
1183
1184**Atomic service API**: This API can be used in atomic services since API version 12.
1185
1186**System capability**: SystemCapability.ArkUI.ArkUI.Full
1187
1188**Example**
1189
1190```ts
1191import { RenderNode, FrameNode, NodeController, ShapeMask } from '@kit.ArkUI';
1192
1193const mask = new ShapeMask();
1194mask.setRectShape({ left: 0, right: 150, top: 0, bottom: 150 });
1195mask.fillColor = 0X55FF0000;
1196
1197const renderNode = new RenderNode();
1198renderNode.frame = { x: 0, y: 0, width: 150, height: 150 };
1199renderNode.backgroundColor = 0XFF00FF00;
1200renderNode.shapeMask = mask;
1201
1202
1203class MyNodeController extends NodeController {
1204  private rootNode: FrameNode | null = null;
1205
1206  makeNode(uiContext: UIContext): FrameNode | null {
1207    this.rootNode = new FrameNode(uiContext);
1208
1209    const rootRenderNode = this.rootNode.getRenderNode();
1210    if (rootRenderNode !== null) {
1211      rootRenderNode.appendChild(renderNode);
1212    }
1213
1214    return this.rootNode;
1215  }
1216}
1217
1218@Entry
1219@Component
1220struct Index {
1221  private myNodeController: MyNodeController = new MyNodeController();
1222
1223  build() {
1224    Row() {
1225      NodeContainer(this.myNodeController)
1226    }
1227  }
1228}
1229```
1230
1231### strokeColor<sup>12+</sup>
1232
1233strokeColor: number
1234
1235Sets the stroke color for the mask, in ARGB format. The default value is **0XFF000000**.
1236
1237**Atomic service API**: This API can be used in atomic services since API version 12.
1238
1239**System capability**: SystemCapability.ArkUI.ArkUI.Full
1240
1241**Example**
1242
1243```ts
1244import { RenderNode, FrameNode, NodeController, ShapeMask } from '@kit.ArkUI';
1245
1246const mask = new ShapeMask();
1247mask.setRectShape({ left: 0, right: 150, top: 0, bottom: 150 });
1248mask.strokeColor = 0XFFFF0000;
1249mask.strokeWidth = 24;
1250
1251const renderNode = new RenderNode();
1252renderNode.frame = { x: 0, y: 0, width: 150, height: 150 };
1253renderNode.backgroundColor = 0XFF00FF00;
1254renderNode.shapeMask = mask;
1255
1256
1257class MyNodeController extends NodeController {
1258  private rootNode: FrameNode | null = null;
1259
1260  makeNode(uiContext: UIContext): FrameNode | null {
1261    this.rootNode = new FrameNode(uiContext);
1262
1263    const rootRenderNode = this.rootNode.getRenderNode();
1264    if (rootRenderNode !== null) {
1265      rootRenderNode.appendChild(renderNode);
1266    }
1267
1268    return this.rootNode;
1269  }
1270}
1271
1272@Entry
1273@Component
1274struct Index {
1275  private myNodeController: MyNodeController = new MyNodeController();
1276
1277  build() {
1278    Row() {
1279      NodeContainer(this.myNodeController)
1280    }
1281  }
1282}
1283```
1284
1285### strokeWidth<sup>12+</sup>
1286
1287strokeWidth: number
1288
1289Sets the stroke width for the mask, in px. The default value is **0**.
1290
1291**Atomic service API**: This API can be used in atomic services since API version 12.
1292
1293**System capability**: SystemCapability.ArkUI.ArkUI.Full
1294
1295**Example**
1296
1297```ts
1298import { RenderNode, FrameNode, NodeController, ShapeMask } from '@kit.ArkUI';
1299
1300const mask = new ShapeMask();
1301mask.setRectShape({ left: 0, right: 150, top: 0, bottom: 150 });
1302mask.strokeColor = 0XFFFF0000;
1303mask.strokeWidth = 24;
1304
1305const renderNode = new RenderNode();
1306renderNode.frame = { x: 0, y: 0, width: 150, height: 150 };
1307renderNode.backgroundColor = 0XFF00FF00;
1308renderNode.shapeMask = mask;
1309
1310
1311class MyNodeController extends NodeController {
1312  private rootNode: FrameNode | null = null;
1313
1314  makeNode(uiContext: UIContext): FrameNode | null {
1315    this.rootNode = new FrameNode(uiContext);
1316
1317    const rootRenderNode = this.rootNode.getRenderNode();
1318    if (rootRenderNode !== null) {
1319      rootRenderNode.appendChild(renderNode);
1320    }
1321
1322    return this.rootNode;
1323  }
1324}
1325
1326@Entry
1327@Component
1328struct Index {
1329  private myNodeController: MyNodeController = new MyNodeController();
1330
1331  build() {
1332    Row() {
1333      NodeContainer(this.myNodeController)
1334    }
1335  }
1336}
1337```
1338
1339## ShapeClip<sup>12+</sup>
1340
1341Sets the clipping shape.
1342
1343### constructor<sup>12+</sup>
1344
1345constructor()
1346
1347A constructor used to create a **ShapeClip** object.
1348
1349**System capability**: SystemCapability.ArkUI.ArkUI.Full
1350
1351**Atomic service API**: This API can be used in atomic services since API version 12.
1352
1353### setRectShape<sup>12+</sup>
1354
1355setRectShape(rect: Rect): void
1356
1357Sets a rectangle as the clipping shape.
1358
1359**System capability**: SystemCapability.ArkUI.ArkUI.Full
1360
1361**Atomic service API**: This API can be used in atomic services since API version 12.
1362
1363**Parameters**
1364
1365| Name| Type         | Mandatory| Description        |
1366| ------ | ------------- | ---- | ------------ |
1367| rect   | [Rect](#rect12) | Yes  | Shape of the rectangle.|
1368
1369**Example**
1370
1371```ts
1372import { RenderNode, FrameNode, NodeController, ShapeClip } from '@kit.ArkUI';
1373
1374const clip = new ShapeClip();
1375clip.setCommandPath({ commands: "M100 0 L0 100 L50 200 L150 200 L200 100 Z" });
1376
1377const renderNode = new RenderNode();
1378renderNode.frame = {
1379  x: 0,
1380  y: 0,
1381  width: 150,
1382  height: 150
1383};
1384renderNode.backgroundColor = 0XFF00FF00;
1385renderNode.shapeClip = clip;
1386const shapeClip = renderNode.shapeClip;
1387
1388class MyNodeController extends NodeController {
1389  private rootNode: FrameNode | null = null;
1390
1391  makeNode(uiContext: UIContext): FrameNode | null {
1392    this.rootNode = new FrameNode(uiContext);
1393
1394    const rootRenderNode = this.rootNode.getRenderNode();
1395    if (rootRenderNode !== null) {
1396      rootRenderNode.appendChild(renderNode);
1397    }
1398
1399    return this.rootNode;
1400  }
1401}
1402
1403@Entry
1404@Component
1405struct Index {
1406  private myNodeController: MyNodeController = new MyNodeController();
1407
1408  build() {
1409    Column() {
1410      NodeContainer(this.myNodeController)
1411        .borderWidth(1)
1412      Button("setRectShape")
1413        .onClick(() => {
1414          shapeClip.setRectShape({
1415            left: 0,
1416            right: 150,
1417            top: 0,
1418            bottom: 150
1419          });
1420          renderNode.shapeClip = shapeClip;
1421        })
1422    }
1423  }
1424}
1425```
1426
1427### setRoundRectShape<sup>12+</sup>
1428
1429setRoundRectShape(roundRect: RoundRect): void
1430
1431Sets a rectangle with rounded corners for shape clipping.
1432
1433**System capability**: SystemCapability.ArkUI.ArkUI.Full
1434
1435**Atomic service API**: This API can be used in atomic services since API version 12.
1436
1437**Parameters**
1438
1439| Name   | Type                   | Mandatory| Description            |
1440| --------- | ----------------------- | ---- | ---------------- |
1441| roundRect | [RoundRect](#roundrect12) | Yes  | Shape of the rectangle with rounded corners.|
1442
1443**Example**
1444```ts
1445import { RenderNode, FrameNode, NodeController, ShapeClip } from '@kit.ArkUI';
1446
1447const clip = new ShapeClip();
1448clip.setCommandPath({ commands: "M100 0 L0 100 L50 200 L150 200 L200 100 Z" });
1449
1450const renderNode = new RenderNode();
1451renderNode.frame = {
1452  x: 0,
1453  y: 0,
1454  width: 150,
1455  height: 150
1456};
1457renderNode.backgroundColor = 0XFF00FF00;
1458renderNode.shapeClip = clip;
1459
1460class MyNodeController extends NodeController {
1461  private rootNode: FrameNode | null = null;
1462
1463  makeNode(uiContext: UIContext): FrameNode | null {
1464    this.rootNode = new FrameNode(uiContext);
1465
1466    const rootRenderNode = this.rootNode.getRenderNode();
1467    if (rootRenderNode !== null) {
1468      rootRenderNode.appendChild(renderNode);
1469    }
1470
1471    return this.rootNode;
1472  }
1473}
1474
1475@Entry
1476@Component
1477struct Index {
1478  private myNodeController: MyNodeController = new MyNodeController();
1479
1480  build() {
1481    Column() {
1482      NodeContainer(this.myNodeController)
1483        .borderWidth(1)
1484      Button("setRoundRectShape")
1485        .onClick(() => {
1486          renderNode.shapeClip.setRoundRectShape({
1487            rect: {
1488              left: 0,
1489              top: 0,
1490              right: vp2px(150),
1491              bottom: vp2px(150)
1492            },
1493            corners: {
1494              topLeft: { x: 32, y: 32 },
1495              topRight: { x: 32, y: 32 },
1496              bottomLeft: { x: 32, y: 32 },
1497              bottomRight: { x: 32, y: 32 }
1498            }
1499          });
1500          renderNode.shapeClip = renderNode.shapeClip;
1501        })
1502    }
1503  }
1504}
1505```
1506
1507### setCircleShape<sup>12+</sup>
1508
1509setCircleShape(circle: Circle): void
1510
1511Sets a circle as the clipping shape.
1512
1513**System capability**: SystemCapability.ArkUI.ArkUI.Full
1514
1515**Atomic service API**: This API can be used in atomic services since API version 12.
1516
1517**Parameters**
1518
1519| Name| Type             | Mandatory| Description        |
1520| ------ | ----------------- | ---- | ------------ |
1521| circle | [Circle](#circle12) | Yes  | Round shape.|
1522
1523**Example**
1524
1525```ts
1526import { RenderNode, FrameNode, NodeController, ShapeClip } from '@kit.ArkUI';
1527
1528const clip = new ShapeClip();
1529clip.setCommandPath({ commands: "M100 0 L0 100 L50 200 L150 200 L200 100 Z" });
1530
1531const renderNode = new RenderNode();
1532renderNode.frame = {
1533  x: 0,
1534  y: 0,
1535  width: 150,
1536  height: 150
1537};
1538renderNode.backgroundColor = 0XFF00FF00;
1539renderNode.shapeClip = clip;
1540
1541class MyNodeController extends NodeController {
1542  private rootNode: FrameNode | null = null;
1543
1544  makeNode(uiContext: UIContext): FrameNode | null {
1545    this.rootNode = new FrameNode(uiContext);
1546
1547    const rootRenderNode = this.rootNode.getRenderNode();
1548    if (rootRenderNode !== null) {
1549      rootRenderNode.appendChild(renderNode);
1550    }
1551
1552    return this.rootNode;
1553  }
1554}
1555
1556@Entry
1557@Component
1558struct Index {
1559  private myNodeController: MyNodeController = new MyNodeController();
1560
1561  build() {
1562    Column() {
1563      NodeContainer(this.myNodeController)
1564        .borderWidth(1)
1565      Button("setCircleShape")
1566        .onClick(() => {
1567          renderNode.shapeClip.setCircleShape({ centerY: 75, centerX: 75, radius: 75 });
1568          renderNode.shapeClip = renderNode.shapeClip;
1569
1570        })
1571    }
1572  }
1573}
1574```
1575
1576### setOvalShape<sup>12+</sup>
1577
1578setOvalShape(oval: Rect): void
1579
1580Sets an oval shape as the clipping shape.
1581
1582**System capability**: SystemCapability.ArkUI.ArkUI.Full
1583
1584**Atomic service API**: This API can be used in atomic services since API version 12.
1585
1586**Parameters**
1587
1588| Name| Type         | Mandatory| Description          |
1589| ------ | ------------- | ---- | -------------- |
1590| oval   | [Rect](#rect12) | Yes  | Oval shape.|
1591
1592**Example**
1593
1594```ts
1595import { RenderNode, FrameNode, NodeController, ShapeClip } from '@kit.ArkUI';
1596
1597const clip = new ShapeClip();
1598clip.setCommandPath({ commands: "M100 0 L0 100 L50 200 L150 200 L200 100 Z" });
1599
1600const renderNode = new RenderNode();
1601renderNode.frame = {
1602  x: 0,
1603  y: 0,
1604  width: 150,
1605  height: 150
1606};
1607renderNode.backgroundColor = 0XFF00FF00;
1608renderNode.shapeClip = clip;
1609
1610class MyNodeController extends NodeController {
1611  private rootNode: FrameNode | null = null;
1612
1613  makeNode(uiContext: UIContext): FrameNode | null {
1614    this.rootNode = new FrameNode(uiContext);
1615
1616    const rootRenderNode = this.rootNode.getRenderNode();
1617    if (rootRenderNode !== null) {
1618      rootRenderNode.appendChild(renderNode);
1619    }
1620
1621    return this.rootNode;
1622  }
1623}
1624
1625@Entry
1626@Component
1627struct Index {
1628  private myNodeController: MyNodeController = new MyNodeController();
1629
1630  build() {
1631    Column() {
1632      NodeContainer(this.myNodeController)
1633        .borderWidth(1)
1634      Button("setOvalShape")
1635        .onClick(() => {
1636          renderNode.shapeClip.setOvalShape({
1637            left: 0,
1638            right: vp2px(150),
1639            top: 0,
1640            bottom: vp2px(100)
1641          });
1642          renderNode.shapeClip = renderNode.shapeClip;
1643        })
1644    }
1645  }
1646}
1647```
1648
1649### setCommandPath<sup>12+</sup>
1650
1651setCommandPath(path: CommandPath): void
1652
1653Sets the command for drawing a path.
1654
1655**System capability**: SystemCapability.ArkUI.ArkUI.Full
1656
1657**Atomic service API**: This API can be used in atomic services since API version 12.
1658
1659**Parameters**
1660
1661| Name| Type                       | Mandatory| Description          |
1662| ------ | --------------------------- | ---- | -------------- |
1663| path   | [CommandPath](#commandpath12) | Yes  | Command for drawing a path.|
1664
1665**Example**
1666
1667```ts
1668import { RenderNode, FrameNode, NodeController, ShapeClip } from '@kit.ArkUI';
1669
1670const clip = new ShapeClip();
1671clip.setCommandPath({ commands: "M100 0 L0 100 L50 200 L150 200 L200 100 Z" });
1672
1673const renderNode = new RenderNode();
1674renderNode.frame = { x: 0, y: 0, width: 150, height: 150 };
1675renderNode.backgroundColor = 0XFF00FF00;
1676renderNode.shapeClip = clip;
1677
1678class MyNodeController extends NodeController {
1679  private rootNode: FrameNode | null = null;
1680
1681  makeNode(uiContext: UIContext): FrameNode | null {
1682    this.rootNode = new FrameNode(uiContext);
1683
1684    const rootRenderNode = this.rootNode.getRenderNode();
1685    if (rootRenderNode !== null) {
1686      rootRenderNode.appendChild(renderNode);
1687    }
1688
1689    return this.rootNode;
1690  }
1691}
1692
1693@Entry
1694@Component
1695struct Index {
1696  private myNodeController: MyNodeController = new MyNodeController();
1697
1698  build() {
1699    Column() {
1700      NodeContainer(this.myNodeController)
1701        .borderWidth(1)
1702      Button("setCommandPath")
1703        .onClick(()=>{
1704          renderNode.shapeClip.setCommandPath({ commands: "M100 0 L0 100 L50 200 L150 200 L200 100 Z" });
1705          renderNode.shapeClip = renderNode.shapeClip;
1706        })
1707    }
1708  }
1709}
1710```
1711
1712## edgeColors<sup>12+</sup>
1713
1714edgeColors(all: number): Edges\<number>
1715
1716Generates an **edgeColors** object with the specified edge color for all edges.
1717
1718**Atomic service API**: This API can be used in atomic services since API version 12.
1719
1720**System capability**: SystemCapability.ArkUI.ArkUI.Full
1721
1722**Parameters**
1723
1724| Name| Type  | Mandatory| Description                |
1725| ------ | ------ | ---- | -------------------- |
1726| all    | number | Yes  | Edge color, in ARGB format, for example, **0xffff00ff**.<br>Value range: [0, 0xffffffff]|
1727
1728**Return value**
1729
1730| Type                    | Description                                  |
1731| ------------------------ | -------------------------------------- |
1732| [Edges\<number>](#edgest12) | **edgeColors** object whose edge colors are all at the specified value.|
1733
1734**Example**
1735
1736```ts
1737import { RenderNode, FrameNode, NodeController, edgeColors } from '@kit.ArkUI';
1738
1739const renderNode = new RenderNode();
1740renderNode.frame = { x: 0, y: 0, width: 150, height: 150 };
1741renderNode.backgroundColor = 0XFF00FF00;
1742renderNode.borderWidth = { left: 8, top: 8, right: 8, bottom: 8 };
1743renderNode.borderColor = edgeColors(0xFF0000FF);
1744
1745
1746class MyNodeController extends NodeController {
1747  private rootNode: FrameNode | null = null;
1748
1749  makeNode(uiContext: UIContext): FrameNode | null {
1750    this.rootNode = new FrameNode(uiContext);
1751
1752    const rootRenderNode = this.rootNode.getRenderNode();
1753    if (rootRenderNode !== null) {
1754      rootRenderNode.appendChild(renderNode);
1755    }
1756
1757    return this.rootNode;
1758  }
1759}
1760
1761@Entry
1762@Component
1763struct Index {
1764  private myNodeController: MyNodeController = new MyNodeController();
1765
1766  build() {
1767    Row() {
1768      NodeContainer(this.myNodeController)
1769    }
1770  }
1771}
1772```
1773
1774## edgeWidths<sup>12+</sup>
1775
1776edgeWidths(all: number): Edges\<number>
1777
1778Generates an **edgeWidths** object with the specified edge width for all edges.
1779
1780**Atomic service API**: This API can be used in atomic services since API version 12.
1781
1782**System capability**: SystemCapability.ArkUI.ArkUI.Full
1783
1784**Parameters**
1785
1786| Name| Type  | Mandatory| Description                |
1787| ------ | ------ | ---- | -------------------- |
1788| all    | number | Yes  | Edge width, in vp.<br>Value range: [0, +∞)|
1789
1790**Return value**
1791
1792| Type                    | Description                                  |
1793| ------------------------ | -------------------------------------- |
1794| [Edges\<number>](#edgest12) | **edgeWidths** object whose edge widths are all at the specified value.|
1795
1796**Example**
1797
1798```ts
1799import { RenderNode, FrameNode, NodeController, edgeWidths } from '@kit.ArkUI';
1800
1801const renderNode = new RenderNode();
1802renderNode.frame = { x: 0, y: 0, width: 150, height: 150 };
1803renderNode.backgroundColor = 0XFF00FF00;
1804renderNode.borderWidth = edgeWidths(8);
1805renderNode.borderColor = { left: 0xFF0000FF, top: 0xFF0000FF, right: 0xFF0000FF, bottom: 0xFF0000FF };
1806
1807
1808class MyNodeController extends NodeController {
1809  private rootNode: FrameNode | null = null;
1810
1811  makeNode(uiContext: UIContext): FrameNode | null {
1812    this.rootNode = new FrameNode(uiContext);
1813
1814    const rootRenderNode = this.rootNode.getRenderNode();
1815    if (rootRenderNode !== null) {
1816      rootRenderNode.appendChild(renderNode);
1817    }
1818
1819    return this.rootNode;
1820  }
1821}
1822
1823@Entry
1824@Component
1825struct Index {
1826  private myNodeController: MyNodeController = new MyNodeController();
1827
1828  build() {
1829    Row() {
1830      NodeContainer(this.myNodeController)
1831    }
1832  }
1833}
1834```
1835
1836## borderStyles<sup>12+</sup>
1837
1838borderStyles(all: BorderStyle): Edges\<BorderStyle>
1839
1840Generates a **borderStyles** object with the specified border style color for all borders.
1841
1842**Atomic service API**: This API can be used in atomic services since API version 12.
1843
1844**System capability**: SystemCapability.ArkUI.ArkUI.Full
1845
1846**Parameters**
1847
1848| Name| Type                                                      | Mandatory| Description      |
1849| ------ | ---------------------------------------------------------- | ---- | ---------- |
1850| all    | [BorderStyle](./arkui-ts/ts-appendix-enums.md#borderstyle) | Yes  | Border style.|
1851
1852**Return value**
1853
1854| Type                                                                       | Description                                  |
1855| --------------------------------------------------------------------------- | -------------------------------------- |
1856| [Edges](#edgest12)<[BorderStyle](./arkui-ts/ts-appendix-enums.md#borderstyle)> | **borderStyles** object whose borders are all in the specified style.|
1857
1858**Example**
1859
1860```ts
1861import { RenderNode, FrameNode, NodeController, borderStyles } from '@kit.ArkUI';
1862
1863const renderNode = new RenderNode();
1864renderNode.frame = { x: 0, y: 0, width: 150, height: 150 };
1865renderNode.backgroundColor = 0XFF00FF00;
1866renderNode.borderWidth = { left: 8, top: 8, right: 8, bottom: 8 };
1867renderNode.borderColor = { left: 0xFF0000FF, top: 0xFF0000FF, right: 0xFF0000FF, bottom: 0xFF0000FF };
1868renderNode.borderStyle = borderStyles(BorderStyle.Dotted);
1869
1870
1871class MyNodeController extends NodeController {
1872  private rootNode: FrameNode | null = null;
1873
1874  makeNode(uiContext: UIContext): FrameNode | null {
1875    this.rootNode = new FrameNode(uiContext);
1876
1877    const rootRenderNode = this.rootNode.getRenderNode();
1878    if (rootRenderNode !== null) {
1879      rootRenderNode.appendChild(renderNode);
1880    }
1881
1882    return this.rootNode;
1883  }
1884}
1885
1886@Entry
1887@Component
1888struct Index {
1889  private myNodeController: MyNodeController = new MyNodeController();
1890
1891  build() {
1892    Row() {
1893      NodeContainer(this.myNodeController)
1894    }
1895  }
1896}
1897```
1898
1899## borderRadiuses<sup>12+</sup>
1900
1901borderRadiuses(all: number): BorderRadiuses
1902
1903Generates a **borderRadiuses** object with the specified radius for all border corners.
1904
1905**Atomic service API**: This API can be used in atomic services since API version 12.
1906
1907**System capability**: SystemCapability.ArkUI.ArkUI.Full
1908
1909**Parameters**
1910
1911| Name| Type  | Mandatory| Description      |
1912| ------ | ------ | ---- | ---------- |
1913| all    | number | Yes  | Radius of border corners.<br>Unit: vp<br>Value range: [0, +∞)|
1914
1915**Return value**
1916
1917| Type                             | Description                                  |
1918| --------------------------------- | -------------------------------------- |
1919| [BorderRadiuses](#borderradiuses12) | **borderRadiuses** object whose border corners all have the specified radius.|
1920
1921**Example**
1922
1923```ts
1924import { RenderNode, FrameNode, NodeController, borderRadiuses }  from '@kit.ArkUI';
1925
1926const renderNode = new RenderNode();
1927renderNode.frame = { x: 0, y: 0, width: 150, height: 150 };
1928renderNode.backgroundColor = 0XFF00FF00;
1929renderNode.borderRadius = borderRadiuses(32);
1930
1931
1932class MyNodeController extends NodeController {
1933  private rootNode: FrameNode | null = null;
1934
1935  makeNode(uiContext: UIContext): FrameNode | null {
1936    this.rootNode = new FrameNode(uiContext);
1937
1938    const rootRenderNode = this.rootNode.getRenderNode();
1939    if (rootRenderNode !== null) {
1940      rootRenderNode.appendChild(renderNode);
1941    }
1942
1943    return this.rootNode;
1944  }
1945}
1946
1947@Entry
1948@Component
1949struct Index {
1950  private myNodeController: MyNodeController = new MyNodeController();
1951
1952  build() {
1953    Row() {
1954      NodeContainer(this.myNodeController)
1955    }
1956  }
1957}
1958```
1959