Trait Rect

Source
pub trait Rect: Sized {
    type Scalar: Float;

Show 26 methods // Required methods fn from_x_y_w_h( _: Self::Scalar, _: Self::Scalar, _: Self::Scalar, _: Self::Scalar, ) -> Self; fn x(&self) -> Self::Scalar; fn y(&self) -> Self::Scalar; fn w(&self) -> Self::Scalar; fn h(&self) -> Self::Scalar; fn set_x(&mut self, val: Self::Scalar); fn set_y(&mut self, val: Self::Scalar); fn set_w(&mut self, val: Self::Scalar); fn set_h(&mut self, val: Self::Scalar); // Provided methods fn from_u32(rect: [u32; 4]) -> Self { ... } fn from_i32(rect: [i32; 4]) -> Self { ... } fn xy(&self) -> (Self::Scalar, Self::Scalar) { ... } fn wh(&self) -> (Self::Scalar, Self::Scalar) { ... } fn xw(&self) -> (Self::Scalar, Self::Scalar) { ... } fn yh(&self) -> (Self::Scalar, Self::Scalar) { ... } fn x1x2(&self) -> (Self::Scalar, Self::Scalar) { ... } fn y1y2(&self) -> (Self::Scalar, Self::Scalar) { ... } fn p1p2(&self) -> ([Self::Scalar; 2], [Self::Scalar; 2]) { ... } fn xywh(&self) -> (Self::Scalar, Self::Scalar, Self::Scalar, Self::Scalar) { ... } fn center(&self) -> [Self::Scalar; 2] { ... } fn is_empty(&self) -> bool { ... } fn margin(&self, val: Self::Scalar) -> Self { ... } fn split_left( &self, val: Self::Scalar, factor: Self::Scalar, ) -> (Self, Self) { ... } fn split_right( &self, val: Self::Scalar, factor: Self::Scalar, ) -> (Self, Self) { ... } fn split_top(&self, val: Self::Scalar, factor: Self::Scalar) -> (Self, Self) { ... } fn split_bottom( &self, val: Self::Scalar, factor: Self::Scalar, ) -> (Self, Self) { ... }
}
Expand description

Helper methods for computing simple rectangle layout.

Required Associated Types§

Source

type Scalar: Float

The internal scalar type.

Required Methods§

Source

fn from_x_y_w_h( _: Self::Scalar, _: Self::Scalar, _: Self::Scalar, _: Self::Scalar, ) -> Self

Creates new rectangle from x, y, w, h.

Source

fn x(&self) -> Self::Scalar

Gets x.

Source

fn y(&self) -> Self::Scalar

Gets y.

Source

fn w(&self) -> Self::Scalar

Gets w.

Source

fn h(&self) -> Self::Scalar

Gets h.

Source

fn set_x(&mut self, val: Self::Scalar)

Sets x.

Source

fn set_y(&mut self, val: Self::Scalar)

Sets y.

Source

fn set_w(&mut self, val: Self::Scalar)

Sets w.

Source

fn set_h(&mut self, val: Self::Scalar)

Sets h.

Provided Methods§

Source

fn from_u32(rect: [u32; 4]) -> Self

Converts from u32 rectangle.

Source

fn from_i32(rect: [i32; 4]) -> Self

Converts from i32 rectangle.

Source

fn xy(&self) -> (Self::Scalar, Self::Scalar)

Returns x and y.

Source

fn wh(&self) -> (Self::Scalar, Self::Scalar)

Returns w and h.

Source

fn xw(&self) -> (Self::Scalar, Self::Scalar)

Return x and w.

Source

fn yh(&self) -> (Self::Scalar, Self::Scalar)

Returns y and h.

Source

fn x1x2(&self) -> (Self::Scalar, Self::Scalar)

Returns left and right.

Source

fn y1y2(&self) -> (Self::Scalar, Self::Scalar)

Returns top and bottom.

Source

fn p1p2(&self) -> ([Self::Scalar; 2], [Self::Scalar; 2])

Returns upper left and lower right corner.

Source

fn xywh(&self) -> (Self::Scalar, Self::Scalar, Self::Scalar, Self::Scalar)

Returns x, y, w, h.

Source

fn center(&self) -> [Self::Scalar; 2]

Returns the center of the rectangle.

Source

fn is_empty(&self) -> bool

Returns true if the rectangle is empty.

Source

fn margin(&self, val: Self::Scalar) -> Self

Computes a margin rectangle. If the margin is too large, an empty rectangle in the middle is returned.

Source

fn split_left(&self, val: Self::Scalar, factor: Self::Scalar) -> (Self, Self)

Splits from the left side of rectangle up to a factor.

Source

fn split_right(&self, val: Self::Scalar, factor: Self::Scalar) -> (Self, Self)

Splits from the right side of rectangle.

Source

fn split_top(&self, val: Self::Scalar, factor: Self::Scalar) -> (Self, Self)

Splits from the top side of rectangle.

Source

fn split_bottom(&self, val: Self::Scalar, factor: Self::Scalar) -> (Self, Self)

Splits from the bottom side of the rectangle.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Rect for [f32; 4]

Source§

type Scalar = f32

Source§

fn from_x_y_w_h(x: f32, y: f32, w: f32, h: f32) -> [f32; 4]

Source§

fn x(&self) -> f32

Source§

fn y(&self) -> f32

Source§

fn w(&self) -> f32

Source§

fn h(&self) -> f32

Source§

fn set_x(&mut self, val: f32)

Source§

fn set_y(&mut self, val: f32)

Source§

fn set_w(&mut self, val: f32)

Source§

fn set_h(&mut self, val: f32)

Source§

impl Rect for [f64; 4]

Source§

type Scalar = f64

Source§

fn from_x_y_w_h(x: f64, y: f64, w: f64, h: f64) -> [f64; 4]

Source§

fn x(&self) -> f64

Source§

fn y(&self) -> f64

Source§

fn w(&self) -> f64

Source§

fn h(&self) -> f64

Source§

fn set_x(&mut self, val: f64)

Source§

fn set_y(&mut self, val: f64)

Source§

fn set_w(&mut self, val: f64)

Source§

fn set_h(&mut self, val: f64)

Implementors§