# PixelRect

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-base/struct-pixelrect/

**struct** · [`ferroui-base`](/docs/0.5.0/api/ferroui-base/) · v0.5.0

```rust
struct PixelRect
```

Represents a rectangle in device pixels. Integer arithmetic wraps on overflow.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L11)

## Members

- [`x`](#struct_field-x)
- [`y`](#struct_field-y)
- [`width`](#struct_field-width)
- [`height`](#struct_field-height)
- [`new`](#function-new)
- [`from_size`](#function-from_size)
- [`from_position_size`](#function-from_position_size)
- [`from_points`](#function-from_points)
- [`position`](#function-position)
- [`size`](#function-size)
- [`right`](#function-right)
- [`bottom`](#function-bottom)
- [`top_left`](#function-top_left)
- [`top_right`](#function-top_right)
- [`bottom_left`](#function-bottom_left)
- [`bottom_right`](#function-bottom_right)
- [`center`](#function-center)
- [`contains`](#function-contains)
- [`contains_exclusive`](#function-contains_exclusive)
- [`contains_rect`](#function-contains_rect)
- [`center_rect`](#function-center_rect)
- [`equals`](#function-equals)
- [`intersect`](#function-intersect)
- [`intersects`](#function-intersects)
- [`translate`](#function-translate)
- [`union`](#function-union)
- [`with_x`](#function-with_x)
- [`with_y`](#function-with_y)
- [`with_width`](#function-with_width)
- [`with_height`](#function-with_height)
- [`to_rect`](#function-to_rect)
- [`to_rect_vector`](#function-to_rect_vector)
- [`to_rect_with_dpi`](#function-to_rect_with_dpi)
- [`to_rect_with_dpi_vector`](#function-to_rect_with_dpi_vector)
- [`from_rect`](#function-from_rect)
- [`from_rect_vector`](#function-from_rect_vector)
- [`from_rect_with_dpi`](#function-from_rect_with_dpi)
- [`from_rect_with_dpi_vector`](#function-from_rect_with_dpi_vector)
- [`parse`](#function-parse)

<a id="struct_field-x"></a>

### x

```rust
x: i32
```

The X position.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L13)

<a id="struct_field-y"></a>

### y

```rust
y: i32
```

The Y position.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L15)

<a id="struct_field-width"></a>

### width

```rust
width: i32
```

The width.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L17)

<a id="struct_field-height"></a>

### height

```rust
height: i32
```

The height.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L19)

<a id="function-new"></a>

### new

```rust
const fn new(x: i32, y: i32, width: i32, height: i32) -> Self
```

Initializes a new instance of the `PixelRect` structure.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L25)

<a id="function-from_size"></a>

### from_size

```rust
const fn from_size(size: PixelSize) -> Self
```

Initializes a `PixelRect` at the origin with the given size.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L36)

<a id="function-from_position_size"></a>

### from_position_size

```rust
const fn from_position_size(position: PixelPoint, size: PixelSize) -> Self
```

Initializes a `PixelRect` from its position and size.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L42)

<a id="function-from_points"></a>

### from_points

```rust
const fn from_points(top_left: PixelPoint, bottom_right: PixelPoint) -> Self
```

Initializes a `PixelRect` from its top left and bottom right corners.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L48)

<a id="function-position"></a>

### position

```rust
const fn position(self: &Self) -> PixelPoint
```

Gets the position of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L59)

<a id="function-size"></a>

### size

```rust
const fn size(self: &Self) -> PixelSize
```

Gets the size of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L65)

<a id="function-right"></a>

### right

```rust
const fn right(self: &Self) -> i32
```

Gets the right position of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L71)

<a id="function-bottom"></a>

### bottom

```rust
const fn bottom(self: &Self) -> i32
```

Gets the bottom position of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L77)

<a id="function-top_left"></a>

### top_left

```rust
const fn top_left(self: &Self) -> PixelPoint
```

Gets the top left point of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L83)

<a id="function-top_right"></a>

### top_right

```rust
const fn top_right(self: &Self) -> PixelPoint
```

Gets the top right point of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L89)

<a id="function-bottom_left"></a>

### bottom_left

```rust
const fn bottom_left(self: &Self) -> PixelPoint
```

Gets the bottom left point of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L95)

<a id="function-bottom_right"></a>

### bottom_right

```rust
const fn bottom_right(self: &Self) -> PixelPoint
```

Gets the bottom right point of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L101)

<a id="function-center"></a>

### center

```rust
const fn center(self: &Self) -> PixelPoint
```

Gets the center point of the rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L107)

<a id="function-contains"></a>

### contains

```rust
const fn contains(self: &Self, p: PixelPoint) -> bool
```

Determines whether a point is in the bounds of the rectangle (edges inclusive).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L116)

<a id="function-contains_exclusive"></a>

### contains_exclusive

```rust
const fn contains_exclusive(self: &Self, p: PixelPoint) -> bool
```

Determines whether a point is in the bounds of the rectangle, exclusive of
the rectangle's bottom/right edge.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L123)

<a id="function-contains_rect"></a>

### contains_rect

```rust
const fn contains_rect(self: &Self, r: PixelRect) -> bool
```

Determines whether the rectangle fully contains another rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L132)

<a id="function-center_rect"></a>

### center_rect

```rust
const fn center_rect(self: &Self, rect: PixelRect) -> PixelRect
```

Centers another rectangle in this rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L138)

<a id="function-equals"></a>

### equals

```rust
const fn equals(self: &Self, other: PixelRect) -> bool
```

Returns a boolean indicating whether the rect is equal to the other given rect.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L150)

<a id="function-intersect"></a>

### intersect

```rust
const fn intersect(self: &Self, rect: PixelRect) -> PixelRect
```

Gets the intersection of two rectangles, or an empty (default) rectangle if
they do not overlap.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L159)

<a id="function-intersects"></a>

### intersects

```rust
const fn intersects(self: &Self, rect: PixelRect) -> bool
```

Determines whether a rectangle intersects with this rectangle.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L187)

<a id="function-translate"></a>

### translate

```rust
fn translate(self: &Self, offset: PixelVector) -> PixelRect
```

Translates the rectangle by an offset.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L196)

<a id="function-union"></a>

### union

```rust
fn union(self: &Self, rect: PixelRect) -> PixelRect
```

Gets the union of two rectangles. A rectangle whose width and height are
both zero is ignored.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L202)

<a id="function-with_x"></a>

### with_x

```rust
const fn with_x(self: &Self, x: i32) -> PixelRect
```

Returns a new `PixelRect` with the specified X position.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L219)

<a id="function-with_y"></a>

### with_y

```rust
const fn with_y(self: &Self, y: i32) -> PixelRect
```

Returns a new `PixelRect` with the specified Y position.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L225)

<a id="function-with_width"></a>

### with_width

```rust
const fn with_width(self: &Self, width: i32) -> PixelRect
```

Returns a new `PixelRect` with the specified width.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L231)

<a id="function-with_height"></a>

### with_height

```rust
const fn with_height(self: &Self, height: i32) -> PixelRect
```

Returns a new `PixelRect` with the specified height.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L237)

<a id="function-to_rect"></a>

### to_rect

```rust
fn to_rect(self: &Self, scale: f64) -> Rect
```

Converts the `PixelRect` to a device-independent `Rect` using the
specified scaling factor.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L244)

<a id="function-to_rect_vector"></a>

### to_rect_vector

```rust
fn to_rect_vector(self: &Self, scale: Vector) -> Rect
```

Converts the `PixelRect` to a device-independent `Rect` using the
specified per-axis scaling factor.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L251)

<a id="function-to_rect_with_dpi"></a>

### to_rect_with_dpi

```rust
fn to_rect_with_dpi(self: &Self, dpi: f64) -> Rect
```

Converts the `PixelRect` to a device-independent `Rect` using the
specified dots per inch (DPI).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L261)

<a id="function-to_rect_with_dpi_vector"></a>

### to_rect_with_dpi_vector

```rust
fn to_rect_with_dpi_vector(self: &Self, dpi: Vector) -> Rect
```

Converts the `PixelRect` to a device-independent `Rect` using the
specified per-axis dots per inch (DPI).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L271)

<a id="function-from_rect"></a>

### from_rect

```rust
fn from_rect(rect: Rect, scale: f64) -> PixelRect
```

Converts a `Rect` to device pixels using the specified scaling factor.
The top left is truncated and the bottom right is rounded up.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L281)

<a id="function-from_rect_vector"></a>

### from_rect_vector

```rust
fn from_rect_vector(rect: Rect, scale: Vector) -> PixelRect
```

Converts a `Rect` to device pixels using the specified per-axis scaling factor.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L290)

<a id="function-from_rect_with_dpi"></a>

### from_rect_with_dpi

```rust
fn from_rect_with_dpi(rect: Rect, dpi: f64) -> PixelRect
```

Converts a `Rect` to device pixels using the specified dots per inch (DPI).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L299)

<a id="function-from_rect_with_dpi_vector"></a>

### from_rect_with_dpi_vector

```rust
fn from_rect_with_dpi_vector(rect: Rect, dpi: Vector) -> PixelRect
```

Converts a `Rect` to device pixels using the specified per-axis dots per inch (DPI).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L308)

<a id="function-parse"></a>

### parse

```rust
fn parse(s: &str) -> Result<Self, FormatError>
```

Parses a `PixelRect` string (`"x, y, width, height"`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Base/pixel_rect.rs#L316)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`ResourceKeyObject`](/docs/0.5.0/api/ferroui-base/controls/trait-resourcekeyobject/)
- [`PropertyValue`](/docs/0.5.0/api/ferroui-base/trait-propertyvalue/)
- [`AnyValue`](/docs/0.5.0/api/ferroui-base/trait-anyvalue/)
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `Borrow<T>`
- `BorrowMut<T>`
- `CloneToUninit`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- `ToOwned`
- `ToString`
- `ErasedDestructor`
- `IntoEither`
- [`MarkupTyped`](/docs/0.5.0/api/ferroui-base/metadata/trait-markuptyped/)
- [`ValueTypeRegistration`](/docs/0.5.0/api/ferroui-base/data/core/trait-valuetyperegistration/)
- `Clone`
- `Copy`
- `Debug`
- `StructuralPartialEq`
- `PartialEq`
- `Eq`
- `Hash`
- `Default`
- `FromStr`
- `Display`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
