Table of Contents

Struct WindowPosition

Namespace
Sdl3Sharp.Video.Windowing
Assembly
Sdl3Sharp.dll

Represents a window position, which can be either a definite window coordinate value, a centered position, or an undefined position

public readonly struct WindowPosition : IEquatable<WindowPosition>, ISpanFormattable, IFormattable, IEqualityOperators<WindowPosition, WindowPosition, bool>
Implements
Inherited Members

Remarks

If the WindowPosition represents a centered position or an undefined position, it can be optionally associated with a specific Display where the centered or undefined position is applicable. Otherwise, if the WindowPosition isn't associated with any specific Display, then the centered or undefined position is applicable to the primary display.

You can use the TryGetValue(out int), TryGetCentered(out Display?), and TryGetUndefined(out Display?) methods to determine whether a WindowPosition represents a definite window coordinate value, a centered position, or an undefined position, and to extract the associated value or Display, if any, accordingly.

Constructors

WindowPosition(int)

Creates a new WindowPosition representing the specified definite window coordinate

public WindowPosition(int value)

Parameters

value int

The definite window coordinate value

Remarks

This constructor can be used to create a WindowPosition with a specific, definite window coordinate for its value.

values passed to specify the window coordinate are technically limited to not be in the range from 536805376 (0x1FFF0000) to 805306367 (0x2FFFFFFF) (inclusive). However, in practice, this shouldn't be an issue since window coordinate values very rarely are within this range. Note that this constructor doesn't fail if a given value is within this range, it instead just accepts the given value as is. This means that, given such a value, the resulting WindowPosition may represent false or invalid window positions.

Properties

Centered

Gets a WindowPosition representing a centered position on the primary display

public static WindowPosition Centered { get; }

Property Value

WindowPosition

A WindowPosition representing a centered position on the primary display

Remarks

If you want to specify a centered position on a specific display, you can use the CenteredOn(Display) method instead.

Undefined

Gets a WindowPosition representing an undefined position on the primary display

public static WindowPosition Undefined { get; }

Property Value

WindowPosition

A WindowPosition representing an undefined position on the primary display

Remarks

This can be used to represent a "don't know" or "don't care" position, which is always going to be treated as if it were on the primary display. If you want to specify an undefined position on a specific display, you can use the UndefinedOn(Display) method instead.

Methods

CenteredOn(Display)

Gets a WindowPosition representing a centered position on the specified display

public static WindowPosition CenteredOn(Display display)

Parameters

display Display

The display on which to center the window coordinate

Returns

WindowPosition

A WindowPosition representing a centered position on the specified display

Remarks

If you want to specify a centered position on the primary display, you can use the Centered property instead.

Displays used by this method are technically limited to having an Id of 65535 or less. However, in practice, this shouldn't be an issue since display ids very rarely exceed this value. Note that this method doesn't fail if given a display with an id larger than 65535, it instead always just takes the lower 16 bits of the display id.

Equals(WindowPosition)

Indicates whether the current object is equal to another object of the same type.

public bool Equals(WindowPosition other)

Parameters

other WindowPosition

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and this instance are the same type and represent the same value; otherwise, false.

GetHashCode()

Returns the hash code for this instance.

public override int GetHashCode()

Returns

int

A 32-bit signed integer that is the hash code for this instance.

ToString()

Returns the fully qualified type name of this instance.

public override string ToString()

Returns

string

The fully qualified type name.

ToString(IFormatProvider?)

Formats the value of the current instance using the specified format.

public string ToString(IFormatProvider? formatProvider)

Parameters

formatProvider IFormatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns

string

The value of the current instance in the specified format.

ToString(string?)

Formats the value of the current instance using the specified format.

public string ToString(string? format)

Parameters

format string

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

Returns

string

The value of the current instance in the specified format.

ToString(string?, IFormatProvider?)

Formats the value of the current instance using the specified format.

public string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string

The format to use.

-or-

A null reference (Nothing in Visual Basic) to use the default format defined for the type of the IFormattable implementation.

formatProvider IFormatProvider

The provider to use to format the value.

-or-

A null reference (Nothing in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system.

Returns

string

The value of the current instance in the specified format.

TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)

Tries to format the value of the current instance into the provided span of characters.

public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)

Parameters

destination Span<char>

The span in which to write this instance's value formatted as a span of characters.

charsWritten int

When this method returns, contains the number of characters that were written in destination.

format ReadOnlySpan<char>

A span containing the characters that represent a standard or custom format string that defines the acceptable format for destination.

provider IFormatProvider

An optional object that supplies culture-specific formatting information for destination.

Returns

bool

true if the formatting was successful; otherwise, false.

TryGetCentered(out Display?)

Tries to determine whether this WindowPosition represents a centered position and, if so, gets the associated Display, if any

public bool TryGetCentered(out Display? display)

Parameters

display Display

The associated Display, or null if this WindowPosition represents a centered position on the primary display

Returns

bool

true, if this WindowPosition represents a centered position; otherwise, false

Remarks

If this method returns true and the value of the display parameter is null, then this WindowPosition represents a centered position on the primary display. The value of the display parameter is always going to be null, if this method returns false.

TryGetUndefined(out Display?)

Tries to determine whether this WindowPosition represents an undefined position and, if so, gets the associated Display, if any

public bool TryGetUndefined(out Display? display)

Parameters

display Display

The associated Display, or null if this WindowPosition represents an undefined position on the primary display

Returns

bool

true, if this WindowPosition represents an undefined position; otherwise, false

Remarks

If this method returns true and the value of the display parameter is null, then this WindowPosition represents an undefined position on the primary display. The value of the display parameter is always going to be null, if this method returns false.

TryGetValue(out int)

Tries to determine whether this WindowPosition represents a definite window coordinate and, if so, gets the associated value

public bool TryGetValue(out int value)

Parameters

value int

The definite window coordinate value

Returns

bool

true, if this WindowPosition represents a definite window coordinate; otherwise, false

Remarks

This method will return true if and only if TryGetCentered(out Display?) and TryGetUndefined(out Display?) would both return false.

UndefinedOn(Display)

Gets a WindowPosition representing an undefined position on the specified display

public static WindowPosition UndefinedOn(Display display)

Parameters

display Display

The display on which to specify the undefined window coordinate

Returns

WindowPosition

A WindowPosition representing an undefined position on the specified display

Remarks

This can be used to represent a "don't know" or "don't care" position on a specific display, which is always going to be treated as if it were on the specified display. If you want to specify an undefined position on the primary display, you can use the Undefined property instead.

Displays used by this method are technically limited to having an Id of 65535 or less. However, in practice, this shouldn't be an issue since display ids very rarely exceed this value. Note that this method doesn't fail if given a display with an id larger than 65535, it instead always just takes the lower 16 bits of the display id.

Operators

operator ==(WindowPosition, WindowPosition)

Compares two values to determine equality.

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

Parameters

left WindowPosition

The value to compare with right.

right WindowPosition

The value to compare with left.

Returns

bool

true if left is equal to right; otherwise, false.

explicit operator int(WindowPosition)

Converts this WindowPosition into a definite window coordinate value

public static explicit operator int(WindowPosition position)

Parameters

position WindowPosition

The WindowPosition to convert

Returns

int

Remarks

Note that this operator will throw an InvalidOperationException if the WindowPosition does not represent a definite window coordinate value.

Exceptions

InvalidOperationException

The WindowPosition does not represent a definite window coordinate value

implicit operator WindowPosition(int)

Converts a definite window coordinate value into a WindowPosition representing that value

public static implicit operator WindowPosition(int value)

Parameters

value int

The definite window coordinate value to convert

Returns

WindowPosition

Remarks

values passed to specify the window coordinate are technically limited to not be in the range from 536805376 to 805306367 (inclusive). However, in practice, this shouldn't be an issue since window coordinate values very rarely are within this range. Note that this operator doesn't fail if a given value is within this range, it instead just accepts the given value as is. This means that, given such a value, the resulting WindowPosition may represent false or invalid window positions.

operator !=(WindowPosition, WindowPosition)

Compares two values to determine inequality.

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

Parameters

left WindowPosition

The value to compare with right.

right WindowPosition

The value to compare with left.

Returns

bool

true if left is not equal to right; otherwise, false.