DesktopWindowBounds record

Namespace Runic.Desktop in Runic.Desktop 0.23.0

public sealed record DesktopWindowBounds : IEquatable<DesktopWindowBounds>

Inherits or implements IEquatable.

A window's frame in the platform's native window units, exactly as DesktopWindow.SetBoundsAsync takes it: DesktopWindowState.Bounds read from a window sets the same frame again, to the pixel.

Remarks

Unlike DesktopWindowState.X, DesktopWindowState.Y, DesktopWindowState.Width and DesktopWindowState.Height, which keep the units of DesktopWindow.MoveAsync and DesktopWindow.ResizeAsync (and of saved placements), all four values here use one unit, so they never round:

A length in device-independent pixels (points, logical pixels), such as the width of a panel, becomes native units with DesktopWindowBounds.Scale; DesktopWindowBounds.Expand does this once, so growing a window and shrinking it by the same length returns exactly the bounds it started from. At 150 % a window 1001 pixels wide grows by 372 to 1559 pixels and shrinks back to 1001.

A custom window host (IDesktopBoundsWindowHost) defines its own units and documents them.

Constructors

DesktopWindowBounds

public DesktopWindowBounds()

No documentation.

Properties

Height

public int Height { get; init; }

Gets the height in native units.

Scale

public double Scale { get; init; }

Gets the native units per device-independent pixel when the bounds were read: the window's DPI divided by 96 on Windows, and 1 on macOS (points) and Linux (logical pixels). Defaults to 1.

Remarks

DesktopWindowBounds.Expand uses it to convert lengths. DesktopWindow.SetBoundsAsync ignores it: native units do not depend on the scale.

Width

public int Width { get; init; }

Gets the width in native units.

X

public int? X { get; init; }

Gets the horizontal position of the top-left corner, or null where the platform reports no position (Wayland) or to keep the window where it is.

Remarks

Applies only together with DesktopWindowBounds.Y.

Y

public int? Y { get; init; }

Gets the vertical position of the top-left corner, or null where the platform reports no position (Wayland) or to keep the window where it is.

Remarks

Applies only together with DesktopWindowBounds.X.

Methods

Expand

public DesktopWindowBounds Expand(DesktopWindowEdge edge, double length, DesktopLayoutDirection layoutDirection = (DesktopLayoutDirection)0)

Returns these bounds grown on one edge by a length in device-independent pixels (points on macOS, logical pixels on Linux), or shrunk by a negative length.

Parameters

edge

The edge that moves. DesktopWindowEdge.Left moves DesktopWindowBounds.X and changes the width, so the right edge stays where it is; DesktopWindowEdge.Right keeps DesktopWindowBounds.X. DesktopWindowEdge.Start and DesktopWindowEdge.End follow layoutDirection.

length

The length to add to the width, converted to native units with DesktopWindowBounds.Scale and rounded once, half away from zero.

layoutDirection

The direction that resolves DesktopWindowEdge.Start and DesktopWindowEdge.End, such as the window's DesktopWindowOptions.LayoutDirection: right to left makes the start the right edge; DesktopLayoutDirection.Default and left to right make it the left edge.

Returns

The new bounds, with the same DesktopWindowBounds.Scale.

Exceptions

ArgumentOutOfRangeException

edge or layoutDirection is not a defined value, length is not finite, or the width would not stay positive.

InvalidOperationException

The left edge would move but the bounds have no position (Wayland, where a window cannot be moved), or DesktopWindowBounds.Scale is not a positive finite number.

Remarks

A length rounds to the same number of native units whether it is added or removed, so bounds.Expand(edge, length).Expand(edge, -length) equals bounds.