#[repr(transparent)]
pub struct LengthPercentage(LengthPercentageUnion);
Expand description

A <length-percentage> value. This can be either a <length>, a <percentage>, or a combination of both via calc().

cbindgen:private-default-tagged-enum-constructor=false cbindgen:derive-mut-casts=true

https://drafts.csswg.org/css-values-4/#typedef-length-percentage

The tag is stored in the lower two bits.

We need to use a struct instead of the union directly because unions with Drop implementations are unstable, looks like.

Also we need the union and the variants to be pub (even though the member is private) so that cbindgen generates it. They’re not part of the public API otherwise.

Tuple Fields§

§0: LengthPercentageUnion

Implementations§

source§

impl LengthPercentage

source

pub fn one() -> Self

1px length value for SVG defaults

source

pub fn zero_percent() -> Self

0%

source

fn to_calc_node(&self) -> Cow<'_, CalcNode>

source

pub fn new_length(length: Length) -> Self

Constructs a length value.

source

pub fn new_percent(percentage: Percentage) -> Self

Constructs a percentage value.

source

pub fn hundred_percent_minus(v: Self, clamping_mode: AllowedNumericType) -> Self

Given a LengthPercentage value v, construct the value representing calc(100% - v).

source

pub fn hundred_percent_minus_list( list: &[&Self], clamping_mode: AllowedNumericType ) -> Self

Given a list of LengthPercentage values, construct the value representing calc(100% - the sum of the list).

source

pub fn new_calc(node: CalcNode, clamping_mode: AllowedNumericType) -> Self

Constructs a calc() value.

source

fn new_calc_unchecked(calc: Box<CalcLengthPercentage>) -> Self

Private version of new_calc() that constructs a calc() variant without checking.

source

fn tag(&self) -> Tag

source

fn unpack_mut<'a>(&'a mut self) -> UnpackedMut<'a>

source

fn unpack<'a>(&'a self) -> Unpacked<'a>

source

unsafe fn calc_ptr(&self) -> *mut CalcLengthPercentage

source

fn to_serializable(&self) -> Serializable

source

fn from_serializable(s: Serializable) -> Self

source

pub fn is_definitely_zero(&self) -> bool

Returns true if the computed value is absolute 0 or 0%.

source

pub fn resolve(&self, basis: Length) -> Length

Resolves the percentage.

source

pub fn percentage_relative_to(&self, basis: Length) -> Length

Resolves the percentage. Just an alias of resolve().

source

pub fn has_percentage(&self) -> bool

Return whether there’s any percentage in this value.

source

pub fn to_length(&self) -> Option<Length>

Converts to a <length> if possible.

source

pub fn to_percentage(&self) -> Option<Percentage>

Converts to a <percentage> if possible.

source

pub fn to_used_value(&self, containing_length: Au) -> Au

Returns the used value.

source

pub fn to_pixel_length(&self, containing_length: Au) -> Length

Returns the used value as CSSPixelLength.

source

pub fn maybe_to_used_value(&self, container_len: Option<Length>) -> Option<Au>

Convert the computed value into used value.

source

pub fn maybe_percentage_relative_to( &self, container_len: Option<Length> ) -> Option<Length>

If there are special rules for computing percentages in a value (e.g. the height property), they apply whenever a calc() expression contains percentages.

source

pub fn clamp_to_non_negative(self) -> Self

Returns the clamped non-negative values.

source§

impl LengthPercentage

source

pub fn normal() -> Self

Return the normal computed value, which is just zero.

Trait Implementations§

source§

impl Animate for LengthPercentage

https://drafts.csswg.org/css-transitions/#animtype-lpcalc https://drafts.csswg.org/css-values-4/#combine-math https://drafts.csswg.org/css-values-4/#combine-mixed

source§

fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()>

Animate a value towards another one, given an animation procedure.
source§

impl Clone for LengthPercentage

source§

fn clone(&self) -> Self

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 ComputeSquaredDistance for LengthPercentage

source§

fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()>

Computes the squared distance between two animatable values.
source§

impl Debug for LengthPercentage

source§

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

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

impl<'de> Deserialize<'de> for LengthPercentage

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 Drop for LengthPercentage

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl MallocSizeOf for LengthPercentage

source§

fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize

Measure the heap usage of all descendant heap-allocated structures, but not the space taken up by the value itself.
source§

impl PartialEq<LengthPercentage> for LengthPercentage

source§

fn eq(&self, other: &Self) -> 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 PositionComponent for LengthPercentage

source§

fn is_center(&self) -> bool

Returns if the position component is 50% or center. For pixel lengths, it always returns false.
source§

impl Serialize for LengthPercentage

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 ToAbsoluteLength for LengthPercentage

source§

fn to_pixel_length( &self, containing_len: Option<ComputedLength> ) -> Result<CSSFloat, ()>

Returns the absolute length as pixel value.
source§

impl ToAnimatedValue for LengthPercentage

§

type AnimatedValue = LengthPercentage

The type of the animated value.
source§

fn to_animated_value(self) -> Self

Converts this value to an animated value.
source§

fn from_animated_value(animated: Self::AnimatedValue) -> Self

Converts back an animated value into a computed value.
source§

impl ToAnimatedZero for LengthPercentage

source§

fn to_animated_zero(&self) -> Result<Self, ()>

Returns a value that, when added with an underlying value, will produce the underlying value. This is used for SMIL animation’s “by-animation” where SMIL first interpolates from the zero value to the ‘by’ value, and then adds the result to the underlying value. Read more
source§

impl ToCss for LengthPercentage

source§

fn to_css<W>(&self, dest: &mut CssWriter<'_, W>) -> Resultwhere W: Write,

Serialize self in CSS syntax, writing to dest.
source§

fn to_css_string(&self) -> String

Serialize self in CSS syntax and return a string. Read more
source§

impl ToResolvedValue for LengthPercentage

§

type ResolvedValue = LengthPercentage

The resolved value type we’re going to be converted to.
source§

fn to_resolved_value(self, _: &Context<'_>) -> Self

Convert a resolved value to a resolved value.
source§

fn from_resolved_value(resolved: Self::ResolvedValue) -> Self

Convert a resolved value to resolved value form.
source§

impl Zero for LengthPercentage

source§

fn zero() -> Self

Returns the zero value.
source§

fn is_zero(&self) -> bool

Returns whether this value is zero.
source§

impl ZeroNoPercent for LengthPercentage

source§

fn is_zero_no_percent(&self) -> bool

So, 0px should return true, but 0% or 1px should return false

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> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> 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> MaybeBoxed<Box<T, Global>> for T

source§

fn maybe_boxed(self) -> Box<T, Global>

Convert
source§

impl<T> MaybeBoxed<T> for T

source§

fn maybe_boxed(self) -> T

Convert
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

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> 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.
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.
source§

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

Performs the conversion.
source§

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

source§

impl<T> Erased for T

source§

impl<T> ErasedDestructor for Twhere T: 'static,

source§

impl<T> MaybeSendSync for T