Skip to main content

PixelRect

Struct PixelRect 

Source
pub struct PixelRect {
    pub x: i32,
    pub y: i32,
    pub width: i32,
    pub height: i32,
}
Expand description

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

Fields§

§x: i32

The X position.

§y: i32

The Y position.

§width: i32

The width.

§height: i32

The height.

Implementations§

Source§

impl PixelRect

Source

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

Initializes a new instance of the PixelRect structure.

Source

pub const fn from_size(size: PixelSize) -> Self

Initializes a PixelRect at the origin with the given size.

Source

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

Initializes a PixelRect from its position and size.

Source

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

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

Source

pub const fn position(&self) -> PixelPoint

Gets the position of the rectangle.

Source

pub const fn size(&self) -> PixelSize

Gets the size of the rectangle.

Source

pub const fn right(&self) -> i32

Gets the right position of the rectangle.

Source

pub const fn bottom(&self) -> i32

Gets the bottom position of the rectangle.

Source

pub const fn top_left(&self) -> PixelPoint

Gets the top left point of the rectangle.

Source

pub const fn top_right(&self) -> PixelPoint

Gets the top right point of the rectangle.

Source

pub const fn bottom_left(&self) -> PixelPoint

Gets the bottom left point of the rectangle.

Source

pub const fn bottom_right(&self) -> PixelPoint

Gets the bottom right point of the rectangle.

Source

pub const fn center(&self) -> PixelPoint

Gets the center point of the rectangle.

Source

pub const fn contains(&self, p: PixelPoint) -> bool

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

Source

pub const fn contains_exclusive(&self, p: PixelPoint) -> bool

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

Source

pub const fn contains_rect(&self, r: PixelRect) -> bool

Determines whether the rectangle fully contains another rectangle.

Source

pub const fn center_rect(&self, rect: PixelRect) -> PixelRect

Centers another rectangle in this rectangle.

Source

pub const fn equals(&self, other: PixelRect) -> bool

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

Source

pub const fn intersect(&self, rect: PixelRect) -> PixelRect

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

Source

pub const fn intersects(&self, rect: PixelRect) -> bool

Determines whether a rectangle intersects with this rectangle.

Source

pub fn translate(&self, offset: PixelVector) -> PixelRect

Translates the rectangle by an offset.

Source

pub fn union(&self, rect: PixelRect) -> PixelRect

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

Source

pub const fn with_x(&self, x: i32) -> PixelRect

Returns a new PixelRect with the specified X position.

Source

pub const fn with_y(&self, y: i32) -> PixelRect

Returns a new PixelRect with the specified Y position.

Source

pub const fn with_width(&self, width: i32) -> PixelRect

Returns a new PixelRect with the specified width.

Source

pub const fn with_height(&self, height: i32) -> PixelRect

Returns a new PixelRect with the specified height.

Source

pub fn to_rect(&self, scale: f64) -> Rect

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

Source

pub fn to_rect_vector(&self, scale: Vector) -> Rect

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

Source

pub fn to_rect_with_dpi(&self, dpi: f64) -> Rect

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

Source

pub fn to_rect_with_dpi_vector(&self, dpi: Vector) -> Rect

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

Source

pub 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

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

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

Source

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

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

Source

pub 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

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

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

Trait Implementations§

Source§

impl Clone for PixelRect

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for PixelRect

Source§

impl Debug for PixelRect

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PixelRect

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for PixelRect

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for PixelRect

Source§

impl FromStr for PixelRect

Source§

type Err = FormatError

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, FormatError>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for PixelRect

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl MarkupTyped for PixelRect

Source§

const MARKUP: &'static MarkupType

The markup metadata of the type.
Source§

impl PartialEq for PixelRect

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for PixelRect

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyValue for T
where T: PartialEq + 'static,

Source§

fn any_value_as_any(&self) -> &(dyn Any + 'static)

Source§

fn any_value_eq(&self, other: &(dyn AnyValue + 'static)) -> bool

Source§

fn any_value_type_name(&self) -> &'static str

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PropertyValue for T
where T: Clone + PartialEq + 'static,

Source§

impl<T> ResourceKeyObject for T
where T: Eq + Hash + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn dyn_eq(&self, other: &(dyn ResourceKeyObject + 'static)) -> bool

Source§

fn dyn_hash(&self, state: &mut dyn Hasher)

Source§

fn key_type_name(&self) -> &'static str

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.