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>
impl<T> Size<T>
Sourcepub fn get_abs(self, axis: AbsoluteAxis) -> T
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>
impl<T> Size<T>
Sourcepub fn map<R, F>(self, f: F) -> Size<R>where
F: Fn(T) -> R,
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>
.
Sourcepub fn map_width<F>(self, f: F) -> Size<T>where
F: Fn(T) -> T,
pub fn map_width<F>(self, f: F) -> Size<T>where
F: Fn(T) -> T,
Applies the function f
to the width
Sourcepub fn map_height<F>(self, f: F) -> Size<T>where
F: Fn(T) -> T,
pub fn map_height<F>(self, f: F) -> Size<T>where
F: Fn(T) -> T,
Applies the function f
to the height
Sourcepub fn zip_map<Other, Ret, Func>(self, other: Size<Other>, f: Func) -> Size<Ret>where
Func: Fn(T, Other) -> Ret,
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
Sourcepub(crate) fn get(self, axis: AbstractAxis) -> T
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
Sourcepub(crate) fn set(&mut self, axis: AbstractAxis, value: T)
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>
impl Size<f32>
Sourcepub fn has_non_zero_area(self) -> bool
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>>
impl Size<Option<f32>>
Sourcepub const fn new(width: f32, height: f32) -> Self
pub const fn new(width: f32, height: f32) -> Self
A Size<Option<f32>>
with Some(width)
and Some(height)
as parameters
Sourcepub fn maybe_apply_aspect_ratio(
self,
aspect_ratio: Option<f32>,
) -> Size<Option<f32>>
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 isNone
, then height is computed from width and aspect_ratio - If height is
Some
but width isNone
, 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>>
impl<T> Size<Option<T>>
Sourcepub fn unwrap_or(self, alt: Size<T>) -> Size<T>
pub fn unwrap_or(self, alt: Size<T>) -> Size<T>
Performs Option::unwrap_or on each component separately
Sourcepub fn or(self, alt: Size<Option<T>>) -> Size<Option<T>>
pub fn or(self, alt: Size<Option<T>>) -> Size<Option<T>>
Performs Option::or on each component separately
Sourcepub fn both_axis_defined(&self) -> bool
pub fn both_axis_defined(&self) -> bool
Return true if both components are Some, else false.
Source§impl Size<Dimension>
impl Size<Dimension>
Sourcepub const fn from_lengths(width: f32, height: f32) -> Self
pub const fn from_lengths(width: f32, height: f32) -> Self
Generates a Size<Dimension>
using Dimension::Length
values
Sourcepub const fn from_percent(width: f32, height: f32) -> Self
pub const fn from_percent(width: f32, height: f32) -> Self
Generates a Size<Dimension>
using Dimension::Percent
values
Source§impl Size<AvailableSpace>
impl Size<AvailableSpace>
Source§impl<T: TaffyMinContent> Size<T>
impl<T: TaffyMinContent> Size<T>
Sourcepub const fn min_content() -> Self
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>
impl<T: TaffyMaxContent> Size<T>
Sourcepub const fn max_content() -> Self
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>
impl<T: TaffyFitContent> Size<T>
Sourcepub fn fit_content(argument: LengthPercentage) -> Self
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>
impl<T: FromLength> Size<T>
Trait Implementations§
Source§impl<'de, T> Deserialize<'de> for Size<T>where
T: Deserialize<'de>,
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>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<T: FromLength> FromLength for Size<T>
impl<T: FromLength> FromLength for Size<T>
Source§impl<T: FromPercent> FromPercent for Size<T>
impl<T: FromPercent> FromPercent for Size<T>
Source§impl<In, Out, T: MaybeMath<In, Out>> MaybeMath<Size<In>, Size<Out>> for Size<T>
impl<In, Out, T: MaybeMath<In, Out>> MaybeMath<Size<In>, Size<Out>> for Size<T>
Source§impl<In, Out, T: MaybeResolve<In, Out>> MaybeResolve<Size<In>, Size<Out>> for Size<T>
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>
fn maybe_resolve(self, context: Size<In>) -> Size<Out>
Converts any parent
-relative values for size into an absolute size
Source§impl<In: Copy, Out: TaffyZero, T: ResolveOrZero<In, Out>> ResolveOrZero<Size<In>, Rect<Out>> for Rect<T>
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>
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>
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>
fn resolve_or_zero(self, context: Size<In>) -> Size<Out>
Converts any parent
-relative values for size into an absolute size