Table of Contents

Struct Size

Namespace
Avalonia
Assembly
Avalonia.Base.dll

Defines a size.

public readonly struct Size : IEquatable<Size>
Implements
Inherited Members

Constructors

Size(double, double)

Initializes a new instance of the Size structure.

public Size(double width, double height)

Parameters

width double

The width.

height double

The height.

Size(Vector2)

Initializes a new instance of the Size structure.

public Size(Vector2 vector2)

Parameters

vector2 Vector2

The vector to take values from.

Fields

Infinity

A size representing infinity.

public static readonly Size Infinity

Field Value

Size

Properties

AspectRatio

Gets the aspect ratio of the size.

public double AspectRatio { get; }

Property Value

double

Height

Gets the height.

public double Height { get; }

Property Value

double

Width

Gets the width.

public double Width { get; }

Property Value

double

Methods

Constrain(Size)

Constrains the size.

public Size Constrain(Size constraint)

Parameters

constraint Size

The size to constrain to.

Returns

Size

The constrained size.

Deconstruct(out double, out double)

Deconstructs the size into its Width and Height values.

public void Deconstruct(out double width, out double height)

Parameters

width double

The width.

height double

The height.

Deflate(Thickness)

Deflates the size by a Thickness.

public Size Deflate(Thickness thickness)

Parameters

thickness Thickness

The thickness.

Returns

Size

The deflated size.

Remarks

The deflated size cannot be less than 0.

Equals(Size)

Returns a boolean indicating whether the size is equal to the other given size (bitwise).

public bool Equals(Size other)

Parameters

other Size

The other size to test equality against.

Returns

bool

True if this size is equal to other; False otherwise.

Equals(object?)

Checks for equality between a size and an object.

public override bool Equals(object? obj)

Parameters

obj object

The object.

Returns

bool

True if obj is a size that equals the current size.

GetHashCode()

Returns a hash code for a Size.

public override int GetHashCode()

Returns

int

The hash code.

Inflate(Thickness)

Inflates the size by a Thickness.

public Size Inflate(Thickness thickness)

Parameters

thickness Thickness

The thickness.

Returns

Size

The inflated size.

NearlyEquals(Size)

Returns a boolean indicating whether the size is equal to the other given size (numerically).

public bool NearlyEquals(Size other)

Parameters

other Size

The other size to test equality against.

Returns

bool

True if this size is equal to other; False otherwise.

Parse(string)

Parses a Size string.

public static Size Parse(string s)

Parameters

s string

The string.

Returns

Size

The Size.

ToString()

Returns the string representation of the size.

public override string ToString()

Returns

string

The string representation of the size.

WithHeight(double)

Returns a new Size with the same width and the specified height.

public Size WithHeight(double height)

Parameters

height double

The height.

Returns

Size

The new Size.

WithWidth(double)

Returns a new Size with the same height and the specified width.

public Size WithWidth(double width)

Parameters

width double

The width.

Returns

Size

The new Size.

Operators

operator +(Size, Size)

public static Size operator +(Size size, Size toAdd)

Parameters

size Size
toAdd Size

Returns

Size

operator /(Size, Size)

Divides a size by another size to produce a scaling factor.

public static Vector operator /(Size left, Size right)

Parameters

left Size

The first size

right Size

The second size.

Returns

Vector

The scaled size.

operator /(Size, Vector)

Scales a size.

public static Size operator /(Size size, Vector scale)

Parameters

size Size

The size

scale Vector

The scaling factor.

Returns

Size

The scaled size.

operator /(Size, double)

Scales a size.

public static Size operator /(Size size, double scale)

Parameters

size Size

The size

scale double

The scaling factor.

Returns

Size

The scaled size.

operator ==(Size, Size)

Checks for equality between two Sizes.

public static bool operator ==(Size left, Size right)

Parameters

left Size

The first size.

right Size

The second size.

Returns

bool

True if the sizes are equal; otherwise false.

operator !=(Size, Size)

Checks for inequality between two Sizes.

public static bool operator !=(Size left, Size right)

Parameters

left Size

The first size.

right Size

The second size.

Returns

bool

True if the sizes are unequal; otherwise false.

operator *(Size, Vector)

Scales a size.

public static Size operator *(Size size, Vector scale)

Parameters

size Size

The size

scale Vector

The scaling factor.

Returns

Size

The scaled size.

operator *(Size, double)

Scales a size.

public static Size operator *(Size size, double scale)

Parameters

size Size

The size

scale double

The scaling factor.

Returns

Size

The scaled size.

operator -(Size, Size)

public static Size operator -(Size size, Size toSubtract)

Parameters

size Size
toSubtract Size

Returns

Size