Skip to main content

Editor.Rect

Class

Represents a 2D rectangle with position and dimensions.

Index

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: 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()

static create(left, right, bottom, top): Rect

Creates a new Rect instance.

Parameters

ParameterType
leftnumber
rightnumber
bottomnumber
topnumber

Returns

Rect


fromMinMax()

static fromMinMax(min, max): Rect

Creates a Rect from minimum and maximum corner points.

Parameters

ParameterType
minvec2
maxvec2

Returns

Rect


getCenter()

getCenter(): vec2

Returns the center point of the rectangle as a vec2.

Returns

vec2


getSize()

getSize(): vec2

Returns the width and height of the rectangle as a vec2.

Returns

vec2


setCenter()

setCenter(center): void

Moves the rectangle so its center is at the given vec2 position.

Parameters

ParameterType
centervec2

Returns

void


setSize()

setSize(size): void

Sets the width and height of the rectangle from a vec2.

Parameters

ParameterType
sizevec2

Returns

void


toVec4()

toVec4(): vec4

Converts the rectangle to a vec4 (left, bottom, right, top).

Returns

vec4