Struct druid::Insets

pub struct Insets {
    pub x0: f64,
    pub y0: f64,
    pub x1: f64,
    pub y1: f64,
}
Expand description

Insets from the edges of a rectangle.

The inset value for each edge can be thought of as a delta computed from the center of the rect to that edge. For instance, with an inset of 2.0 on the x-axis, a rectangle with the origin (0.0, 0.0) with that inset added will have the new origin at (-2.0, 0.0).

Put alternatively, a positive inset represents increased distance from center, and a negative inset represents decreased distance from center.

Examples

Positive insets added to a Rect produce a larger Rect:

let rect = Rect::from_origin_size((0., 0.,), (10., 10.,));
let insets = Insets::uniform_xy(3., 0.,);

let inset_rect = rect + insets;
assert_eq!(inset_rect.width(), 16.0, "10.0 + 3.0 × 2");
assert_eq!(inset_rect.x0, -3.0);

Negative insets added to a Rect produce a smaller Rect:

let rect = Rect::from_origin_size((0., 0.,), (10., 10.,));
let insets = Insets::uniform_xy(-3., 0.,);

let inset_rect = rect + insets;
assert_eq!(inset_rect.width(), 4.0, "10.0 - 3.0 × 2");
assert_eq!(inset_rect.x0, 3.0);

Insets operate on the absolute rectangle Rect::abs, and so ignore existing negative widths and heights.

let rect = Rect::new(7., 11., 0., 0.,);
let insets = Insets::uniform_xy(0., 1.,);

assert_eq!(rect.width(), -7.0);

let inset_rect = rect + insets;
assert_eq!(inset_rect.width(), 7.0);
assert_eq!(inset_rect.x0, 0.0);
assert_eq!(inset_rect.height(), 13.0);

The width and height of an inset operation can still be negative if the Insets’ dimensions are greater than the dimensions of the original Rect.

let rect = Rect::new(0., 0., 3., 5.);
let insets = Insets::uniform_xy(0., 7.,);

let inset_rect = rect - insets;
assert_eq!(inset_rect.height(), -9., "5 - 7 × 2")

Rect - Rect = Insets:

let rect = Rect::new(0., 0., 5., 11.);
let insets = Insets::uniform_xy(1., 7.,);

let inset_rect = rect + insets;
let insets2 = inset_rect - rect;

assert_eq!(insets2.x0, insets.x0);
assert_eq!(insets2.y1, insets.y1);
assert_eq!(insets2.x_value(), insets.x_value());
assert_eq!(insets2.y_value(), insets.y_value());

Fields§

§x0: f64

The minimum x coordinate (left edge).

§y0: f64

The minimum y coordinate (top edge in y-down spaces).

§x1: f64

The maximum x coordinate (right edge).

§y1: f64

The maximum y coordinate (bottom edge in y-down spaces).

Implementations§

§

impl Insets

pub const ZERO: Insets = Insets::uniform(0.)

Zeroed insets.

pub const fn uniform(d: f64) -> Insets

New uniform insets.

pub const fn uniform_xy(x: f64, y: f64) -> Insets

New insets with uniform values along each axis.

pub const fn new(x0: f64, y0: f64, x1: f64, y1: f64) -> Insets

New insets. The ordering of the arguments is “left, top, right, bottom”, assuming a y-down coordinate space.

pub fn x_value(self) -> f64

The total delta on the x-axis represented by these insets.

Examples
use kurbo::Insets;

let insets = Insets::uniform_xy(3., 8.);
assert_eq!(insets.x_value(), 6.);

let insets = Insets::new(5., 0., -12., 0.,);
assert_eq!(insets.x_value(), -7.);

pub fn y_value(self) -> f64

The total delta on the y-axis represented by these insets.

Examples
use kurbo::Insets;

let insets = Insets::uniform_xy(3., 7.);
assert_eq!(insets.y_value(), 14.);

let insets = Insets::new(5., 10., -12., 4.,);
assert_eq!(insets.y_value(), 14.);

pub fn size(self) -> Size

Returns the total delta represented by these insets as a Size.

This is equivalent to creating a Size from the values returned by x_value and y_value.

This function may return a size with negative values.

Examples
use kurbo::{Insets, Size};

let insets = Insets::new(11.1, -43.3, 3.333, -0.0);
assert_eq!(insets.size(), Size::new(insets.x_value(), insets.y_value()));

pub fn are_nonnegative(self) -> bool

Return true iff all values are nonnegative.

pub fn nonnegative(self) -> Insets

Return new Insets with all negative values replaced with 0.0.

This is provided as a convenience for applications where negative insets are not meaningful.

Examples
use kurbo::Insets;

let insets = Insets::new(-10., 3., -0.2, 4.);
let nonnegative = insets.nonnegative();
assert_eq!(nonnegative.x_value(), 0.0);
assert_eq!(nonnegative.y_value(), 7.0);

pub fn is_finite(&self) -> bool

Are these insets finite?

pub fn is_nan(&self) -> bool

Are these insets NaN?

Trait Implementations§

§

impl Add<Insets> for Rect

§

type Output = Rect

The resulting type after applying the + operator.
§

fn add(self, other: Insets) -> Rect

Performs the + operation. Read more
§

impl Add<Rect> for Insets

§

type Output = Rect

The resulting type after applying the + operator.
§

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

Performs the + operation. Read more
§

impl Clone for Insets

§

fn clone(&self) -> Insets

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 Insets

source§

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

Determine whether two values are the same. Read more
§

impl Debug for Insets

§

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

Formats the value using the given formatter. Read more
§

impl Default for Insets

§

fn default() -> Insets

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

impl From<(f64, f64)> for Insets

§

fn from(src: (f64, f64)) -> Insets

Converts to this type from the input type.
§

impl From<(f64, f64, f64, f64)> for Insets

§

fn from(src: (f64, f64, f64, f64)) -> Insets

Converts to this type from the input type.
source§

impl From<Insets> for Value

source§

fn from(val: Insets) -> Value

Converts to this type from the input type.
§

impl From<f64> for Insets

§

fn from(src: f64) -> Insets

Converts to this type from the input type.
§

impl Neg for Insets

§

type Output = Insets

The resulting type after applying the - operator.
§

fn neg(self) -> Insets

Performs the unary - operation. Read more
§

impl PartialEq<Insets> for Insets

§

fn eq(&self, other: &Insets) -> 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 Insets

source§

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

Converts Insets from display points into pixels, using the x axis scale factor for x0 and x1 and the y axis scale factor for y0 and y1.

source§

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

Converts Insets from pixels into display points, using the x axis scale factor for x0 and x1 and the y axis scale factor for y0 and y1.

§

impl Sub<Insets> for Rect

§

type Output = Rect

The resulting type after applying the - operator.
§

fn sub(self, other: Insets) -> Rect

Performs the - operation. Read more
§

impl Sub<Rect> for Insets

§

type Output = Rect

The resulting type after applying the - operator.
§

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

Performs the - operation. Read more
source§

impl ValueType for Insets

source§

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

Attempt to convert the generic Value into this type.
§

impl Copy for Insets

§

impl StructuralPartialEq for Insets

Auto Trait Implementations§

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, 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