Skip to main content

Size

Struct Size 

Source
#[repr(C)]
pub struct Size<T: Clone + Debug + Default + PartialEq> { pub width: T, pub height: T, }
Expand description

A width and height, such as the size of a window or an element.

Size<Pixels> holds layout sizes in logical pixels. Size<Length> holds style values, which can also be auto or a fraction of the parent. Size<DevicePixels> holds whole physical pixels, such as the size of an image. Construct a size with size.

§Examples

use gpui::{px, size};

let window = size(px(800.), px(600.));
assert_eq!(window.width, px(800.));
assert_eq!(window.height, px(600.));

Fields§

§width: T

The width, along the horizontal axis.

§height: T

The height, along the vertical axis.

Implementations§

Source§

impl<T: Clone + Debug + Default + PartialEq> Size<T>

Source

pub fn new(width: T, height: T) -> Self

Creates a size from its width and height. Same as size.

§Examples
use gpui::Size;

let s = Size::new(10, 20);
assert_eq!(s.width, 10);
assert_eq!(s.height, 20);
Source§

impl<T> Size<T>
where T: Clone + Debug + Default + PartialEq,

Source

pub fn map<U>(&self, f: impl Fn(T) -> U) -> Size<U>
where U: Clone + Debug + Default + PartialEq,

Returns a new size with f applied to the width and the height.

§Examples
let my_size = Size { width: 10, height: 20 };
let my_new_size = my_size.map(|dimension| dimension as f32 * 1.5);
assert_eq!(my_new_size, Size { width: 15.0, height: 30.0 });
Source§

impl<T> Size<T>
where T: Clone + Debug + Default + PartialEq + Half,

Source

pub fn center(&self) -> Point<T>

Returns the point at the center of a box of this size, measured from (0, 0).

§Examples
assert_eq!(size(px(100.), px(40.)).center(), point(px(50.), px(20.)));
Source

pub fn at_anchor(&self, anchor: Anchor) -> Point<T>

Returns the point at anchor on the edge or corner of a box of this size.

The box’s top left corner is (0, 0), so Anchor::BottomRight returns the size itself.

§Examples
let s = size(px(100.), px(40.));
assert_eq!(s.at_anchor(Anchor::BottomCenter), point(px(50.), px(40.)));
assert_eq!(s.at_anchor(Anchor::BottomRight), point(px(100.), px(40.)));
Source§

impl Size<Pixels>

Source

pub fn scale(&self, factor: f32) -> Size<ScaledPixels>

Multiplies the width and height by factor, producing ScaledPixels.

§Examples
let size = Size { width: Pixels::from(100.0), height: Pixels::from(50.0) };
let scaled_size = size.scale(2.0);
assert_eq!(scaled_size, Size { width: ScaledPixels::from(200.0), height: ScaledPixels::from(100.0) });
Source§

impl<T> Size<T>

Source

pub fn max(&self, other: &Self) -> Self

Returns a size with the larger width and the larger height of self and other.

§Examples
let size1 = Size { width: 30, height: 40 };
let size2 = Size { width: 50, height: 20 };
assert_eq!(size1.max(&size2), Size { width: 50, height: 40 });
Source

pub fn min(&self, other: &Self) -> Self

Returns a size with the smaller width and the smaller height of self and other.

§Examples
let size1 = Size { width: 30, height: 40 };
let size2 = Size { width: 50, height: 20 };
assert_eq!(size1.min(&size2), Size { width: 30, height: 20 });
Source§

impl Size<Length>

Source

pub fn full() -> Self

Returns a size whose width and height are both relative(1.), filling the parent.

§Examples
let full = Size::<Length>::full();
assert_eq!(full.width, Length::Definite(DefiniteLength::from(relative(1.))));
assert_eq!(full.height, Length::Definite(DefiniteLength::from(relative(1.))));
Source§

impl Size<Length>

Source

pub fn auto() -> Self

Returns a size whose width and height are both Length::Auto.

With auto in both dimensions, layout sizes the element from its content.

§Examples
let auto = Size::<Length>::auto();
assert_eq!(auto.width, Length::Auto);
assert_eq!(auto.height, Length::Auto);
Source§

impl Size<DevicePixels>

Source

pub fn to_pixels(self, scale_factor: f32) -> Size<Pixels>

Converts this size from device pixels to logical pixels by dividing by scale_factor.

§Examples
let device = size(DevicePixels(200), DevicePixels(100));
assert_eq!(device.to_pixels(2.), size(px(100.), px(50.)));
Source§

impl Size<Pixels>

Source

pub fn to_device_pixels(self, scale_factor: f32) -> Size<DevicePixels>

Converts this size from logical pixels to device pixels.

Multiplies each side by scale_factor and rounds it to the nearest whole device pixel.

§Examples
let logical = size(px(100.), px(50.3));
assert_eq!(logical.to_device_pixels(2.), size(DevicePixels(200), DevicePixels(101)));

Trait Implementations§

Source§

impl<T> Add for Size<T>
where T: Add<Output = T> + Clone + Debug + Default + PartialEq,

Source§

type Output = Size<T>

The resulting type after applying the + operator.
Source§

fn add(self, __rhs: Self) -> Self::Output

Performs the + operation. Read more
Source§

impl<T> Along for Size<T>
where T: Clone + Debug + Default + PartialEq,

Source§

type Unit = T

The type of the value along each axis.
Source§

fn along(&self, axis: Axis) -> T

Returns the value along axis.
Source§

fn apply_along(&self, axis: Axis, f: impl FnOnce(T) -> T) -> Self

Returns a copy with f applied to the value along axis. The other axis is unchanged.
Source§

impl<T: Clone + Clone + Debug + Default + PartialEq> Clone for Size<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Copy + Clone + Debug + Default + PartialEq> Copy for Size<T>

Source§

impl<T> Debug for Size<T>
where T: Clone + Debug + Default + PartialEq,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Default + Clone + Debug + Default + PartialEq> Default for Size<T>

Source§

fn default() -> Self

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

impl<'de, T> Deserialize<'de> for Size<T>
where T: Deserialize<'de> + Clone + Debug + Default + PartialEq,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Clone + Debug + Default + PartialEq + Display> Display for Size<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T, __derive_more_Rhs> Div<__derive_more_Rhs> for Size<T>
where T: Div<__derive_more_Rhs, Output = T> + Clone + Debug + Default + PartialEq, __derive_more_Rhs: Copy,

Source§

type Output = Size<T>

The resulting type after applying the / operator.
Source§

fn div(self, __rhs: __derive_more_Rhs) -> Self::Output

Performs the / operation. Read more
Source§

impl<T> Eq for Size<T>
where T: Eq + Clone + Debug + Default + PartialEq,

Source§

impl<T: Clone + Debug + Default + PartialEq> From<Point<T>> for Size<T>

Source§

fn from(point: Point<T>) -> Self

Converts to this type from the input type.
Source§

impl From<Size<Pixels>> for Size<DefiniteLength>

Source§

fn from(size: Size<Pixels>) -> Self

Converts to this type from the input type.
Source§

impl From<Size<Pixels>> for Size<AbsoluteLength>

Source§

fn from(size: Size<Pixels>) -> Self

Converts to this type from the input type.
Source§

impl From<Size<Pixels>> for Size<AvailableSpace>

Source§

fn from(size: Size<Pixels>) -> Self

Converts to this type from the input type.
Source§

impl<T: Clone + Debug + Default + PartialEq> From<Size<T>> for Point<T>

Source§

fn from(size: Size<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, U> From<Size<T>> for Size<U>
where T: Into<U>, U: Clone + Debug + Default + PartialEq,

Source§

fn from(taffy_size: TaffySize<T>) -> Self

Converts to this type from the input type.
Source§

impl<T, U> From<Size<T>> for Size<U>
where T: Into<U> + Clone + Debug + Default + PartialEq,

Source§

fn from(size: Size<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Clone + Debug + Default + PartialEq> From<SizeRefinement<T>> for Size<T>
where Option<T>: Clone,

Source§

fn from(value: SizeRefinement<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: Hash + Clone + Debug + Default + PartialEq> Hash for Size<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> IsZero for Size<T>
where T: IsZero + Clone + Debug + Default + PartialEq,

Source§

fn is_zero(&self) -> bool

Returns true if this value is zero.
Source§

impl<T: Lerp + Clone + Debug + Default + PartialEq> Lerp for Size<T>

Source§

fn lerp(&self, to: &Self, delta: f32) -> Self

Returns the value delta of the way from self to to.
Source§

impl<T, Rhs> Mul<Rhs> for Size<T>
where T: Mul<Rhs, Output = Rhs> + Clone + Debug + Default + PartialEq, Rhs: Clone + Debug + Default + PartialEq,

Source§

type Output = Size<Rhs>

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Rhs) -> Self::Output

Performs the * operation. Read more
Source§

impl<T, S> MulAssign<S> for Size<T>
where T: Mul<S, Output = T> + Clone + Debug + Default + PartialEq, S: Clone,

Source§

fn mul_assign(&mut self, rhs: S)

Performs the *= operation. Read more
Source§

impl<T: Clone + Debug + Default + PartialEq + Neg<Output = T>> Neg for Size<T>

Source§

type Output = Size<T>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Size<T>

Performs the unary - operation. Read more
Source§

impl<T: PartialEq + Clone + Debug + Default + PartialEq> PartialEq for Size<T>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: Clone + Debug + Default + PartialEq> Refineable for Size<T>
where Option<T>: Clone,

Source§

type Refinement = SizeRefinement<T>

Source§

fn refine(&mut self, refinement: &Self::Refinement)

Applies the given refinement to this instance, modifying it in place. Read more
Source§

fn refined(self, refinement: Self::Refinement) -> Self

Returns a new instance with the refinement applied, equivalent to cloning self and calling refine on it.
Source§

fn is_superset_of(&self, refinement: &Self::Refinement) -> bool

Returns true if this instance would contain all values from the refinement. Read more
Source§

fn subtract(&self, refinement: &Self::Refinement) -> Self::Refinement

Returns a refinement that represents the difference between this instance and the given refinement. Read more
Source§

fn from_cascade(cascade: &Cascade<Self>) -> Self
where Self: Sized + Default,

Creates an instance from a cascade by merging all refinements atop the default value.
Source§

impl<T> Serialize for Size<T>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<T: PartialEq + Clone + Debug + Default + PartialEq> StructuralPartialEq for Size<T>

Source§

impl<T> Sub for Size<T>
where T: Sub<Output = T> + Clone + Debug + Default + PartialEq,

Source§

type Output = Size<T>

The resulting type after applying the - operator.
Source§

fn sub(self, __rhs: Self) -> Self::Output

Performs the - operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Size<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Size<T>
where T: RefUnwindSafe,

§

impl<T> Send for Size<T>
where T: Send,

§

impl<T> Sync for Size<T>
where T: Sync,

§

impl<T> Unpin for Size<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Size<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Size<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Real + Zero + Arithmetics + Clone, Swp: WhitePoint<T>, Dwp: WhitePoint<T>, D: AdaptFrom<S, Swp, Dwp, T>,

Source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<T>,

👎Deprecated since 0.7.7:

replaced by palette::chromatic_adaptation::AdaptIntoUnclamped

Convert the source color to the destination color using the specified method.
Source§

fn adapt_into(self) -> D

👎Deprecated since 0.7.7:

replaced by palette::chromatic_adaptation::AdaptIntoUnclamped

Convert the source color to the destination color using the bradford method by default.
Source§

impl<T, C> AdaptIntoUnclamped<T> for C
where T: AdaptFromUnclamped<C>,

Source§

type Scalar = <T as AdaptFromUnclamped<C>>::Scalar

The number type that’s used as the color’s components.
Source§

fn adapt_into_unclamped_with<M>(self) -> T

Adapt a color of type Self into a color of type T, using the custom matrix M. Read more
Source§

fn adapt_into_unclamped(self) -> T
where Bradford: LmsToXyz<Self::Scalar> + XyzToLms<Self::Scalar>,

Adapt a color of type Self into a color of type T, using the Bradford matrix. Read more
Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T, C> ArraysFrom<C> for T
where C: IntoArrays<T>,

Source§

fn arrays_from(colors: C) -> T

Cast a collection of colors into a collection of arrays.
Source§

impl<T, C> ArraysInto<C> for T
where C: FromArrays<T>,

Source§

fn arrays_into(self) -> C

Cast this collection of arrays into a collection of colors.
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for U
where T: FromCam16Unclamped<WpParam, U>,

Source§

type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T, C> ComponentsFrom<C> for T
where C: IntoComponents<T>,

Source§

fn components_from(colors: C) -> T

Cast a collection of colors into a collection of color components.
Source§

impl<T, C> ComponentsInto<C> for T

Source§

fn components_into(self) -> C

Cast this collection of color components into a collection of colors. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromAngle<T> for T

Source§

fn from_angle(angle: T) -> T

Performs a conversion from angle.
Source§

impl<T, U> FromStimulus<U> for T
where U: IntoStimulus<T>,

Source§

fn from_stimulus(other: U) -> T

Converts other into Self, while performing the appropriate scaling, rounding and clamping.
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 T
where U: From<T>,

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, U> IntoAngle<U> for T
where U: FromAngle<T>,

Source§

fn into_angle(self) -> U

Performs a conversion into T.
Source§

impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for U
where T: Cam16FromUnclamped<WpParam, U>,

Source§

type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar

The number type that’s used in parameters when converting.
Source§

fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T

Converts self into C, using the provided parameters.
Source§

impl<T, U> IntoColor<U> for T
where U: FromColor<T>,

Source§

fn into_color(self) -> U

Convert into T with values clamped to the color defined bounds Read more
Source§

impl<T, U> IntoColorUnclamped<U> for T
where U: FromColorUnclamped<T>,

Source§

fn into_color_unclamped(self) -> U

Convert into T. The resulting color might be invalid in its color space Read more
Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoStimulus<T> for T

Source§

fn into_stimulus(self) -> T

Converts self into T, while performing the appropriate scaling, rounding and clamping.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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> ToSmolStr for T
where T: Display + ?Sized,

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

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

impl<T, C> TryComponentsInto<C> for T
where C: TryFromComponents<T>,

Source§

type Error = <C as TryFromComponents<T>>::Error

The error for when try_into_colors fails to cast.
Source§

fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>

Try to cast this collection of color components into a collection of colors. Read more
Source§

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

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryIntoColor<U> for T
where U: TryFromColor<T>,

Source§

fn try_into_color(self) -> Result<U, OutOfBounds<U>>

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more
Source§

impl<C, U> UintsFrom<C> for U
where C: IntoUints<U>,

Source§

fn uints_from(colors: C) -> U

Cast a collection of colors into a collection of unsigned integers.
Source§

impl<C, U> UintsInto<C> for U
where C: FromUints<U>,

Source§

fn uints_into(self) -> C

Cast this collection of unsigned integers into a collection of colors.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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