[−]Struct druid::Size
A 2D size.
Fields
width: f64
The width.
height: f64
The height.
Implementations
impl Size
pub const ZERO: Size
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 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 const fn to_rect(self) -> Rect
Convert this Size
into a Rect
with origin (0.0, 0.0)
.
pub fn to_rounded_rect(self, radius: f64) -> RoundedRect
Convert this Size
into a RoundedRect
with origin (0.0, 0.0)
and
the provided corner radius.
Trait Implementations
impl Add<Size> for Size
type Output = Size
The resulting type after applying the +
operator.
fn add(self, other: Size) -> Size
impl AddAssign<Size> for Size
fn add_assign(&mut self, other: Size)
impl Clone for Size
fn clone(&self) -> Size
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for Size
impl Data for Size
[src]
impl Debug for Size
impl Default for Size
impl Display for Size
impl Div<f64> for Size
type Output = Size
The resulting type after applying the /
operator.
fn div(self, other: f64) -> Size
impl DivAssign<f64> for Size
fn div_assign(&mut self, other: f64)
impl From<(f64, f64)> for Size
impl Into<Size> for Vec2
impl Into<Value> for Size
[src]
impl Mul<f64> for Size
type Output = Size
The resulting type after applying the *
operator.
fn mul(self, other: f64) -> Size
impl MulAssign<f64> for Size
fn mul_assign(&mut self, other: f64)
impl PartialEq<Size> for Size
impl Scalable for Size
[src]
fn to_px(&self, scale: &Scale) -> Size
[src]
Converts a Size
from display points into pixels,
using the x axis scale factor for width
and the y axis scale factor for height
.
fn to_dp(&self, scale: &Scale) -> Size
[src]
Converts a Size
from pixels into points,
using the x axis scale factor for width
and the y axis scale factor for height
.
impl StructuralPartialEq for Size
impl Sub<Size> for Size
type Output = Size
The resulting type after applying the -
operator.
fn sub(self, other: Size) -> Size
impl SubAssign<Size> for Size
fn sub_assign(&mut self, other: Size)
impl<'a> ValueType<'a> for Size
[src]
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> AnyEq for T where
T: PartialEq<T> + Any,
[src]
T: PartialEq<T> + Any,
fn equals(&self, other: &(dyn Any + 'static)) -> bool
[src]
fn as_any(&self) -> &(dyn Any + 'static)
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> RoundFrom<T> for T
fn round_from(x: T) -> T
impl<T, U> RoundInto<U> for T where
U: RoundFrom<T>,
U: RoundFrom<T>,
fn round_into(self) -> U
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,