Struct druid::Size

pub struct Size {
    pub width: f64,
    pub height: f64,
}
Expand description

A 2D size.

Fields§

§width: f64

The width.

§height: f64

The height.

Implementations§

§

impl Size

pub const ZERO: Size = Size::new(0., 0.)

A size with zero width or height.

pub const fn new(width: f64, height: f64) -> Size

Create a new Size with the provided width and height.

pub fn max_side(self) -> f64

Returns the max of width and height.

Examples
use kurbo::Size;
let size = Size::new(-10.5, 42.0);
assert_eq!(size.max_side(), 42.0);

pub fn min_side(self) -> f64

Returns the min of width and height.

Examples
use kurbo::Size;
let size = Size::new(-10.5, 42.0);
assert_eq!(size.min_side(), -10.5);

pub fn area(self) -> f64

The area covered by this size.

pub fn is_empty(self) -> bool

Whether this size has zero area.

Note: a size with negative area is not considered empty.

pub fn clamp(self, min: Size, max: Size) -> Size

Returns a new size bounded by min and max.

Examples
use kurbo::Size;

let this = Size::new(0., 100.);
let min = Size::new(10., 10.,);
let max = Size::new(50., 50.);
assert_eq!(this.clamp(min, max), Size::new(10., 50.))

pub const fn to_vec2(self) -> Vec2

Convert this size into a Vec2, with width mapped to x and height mapped to y.

pub fn round(self) -> Size

Returns a new Size, with width and height rounded to the nearest integer.

Examples
use kurbo::Size;
let size_pos = Size::new(3.3, 3.6).round();
assert_eq!(size_pos.width, 3.0);
assert_eq!(size_pos.height, 4.0);
let size_neg = Size::new(-3.3, -3.6).round();
assert_eq!(size_neg.width, -3.0);
assert_eq!(size_neg.height, -4.0);

pub fn ceil(self) -> Size

Returns a new Size, with width and height rounded up to the nearest integer, unless they are already an integer.

Examples
use kurbo::Size;
let size_pos = Size::new(3.3, 3.6).ceil();
assert_eq!(size_pos.width, 4.0);
assert_eq!(size_pos.height, 4.0);
let size_neg = Size::new(-3.3, -3.6).ceil();
assert_eq!(size_neg.width, -3.0);
assert_eq!(size_neg.height, -3.0);

pub fn floor(self) -> Size

Returns a new Size, with width and height rounded down to the nearest integer, unless they are already an integer.

Examples
use kurbo::Size;
let size_pos = Size::new(3.3, 3.6).floor();
assert_eq!(size_pos.width, 3.0);
assert_eq!(size_pos.height, 3.0);
let size_neg = Size::new(-3.3, -3.6).floor();
assert_eq!(size_neg.width, -4.0);
assert_eq!(size_neg.height, -4.0);

pub fn expand(self) -> Size

Returns a new Size, with width and height rounded away from zero to the nearest integer, unless they are already an integer.

Examples
use kurbo::Size;
let size_pos = Size::new(3.3, 3.6).expand();
assert_eq!(size_pos.width, 4.0);
assert_eq!(size_pos.height, 4.0);
let size_neg = Size::new(-3.3, -3.6).expand();
assert_eq!(size_neg.width, -4.0);
assert_eq!(size_neg.height, -4.0);

pub fn trunc(self) -> Size

Returns a new Size, with width and height rounded down towards zero the nearest integer, unless they are already an integer.

Examples
use kurbo::Size;
let size_pos = Size::new(3.3, 3.6).trunc();
assert_eq!(size_pos.width, 3.0);
assert_eq!(size_pos.height, 3.0);
let size_neg = Size::new(-3.3, -3.6).trunc();
assert_eq!(size_neg.width, -3.0);
assert_eq!(size_neg.height, -3.0);

pub fn aspect_ratio(self) -> f64

Returns the aspect ratio of a rectangle with the given size.

If the width is 0, the output will be sign(self.height) * infinity. If The width and height are 0, then the output will be NaN.

pub const fn to_rect(self) -> Rect

Convert this Size into a Rect with origin (0.0, 0.0).

pub fn to_rounded_rect(self, radii: impl Into<RoundedRectRadii>) -> RoundedRect

Convert this Size into a RoundedRect with origin (0.0, 0.0) and the provided corner radius.

pub fn is_finite(self) -> bool

Is this size finite?

pub fn is_nan(self) -> bool

Is this size NaN?

Trait Implementations§

§

impl Add<Size> for Size

§

type Output = Size

The resulting type after applying the + operator.
§

fn add(self, other: Size) -> Size

Performs the + operation. Read more
§

impl AddAssign<Size> for Size

§

fn add_assign(&mut self, other: Size)

Performs the += operation. Read more
§

impl Clone for Size

§

fn clone(&self) -> Size

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Data for Size

source§

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

Determine whether two values are the same. Read more
§

impl Debug for Size

§

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

Formats the value using the given formatter. Read more
§

impl Default for Size

§

fn default() -> Size

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

impl Display for Size

§

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

Formats the value using the given formatter. Read more
§

impl Div<f64> for Size

§

type Output = Size

The resulting type after applying the / operator.
§

fn div(self, other: f64) -> Size

Performs the / operation. Read more
§

impl DivAssign<f64> for Size

§

fn div_assign(&mut self, other: f64)

Performs the /= operation. Read more
§

impl From<(f64, f64)> for Size

§

fn from(v: (f64, f64)) -> Size

Converts to this type from the input type.
source§

impl From<Size> for Value

source§

fn from(val: Size) -> Value

Converts to this type from the input type.
§

impl Mul<f64> for Size

§

type Output = Size

The resulting type after applying the * operator.
§

fn mul(self, other: f64) -> Size

Performs the * operation. Read more
§

impl MulAssign<f64> for Size

§

fn mul_assign(&mut self, other: f64)

Performs the *= operation. Read more
§

impl PartialEq<Size> for Size

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Scalable for Size

source§

fn to_px(&self, scale: Scale) -> Size

Converts a Size from display points into pixels, using the x axis scale factor for width and the y axis scale factor for height.

source§

fn to_dp(&self, scale: Scale) -> Size

Converts a Size from pixels into points, using the x axis scale factor for width and the y axis scale factor for height.

§

impl Sub<Size> for Size

§

type Output = Size

The resulting type after applying the - operator.
§

fn sub(self, other: Size) -> Size

Performs the - operation. Read more
§

impl SubAssign<Size> for Size

§

fn sub_assign(&mut self, other: Size)

Performs the -= operation. Read more
source§

impl ValueType for Size

source§

fn try_from_value(value: &Value) -> Result<Self, ValueTypeError>

Attempt to convert the generic Value into this type.
§

impl Copy for Size

§

impl StructuralPartialEq for Size

Auto Trait Implementations§

§

impl RefUnwindSafe for Size

§

impl Send for Size

§

impl Sync for Size

§

impl Unpin for Size

§

impl UnwindSafe for Size

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AnyEq for Twhere T: Any + PartialEq<T>,

source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

source§

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

source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

const: unstable · 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> IsDefault for Twhere T: Default + PartialEq<T> + Copy,

source§

fn is_default(&self) -> bool

Checks that type has a default value.
§

impl<T> RoundFrom<T> for T

§

fn round_from(x: T) -> T

Performs the conversion.
§

impl<T, U> RoundInto<U> for Twhere U: RoundFrom<T>,

§

fn round_into(self) -> U

Performs the conversion.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

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

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more