Struct druid::Size [−]
Expand description
A 2D size.
Fields
width: f64
The width.
height: f64
The height.
Implementations
impl Size
impl Size
Create a new Size
with the provided width
and height
.
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);
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);
Whether this size has zero area.
Note: a size with negative area is not considered empty.
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.))
Convert this size into a Vec2
, with width
mapped to x
and height
mapped to y
.
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);
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);
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);
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);
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
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 fn to_rounded_rect(self, radii: impl Into<RoundedRectRadii>) -> RoundedRect
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.
Trait Implementations
pub fn add_assign(&mut self, other: Size)
pub fn add_assign(&mut self, other: Size)
Performs the +=
operation. Read more
pub fn div_assign(&mut self, other: f64)
pub fn div_assign(&mut self, other: f64)
Performs the /=
operation. Read more
pub fn mul_assign(&mut self, other: f64)
pub fn mul_assign(&mut self, other: f64)
Performs the *=
operation. Read more
Converts a Size
from display points into pixels,
using the x axis scale factor for width
and the y axis scale factor for height
.
pub fn sub_assign(&mut self, other: Size)
pub fn sub_assign(&mut self, other: Size)
Performs the -=
operation. Read more
Attempt to convert the generic Value
into this type.
impl StructuralPartialEq for Size
Auto Trait Implementations
impl RefUnwindSafe for Size
impl UnwindSafe for Size
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
impl<T> RoundFrom<T> for T
impl<T> RoundFrom<T> for T
pub fn round_from(x: T) -> T
pub fn round_from(x: T) -> T
Performs the conversion.
pub fn round_into(self) -> U
pub fn round_into(self) -> U
Performs the conversion.
type Output = T
type Output = T
Should always be Self
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more