Struct layout_2020::taffy::stylo_taffy::convert::stylo::LengthPercentage
source · #[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
impl LengthPercentage
sourcepub fn one() -> LengthPercentage
pub fn one() -> LengthPercentage
1px length value for SVG defaults
sourcepub fn zero_percent() -> LengthPercentage
pub fn zero_percent() -> LengthPercentage
0%
sourcepub fn new_length(length: CSSPixelLength) -> LengthPercentage
pub fn new_length(length: CSSPixelLength) -> LengthPercentage
Constructs a length value.
sourcepub fn new_percent(percentage: Percentage) -> LengthPercentage
pub fn new_percent(percentage: Percentage) -> LengthPercentage
Constructs a percentage value.
sourcepub fn hundred_percent_minus(
v: LengthPercentage,
clamping_mode: AllowedNumericType,
) -> LengthPercentage
pub fn hundred_percent_minus( v: LengthPercentage, clamping_mode: AllowedNumericType, ) -> LengthPercentage
Given a LengthPercentage
value v
, construct the value representing
calc(100% - v)
.
sourcepub fn hundred_percent_minus_list(
list: &[&LengthPercentage],
clamping_mode: AllowedNumericType,
) -> LengthPercentage
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)
.
sourcepub fn new_calc(
node: GenericCalcNode<CalcLengthPercentageLeaf>,
clamping_mode: AllowedNumericType,
) -> LengthPercentage
pub fn new_calc( node: GenericCalcNode<CalcLengthPercentageLeaf>, clamping_mode: AllowedNumericType, ) -> LengthPercentage
Constructs a calc()
value.
sourcepub fn is_definitely_zero(&self) -> bool
pub fn is_definitely_zero(&self) -> bool
Returns true if the computed value is absolute 0 or 0%.
sourcepub fn resolve(&self, basis: CSSPixelLength) -> CSSPixelLength
pub fn resolve(&self, basis: CSSPixelLength) -> CSSPixelLength
Resolves the percentage.
sourcepub fn percentage_relative_to(&self, basis: CSSPixelLength) -> CSSPixelLength
pub fn percentage_relative_to(&self, basis: CSSPixelLength) -> CSSPixelLength
Resolves the percentage. Just an alias of resolve().
sourcepub fn has_percentage(&self) -> bool
pub fn has_percentage(&self) -> bool
Return whether there’s any percentage in this value.
sourcepub fn to_length(&self) -> Option<CSSPixelLength>
pub fn to_length(&self) -> Option<CSSPixelLength>
Converts to a <length>
if possible.
sourcepub fn to_percentage(&self) -> Option<Percentage>
pub fn to_percentage(&self) -> Option<Percentage>
Converts to a <percentage>
if possible.
sourcepub fn to_percentage_of(&self, basis: CSSPixelLength) -> Option<Percentage>
pub fn to_percentage_of(&self, basis: CSSPixelLength) -> Option<Percentage>
Converts to a <percentage>
with given basis. Returns None if the basis is 0.
sourcepub fn to_used_value(&self, containing_length: Au) -> Au
pub fn to_used_value(&self, containing_length: Au) -> Au
Returns the used value.
sourcepub fn to_pixel_length(&self, containing_length: Au) -> CSSPixelLength
pub fn to_pixel_length(&self, containing_length: Au) -> CSSPixelLength
Returns the used value as CSSPixelLength.
sourcepub fn maybe_to_used_value(&self, container_len: Option<Au>) -> Option<Au>
pub fn maybe_to_used_value(&self, container_len: Option<Au>) -> Option<Au>
Convert the computed value into used value.
sourcepub fn maybe_percentage_relative_to(
&self,
container_len: Option<CSSPixelLength>,
) -> Option<CSSPixelLength>
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.
sourcepub fn clamp_to_non_negative(self) -> LengthPercentage
pub fn clamp_to_non_negative(self) -> LengthPercentage
Returns the clamped non-negative values.
source§impl LengthPercentage
impl LengthPercentage
sourcepub fn normal() -> LengthPercentage
pub fn normal() -> LengthPercentage
Return the normal
computed value, which is just zero.
Trait Implementations§
source§impl Animate for LengthPercentage
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, ()>
fn animate( &self, other: &LengthPercentage, procedure: Procedure, ) -> Result<LengthPercentage, ()>
source§impl Clone for LengthPercentage
impl Clone for LengthPercentage
source§fn clone(&self) -> LengthPercentage
fn clone(&self) -> LengthPercentage
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl ComputeSquaredDistance for LengthPercentage
impl ComputeSquaredDistance for LengthPercentage
source§fn compute_squared_distance(
&self,
other: &LengthPercentage,
) -> Result<SquaredDistance, ()>
fn compute_squared_distance( &self, other: &LengthPercentage, ) -> Result<SquaredDistance, ()>
source§impl Debug for LengthPercentage
impl Debug for LengthPercentage
source§impl<'de> Deserialize<'de> for LengthPercentage
impl<'de> Deserialize<'de> for LengthPercentage
source§fn deserialize<D>(
deserializer: D,
) -> Result<LengthPercentage, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<LengthPercentage, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
source§impl Drop for LengthPercentage
impl Drop for LengthPercentage
source§impl MallocSizeOf for LengthPercentage
impl MallocSizeOf for LengthPercentage
source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
source§impl PartialEq for LengthPercentage
impl PartialEq for LengthPercentage
source§impl PositionComponent for LengthPercentage
impl PositionComponent for LengthPercentage
source§impl Serialize for LengthPercentage
impl Serialize for LengthPercentage
source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
source§impl ToAbsoluteLength for LengthPercentage
impl ToAbsoluteLength for LengthPercentage
source§fn to_pixel_length(
&self,
containing_len: Option<CSSPixelLength>,
) -> Result<f32, ()>
fn to_pixel_length( &self, containing_len: Option<CSSPixelLength>, ) -> Result<f32, ()>
source§impl ToAnimatedValue for LengthPercentage
impl ToAnimatedValue for LengthPercentage
source§type AnimatedValue = LengthPercentage
type AnimatedValue = LengthPercentage
source§fn to_animated_value(
self,
context: &Context<'_>,
) -> <LengthPercentage as ToAnimatedValue>::AnimatedValue
fn to_animated_value( self, context: &Context<'_>, ) -> <LengthPercentage as ToAnimatedValue>::AnimatedValue
source§fn from_animated_value(
value: <LengthPercentage as ToAnimatedValue>::AnimatedValue,
) -> LengthPercentage
fn from_animated_value( value: <LengthPercentage as ToAnimatedValue>::AnimatedValue, ) -> LengthPercentage
source§impl ToAnimatedZero for LengthPercentage
impl ToAnimatedZero for LengthPercentage
source§fn to_animated_zero(&self) -> Result<LengthPercentage, ()>
fn to_animated_zero(&self) -> Result<LengthPercentage, ()>
source§impl ToCss for LengthPercentage
impl ToCss for LengthPercentage
source§impl ToResolvedValue for LengthPercentage
impl ToResolvedValue for LengthPercentage
source§type ResolvedValue = LengthPercentage
type ResolvedValue = LengthPercentage
source§fn to_resolved_value(
self,
context: &Context<'_>,
) -> <LengthPercentage as ToResolvedValue>::ResolvedValue
fn to_resolved_value( self, context: &Context<'_>, ) -> <LengthPercentage as ToResolvedValue>::ResolvedValue
source§fn from_resolved_value(
value: <LengthPercentage as ToResolvedValue>::ResolvedValue,
) -> LengthPercentage
fn from_resolved_value( value: <LengthPercentage as ToResolvedValue>::ResolvedValue, ) -> LengthPercentage
source§impl Zero for LengthPercentage
impl Zero for LengthPercentage
source§impl ZeroNoPercent for LengthPercentage
impl ZeroNoPercent for LengthPercentage
source§fn is_zero_no_percent(&self) -> bool
fn is_zero_no_percent(&self) -> bool
0px
should return true
, but 0%
or 1px
should return false
Auto Trait Implementations§
impl Freeze for LengthPercentage
impl RefUnwindSafe for LengthPercentage
impl Send for LengthPercentage
impl Sync for LengthPercentage
impl Unpin for LengthPercentage
impl UnwindSafe for LengthPercentage
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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