s&box docs

public sealed struct Sandbox.Rect

Represents a rectangle.

Broader workflow and conceptual references connected to this API.

Constructors

Showing 2 constructors

Methods

Showing 22 methods

public Sandbox.Rect AddPoint(Vector2 pos)

Returns this rect expanded to include this point

public Sandbox.Rect Align(Vector2 size, Sandbox.TextFlag align)

Align the smaller rect inside this rect. Default alignment on each axis is Top, Left.

public Sandbox.Rect Ceiling()

Returns a Rect with position and size rounded up.

public Vector2 ClosestPoint(Vector2 point)

Returns the closest point on this rect to another point

public Sandbox.Rect Contain(Vector2 size, Sandbox.TextFlag align = 132, bool stretch = False)

Contain a given rectangle (image) within this rectangle (frame), preserving aspect ratio.

Parameters

  • size: Size of the rectagle (image) to try to contain within this frame rectangle.
  • align: Where to align the given box within this rectangle. Default: 132
  • stretch: Whether to stretch the given rectagle (image) should its size be smaller than largest rectagle (image) size possible within this rectangle (frame). Default: False

Returns

A rectangle with correct position and size to fit within the "parent" rectangle.

public Sandbox.Rect Floor()

Returns a Rect with position and size rounded down.

public static Sandbox.Rect FromPoints(Vector2 a, Vector2 b)

Create a rect between two points. The order of the points doesn't matter.

public Sandbox.Rect Round()

Returns a Rect with position and size rounded to closest integer values.

public Sandbox.Rect SnapToGrid()

Align to a grid

public Vector4 ToVector4()

Returns this rect as a Vector4, where X/Y/Z/W are Left/Top/Right/Bottom respectively.

Properties

Showing 14 properties

public float Sandbox.Rect.Bottom { get; set; }

Position of rect's bottom edge relative to its parent.

public Vector2 Sandbox.Rect.BottomLeft { get; set; }

Position of the bottom left edge of this rect.

public Vector2 Sandbox.Rect.BottomRight { get; set; }

Position of the bottom right edge of this rect.

public Vector2 Sandbox.Rect.Center { get; set; }

Center of this rect.

public float Sandbox.Rect.Height { get; set; }

Height of the rect.

public float Sandbox.Rect.Left { get; set; }

Position of rect's left edge relative to its parent, can also be interpreted as its position on the X axis.

public float Sandbox.Rect.Right { get; set; }

Position of rect's right edge relative to its parent.

public Vector2 Sandbox.Rect.Size { get; set; }

Size of this rect.

public float Sandbox.Rect.Top { get; set; }

Position of rect's top edge relative to its parent, can also be interpreted as its position on the Y axis.

public Vector2 Sandbox.Rect.TopLeft { get; set; }

Position of the top left edge of this rect.

public Vector2 Sandbox.Rect.TopRight { get; set; }

Position of the top right edge of this rect.

public float Sandbox.Rect.Width { get; set; }

Width of the rect.

public Sandbox.Rect Sandbox.Rect.WithoutPosition { get; set; }

Returns this rect with position set to 0 on both axes.

Metadata

FieldValue
NamespaceSandbox
Typeclass
AssemblySandbox.System
Doc IDT:Sandbox.Rect

On this page

Constructorspublic Rect(System.Single x, System.Single y, System.Single width, System.Single height)public Rect(Vector2 point, Vector2 size = null)Methodspublic System.Void Add(Sandbox.Rect r)public System.Void Add(Vector2 point)public Sandbox.Rect AddPoint(Vector2 pos)public Sandbox.Rect Align(Vector2 size, Sandbox.TextFlag align)public Sandbox.Rect Ceiling()public Vector2 ClosestPoint(Vector2 point)public Sandbox.Rect Contain(Vector2 size, Sandbox.TextFlag align = 132, System.Boolean stretch = False)public Sandbox.Rect Floor()public static Sandbox.Rect FromPoints(Vector2 a, Vector2 b)public Sandbox.Rect Grow(Sandbox.UI.Margin m)public Sandbox.Rect Grow(System.Single left, System.Single top, System.Single right, System.Single bottom)public Sandbox.Rect Grow(System.Single x, System.Single y)public Sandbox.Rect Grow(System.Single amt)public System.Boolean IsInside(Sandbox.Rect rect, System.Boolean fullyInside = False)public System.Boolean IsInside(Vector2 pos)public Sandbox.Rect Round()public Sandbox.Rect Shrink(Sandbox.UI.Margin m)public Sandbox.Rect Shrink(System.Single left, System.Single top, System.Single right, System.Single bottom)public Sandbox.Rect Shrink(System.Single x, System.Single y)public Sandbox.Rect Shrink(System.Single amt)public Sandbox.Rect SnapToGrid()public Vector4 ToVector4()Propertiespublic System.Single Sandbox.Rect.Bottom { get; set; }public Vector2 Sandbox.Rect.BottomLeft { get; set; }public Vector2 Sandbox.Rect.BottomRight { get; set; }public Vector2 Sandbox.Rect.Center { get; set; }public System.Single Sandbox.Rect.Height { get; set; }public System.Single Sandbox.Rect.Left { get; set; }public Vector2 Sandbox.Rect.Position { get; set; }public System.Single Sandbox.Rect.Right { get; set; }public Vector2 Sandbox.Rect.Size { get; set; }public System.Single Sandbox.Rect.Top { get; set; }public Vector2 Sandbox.Rect.TopLeft { get; set; }public Vector2 Sandbox.Rect.TopRight { get; set; }public System.Single Sandbox.Rect.Width { get; set; }public Sandbox.Rect Sandbox.Rect.WithoutPosition { get; set; }Metadata