Editor.Rect
ClassRepresents a 2D rectangle with position and dimensions.
Index
Properties
Methods
Example
// Editor.Rect is a 2D axis-aligned rectangle defined by left/right/bottom/top
// edges. It is used by ScreenTransform to express its anchor and offset
// rectangles relative to the parent canvas.
const model = this.pluginSystem.findInterface(Editor.Model.IModel) as Editor.Model.IModel;
const scene = model.project.scene;
const obj = scene.createSceneObject('UiElement');
const st = obj.addComponent('ScreenTransform') as Editor.Components.ScreenTransform;
// Anchor to the full parent rect (0..1 on both axes).
st.anchor = Editor.Rect.fromMinMax(new vec2(0, 0), new vec2(1, 1));
// Offset expressed in points: shrink by 20 on every side.
const offset = Editor.Rect.create(20, -20, 20, -20);
st.offset = offset;
console.log(`offset size: ${offset.getSize()}, center: ${offset.getCenter()}`);
Constructors
Constructor
new Rect():
Rect
Constructs a new Rect with default zero values.
Returns
Rect
Properties
bottom
bottom:
number
Y coordinate of the bottom edge.
left
left:
number
X coordinate of the left edge.
leftBottom
leftBottom:
vec2
Corner point at the left and bottom edges as a vec2.
right
right:
number
X coordinate of the right edge.
rightTop
rightTop:
vec2
Corner point at the right and top edges as a vec2.
top
top:
number
Y coordinate of the top edge.
Methods
create()
staticcreate(left,right,bottom,top):Rect
Creates a new Rect instance.
Parameters
| Parameter | Type |
|---|---|
left | number |
right | number |
bottom | number |
top | number |
Returns
Rect
fromMinMax()
staticfromMinMax(min,max):Rect
Creates a Rect from minimum and maximum corner points.
Parameters
Returns
Rect
getCenter()
getCenter():
vec2
Returns the center point of the rectangle as a vec2.
Returns
getSize()
getSize():
vec2
Returns the width and height of the rectangle as a vec2.
Returns
setCenter()
setCenter(
center):void
Moves the rectangle so its center is at the given vec2 position.
Parameters
| Parameter | Type |
|---|---|
center | vec2 |
Returns
void
setSize()
setSize(
size):void
Sets the width and height of the rectangle from a vec2.
Parameters
| Parameter | Type |
|---|---|
size | vec2 |
Returns
void
toVec4()
toVec4():
vec4
Converts the rectangle to a vec4 (left, bottom, right, top).