#[repr(transparent)]
pub(crate) 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() -> LengthPercentage

1px length value for SVG defaults

source

pub fn zero_percent() -> LengthPercentage

0%

source

pub fn new_length(length: CSSPixelLength) -> LengthPercentage

Constructs a length value.

source

pub fn new_percent(percentage: Percentage) -> LengthPercentage

Constructs a percentage value.

source

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

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

source

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

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

source

pub fn new_calc( node: GenericCalcNode<CalcLengthPercentageLeaf>, clamping_mode: AllowedNumericType, ) -> LengthPercentage

Constructs a calc() value.

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: CSSPixelLength) -> CSSPixelLength

Resolves the percentage.

source

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

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

Converts to a <length> if possible.

source

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

Converts to a <percentage> if possible.

source

pub fn to_percentage_of(&self, basis: CSSPixelLength) -> Option<Percentage>

Converts to a <percentage> with given basis. Returns None if the basis is 0.

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) -> CSSPixelLength

Returns the used value as CSSPixelLength.

source

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

Convert the computed value into used value.

source

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

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) -> LengthPercentage

Returns the clamped non-negative values.

source§

impl LengthPercentage

source

pub fn normal() -> LengthPercentage

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: &LengthPercentage, procedure: Procedure, ) -> Result<LengthPercentage, ()>

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

impl Clone for LengthPercentage

source§

fn clone(&self) -> LengthPercentage

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: &LengthPercentage, ) -> Result<SquaredDistance, ()>

Computes the squared distance between two animatable values.
source§

impl Debug for LengthPercentage

source§

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

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

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

source§

fn deserialize<D>( deserializer: D, ) -> Result<LengthPercentage, <D as Deserializer<'de>>::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 for LengthPercentage

source§

fn eq(&self, other: &LengthPercentage) -> 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 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 as Serializer>::Ok, <S as Serializer>::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<CSSPixelLength>, ) -> Result<f32, ()>

Returns the absolute length as pixel value.
source§

impl ToAnimatedValue for LengthPercentage

source§

type AnimatedValue = LengthPercentage

The type of the animated value.
source§

fn to_animated_value( self, context: &Context<'_>, ) -> <LengthPercentage as ToAnimatedValue>::AnimatedValue

Converts this value to an animated value.
source§

fn from_animated_value( value: <LengthPercentage as ToAnimatedValue>::AnimatedValue, ) -> LengthPercentage

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

impl ToAnimatedZero for LengthPercentage

source§

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

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>) -> Result<(), Error>
where 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

source§

type ResolvedValue = LengthPercentage

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

fn to_resolved_value( self, context: &Context<'_>, ) -> <LengthPercentage as ToResolvedValue>::ResolvedValue

Convert a resolved value to a resolved value.
source§

fn from_resolved_value( value: <LengthPercentage as ToResolvedValue>::ResolvedValue, ) -> LengthPercentage

Convert a resolved value to resolved value form.
source§

impl Zero for LengthPercentage

source§

fn zero() -> LengthPercentage

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 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> Downcast<T> for T

source§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

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 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> 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>> for T

source§

fn maybe_boxed(self) -> Box<T>

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.
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> Same for T

source§

type Output = T

Should always be Self
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> Upcast<T> for T

source§

fn upcast(&self) -> Option<&T>

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

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

source§

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

source§

impl<T> MaybeSendSync for T

source§

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

source§

impl<T> WasmNotSendSync for T

source§

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