# PixelSize

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

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

```rust
struct PixelSize
```

Represents a size in device pixels.

Conversions from floating point saturate at the `i32` range (NaN becomes 0).

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

## Members

- [`width`](#struct_field-width)
- [`height`](#struct_field-height)
- [`EMPTY`](#assoc_const-empty)
- [`new`](#function-new)
- [`aspect_ratio`](#function-aspect_ratio)
- [`parse`](#function-parse)
- [`try_parse`](#function-try_parse)
- [`equals`](#function-equals)
- [`with_width`](#function-with_width)
- [`with_height`](#function-with_height)
- [`to_size`](#function-to_size)
- [`to_size_vector`](#function-to_size_vector)
- [`to_size_with_dpi`](#function-to_size_with_dpi)
- [`to_size_with_dpi_vector`](#function-to_size_with_dpi_vector)
- [`from_size`](#function-from_size)
- [`from_size_ceiling`](#function-from_size_ceiling)
- [`from_size_vector`](#function-from_size_vector)
- [`from_size_with_dpi`](#function-from_size_with_dpi)
- [`from_size_with_dpi_vector`](#function-from_size_with_dpi_vector)

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

### width

```rust
width: i32
```

The width.

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

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

### height

```rust
height: i32
```

The height.

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

<a id="assoc_const-empty"></a>

### EMPTY

```rust
const EMPTY: PixelSize
```

A size representing zero.

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

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

### new

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

Initializes a new instance of the `PixelSize` structure.

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

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

### aspect_ratio

```rust
fn aspect_ratio(self: &Self) -> f64
```

Gets the aspect ratio of the size.

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

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

### parse

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

Parses a `PixelSize` string (`"width, height"`).

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

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

### try_parse

```rust
fn try_parse(source: &str) -> Option<Self>
```

Tries to parse a `PixelSize` string. Every kind of malformed input yields
`None` (the reference implementation raises a format error for some of them,
e.g. trailing tokens; there is no such distinction here).

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

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

### equals

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

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

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

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

### with_width

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

Returns a new `PixelSize` with the same height and the specified width.

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

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

### with_height

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

Returns a new `PixelSize` with the same width and the specified height.

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

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

### to_size

```rust
fn to_size(self: &Self, scale: f64) -> Size
```

Converts the `PixelSize` to a device-independent `Size` using the
specified scaling factor.

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

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

### to_size_vector

```rust
fn to_size_vector(self: &Self, scale: Vector) -> Size
```

Converts the `PixelSize` to a device-independent `Size` using the
specified per-axis scaling factor.

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

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

### to_size_with_dpi

```rust
fn to_size_with_dpi(self: &Self, dpi: f64) -> Size
```

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

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

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

### to_size_with_dpi_vector

```rust
fn to_size_with_dpi_vector(self: &Self, dpi: Vector) -> Size
```

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

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

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

### from_size

```rust
fn from_size(size: Size, scale: f64) -> PixelSize
```

Converts a `Size` to device pixels using the specified scaling factor,
rounding up.

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

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

### from_size_ceiling

```rust
fn from_size_ceiling(size: Size, scale: f64) -> PixelSize
```

A tolerant ceiling variant of `from_size`: a value within
`1e-6` of an integer snaps to that integer, otherwise it is rounded up.
This prevents floating-point artifacts (e.g. `24.0000001`) from producing an
extra pixel while still guaranteeing the pixel size covers the logical size.

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

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

### from_size_vector

```rust
fn from_size_vector(size: Size, scale: Vector) -> PixelSize
```

Converts a `Size` to device pixels using the specified per-axis scaling
factor, rounding up.

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

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

### from_size_with_dpi

```rust
fn from_size_with_dpi(size: Size, dpi: f64) -> PixelSize
```

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

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

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

### from_size_with_dpi_vector

```rust
fn from_size_with_dpi_vector(size: Size, dpi: Vector) -> PixelSize
```

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

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

## 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/).
