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