Skip to content

ui::Rect

Header: winui/core/Geometry.hpp.

Axis-aligned rectangle: (x, y) is the top-left, extents are width/height.

All values are DIPs. The layout rect handed to Element::arrange() is a Rect; a rect with a non-positive extent is empty().

Example:

const ui::Rect bounds{0, 0, 200, 32};
const ui::Rect content = bounds.inset(ui::Edges{.left = 12, .top = 5, .right = 12, .bottom = 6});
const ui::Rect focus   = bounds.inflate(3.0f); // focus visual outside the border
const ui::Rect visible = ui::intersection(content, ui::Rect{0, 0, 100, 100}); // {12, 5, 88, 21}

x

float x = 0.0f

Left edge, DIPs.

y

float y = 0.0f

Top edge, DIPs.

width

float width = 0.0f

Horizontal extent, DIPs.

height

float height = 0.0f

Vertical extent, DIPs.

Rect

constexpr Rect() = default

The empty rect at the origin.

Rect

constexpr Rect(float x_, float y_, float w_, float h_)

From top-left corner and extents.

Rect

constexpr Rect(Point origin, Size size)

From top-left corner and a Size.

left

float left() const

Same as x.

top

float top() const

Same as y.

float right() const

x + width: the first x coordinate outside the rect.

bottom

float bottom() const

y + height: the first y coordinate outside the rect.

origin

Point origin() const

The top-left corner.

size

Size size() const

The extents as a Size.

center

Point center() const

The midpoint of the rect.

empty

bool empty() const

True if either extent is zero or negative.

contains

bool contains(Point p) const

Point-in-rect test. Left/top edges are inclusive, right/bottom exclusive.

intersects

bool intersects(const Rect& o) const

True if the two rects share some area. Rects that only share an edge do not overlap, and an empty rect overlaps nothing.

inset

Rect inset(const Thickness& t) const

Shrink inward by a thickness (padding). Never produces negative extents.

inflate

Rect inflate(float amount) const

Grow outward uniformly by amount on every edge. A negative amount shrinks, unclamped.