Struct taffy::geometry::Size

source ·
pub struct Size<T> {
    pub width: T,
    pub height: T,
}
Expand description

The width and height of a Rect

Fields§

§width: T

The x extent of the rectangle

§height: T

The y extent of the rectangle

Implementations§

source§

impl<T> Size<T>

source

pub fn get_abs(self, axis: AbsoluteAxis) -> T

Get either the width or height depending on the AbsoluteAxis passed in

source§

impl<T> Size<T>

source

pub fn map<R, F>(self, f: F) -> Size<R>
where F: Fn(T) -> R,

Applies the function f to both the width and height

This is used to transform a Size<T> into a Size<R>.

source

pub fn map_width<F>(self, f: F) -> Size<T>
where F: Fn(T) -> T,

Applies the function f to the width

source

pub fn map_height<F>(self, f: F) -> Size<T>
where F: Fn(T) -> T,

Applies the function f to the height

source

pub fn zip_map<Other, Ret, Func>(self, other: Size<Other>, f: Func) -> Size<Ret>
where Func: Fn(T, Other) -> Ret,

Applies the function f to both the width and height of this value and another passed value

source

pub(crate) fn get(self, axis: AbstractAxis) -> T

Gets the extent of the specified layout axis Whether this is the width or height depends on the GridAxis provided

source

pub(crate) fn set(&mut self, axis: AbstractAxis, value: T)

Sets the extent of the specified layout axis Whether this is the width or height depends on the GridAxis provided

source§

impl Size<f32>

source

pub const ZERO: Size<f32> = _

A Size with zero width and height

source

pub fn f32_max(self, rhs: Size<f32>) -> Size<f32>

Applies f32_max to each component separately

source

pub fn f32_min(self, rhs: Size<f32>) -> Size<f32>

Applies f32_min to each component separately

source

pub fn has_non_zero_area(self) -> bool

Return true if both width and height are greater than 0 else false

source§

impl Size<Option<f32>>

source

pub const NONE: Size<Option<f32>> = _

A Size with None width and height

source

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

A Size<Option<f32>> with Some(width) and Some(height) as parameters

source

pub fn maybe_apply_aspect_ratio( self, aspect_ratio: Option<f32>, ) -> Size<Option<f32>>

Applies aspect_ratio (if one is supplied) to the Size:

  • If width is Some but height is None, then height is computed from width and aspect_ratio
  • If height is Some but width is None, then width is computed from height and aspect_ratio

If aspect_ratio is None then this function simply returns self.

source§

impl<T> Size<Option<T>>

source

pub fn unwrap_or(self, alt: Size<T>) -> Size<T>

Performs Option::unwrap_or on each component separately

source

pub fn or(self, alt: Size<Option<T>>) -> Size<Option<T>>

Performs Option::or on each component separately

source

pub fn both_axis_defined(&self) -> bool

Return true if both components are Some, else false.

source§

impl Size<Dimension>

source

pub const fn from_lengths(width: f32, height: f32) -> Self

Generates a Size<Dimension> using Dimension::Length values

source

pub const fn from_percent(width: f32, height: f32) -> Self

Generates a Size<Dimension> using Dimension::Percent values

source§

impl Size<AvailableSpace>

source

pub fn into_options(self) -> Size<Option<f32>>

Convert Size<AvailableSpace> into Size<Option<f32>>

source

pub fn maybe_set(self, value: Size<Option<f32>>) -> Size<AvailableSpace>

If passed value is Some then return AvailableSpace::Definite containing that value, else return self

source§

impl<T: TaffyZero> Size<T>

source

pub const fn zero() -> Self

Returns a Size where both the width and height values are the zero value of the contained type (e.g. 0.0, Some(0.0), or Dimension::Length(0.0))

source§

impl<T: TaffyAuto> Size<T>

source

pub const fn auto() -> Self

Returns a Size where both the width and height values are the auto value of the contained type (e.g. Dimension::Auto or LengthPercentageAuto::Auto)

source§

impl<T: TaffyMinContent> Size<T>

source

pub const fn min_content() -> Self

Returns a Size where both the width and height values are the min_content value of the contained type (e.g. Dimension::Auto or LengthPercentageAuto::Auto)

source§

impl<T: TaffyMaxContent> Size<T>

source

pub const fn max_content() -> Self

Returns a Size where both the width and height values are the max_content value of the contained type (e.g. Dimension::Auto or LengthPercentageAuto::Auto)

source§

impl<T: TaffyFitContent> Size<T>

source

pub fn fit_content(argument: LengthPercentage) -> Self

Returns a Size where with width and height set to the same fit-content(…) value with the given argument.

source§

impl<T: FromLength> Size<T>

source

pub fn length<Input: Into<f32> + Copy>(value: Input) -> Self

Returns a Size where both the width and height values the same given absolute length

source§

impl<T: FromPercent> Size<T>

source

pub fn percent<Input: Into<f32> + Copy>(percent_value: Input) -> Self

Returns a Size where both the width and height values are the constant percent value of the contained type (e.g. 2.1, Some(2.1), or Dimension::Length(2.1))

Trait Implementations§

source§

impl<U, T: Add<U>> Add<Size<U>> for Size<T>

source§

type Output = Size<<T as Add<U>>::Output>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Size<U>) -> Self::Output

Performs the + operation. Read more
source§

impl<T: Clone> Clone for Size<T>

source§

fn clone(&self) -> Size<T>

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<T: Debug> Debug for Size<T>

source§

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

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

impl<T: Default> Default for Size<T>

source§

fn default() -> Size<T>

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

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

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> From<Point<T>> for Size<T>

source§

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

Converts to this type from the input type.
source§

impl<T: FromLength> FromLength for Size<T>

source§

fn from_length<Input: Into<f32> + Copy>(value: Input) -> Self

Converts into an Into<f32> into Self
source§

impl<T: FromPercent> FromPercent for Size<T>

source§

fn from_percent<Input: Into<f32> + Copy>(percent: Input) -> Self

Converts into an Into<f32> into Self
source§

impl<In, Out, T: MaybeMath<In, Out>> MaybeMath<Size<In>, Size<Out>> for Size<T>

source§

fn maybe_min(self, rhs: Size<In>) -> Size<Out>

Returns the minimum of self and rhs
source§

fn maybe_max(self, rhs: Size<In>) -> Size<Out>

Returns the maximum of self and rhs
source§

fn maybe_clamp(self, min: Size<In>, max: Size<In>) -> Size<Out>

Returns self clamped between min and max
source§

fn maybe_add(self, rhs: Size<In>) -> Size<Out>

Adds self and rhs.
source§

fn maybe_sub(self, rhs: Size<In>) -> Size<Out>

Subtracts rhs from self, treating None values as default
source§

impl<In, Out, T: MaybeResolve<In, Out>> MaybeResolve<Size<In>, Size<Out>> for Size<T>

source§

fn maybe_resolve(self, context: Size<In>) -> Size<Out>

Converts any parent-relative values for size into an absolute size

source§

impl<T: PartialEq> PartialEq for Size<T>

source§

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

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

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

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

impl<In: Copy, Out: TaffyZero, T: ResolveOrZero<In, Out>> ResolveOrZero<Size<In>, Rect<Out>> for Rect<T>

source§

fn resolve_or_zero(self, context: Size<In>) -> Rect<Out>

Converts any parent-relative values for Rect into an absolute Rect

source§

impl<In, Out: TaffyZero, T: ResolveOrZero<In, Out>> ResolveOrZero<Size<In>, Size<Out>> for Size<T>

source§

fn resolve_or_zero(self, context: Size<In>) -> Size<Out>

Converts any parent-relative values for size into an absolute size

source§

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

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<U, T: Sub<U>> Sub<Size<U>> for Size<T>

source§

type Output = Size<<T as Sub<U>>::Output>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Size<U>) -> Self::Output

Performs the - operation. Read more
source§

impl<T: TaffyAuto> TaffyAuto for Size<T>

source§

const AUTO: Size<T> = _

The auto value for type implementing TaffyAuto
source§

impl<T: TaffyFitContent> TaffyFitContent for Size<T>

source§

fn fit_content(argument: LengthPercentage) -> Self

Converts a LengthPercentage into Self
source§

impl<T: TaffyMaxContent> TaffyMaxContent for Size<T>

source§

const MAX_CONTENT: Size<T> = _

The max_content value for type implementing TaffyZero
source§

impl<T: TaffyMinContent> TaffyMinContent for Size<T>

source§

const MIN_CONTENT: Size<T> = _

The min_content value for type implementing TaffyZero
source§

impl<T: TaffyZero> TaffyZero for Size<T>

source§

const ZERO: Size<T> = _

The zero value for type implementing TaffyZero
source§

impl<T: Copy> Copy for Size<T>

source§

impl<T: Eq> Eq for Size<T>

source§

impl<T> StructuralPartialEq for Size<T>

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> UnwindSafe for Size<T>
where T: UnwindSafe,

Blanket Implementations§

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> 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<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> 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, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

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

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

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,