Struct style::values::computed::length_percentage::LengthPercentage
source · #[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
impl LengthPercentage
sourcepub fn zero_percent() -> Self
pub fn zero_percent() -> Self
0%
fn to_calc_node(&self) -> Cow<'_, CalcNode>
fn map_lengths(&self, map_fn: impl FnMut(Length) -> Length) -> Self
sourcepub fn new_length(length: Length) -> Self
pub fn new_length(length: Length) -> Self
Constructs a length value.
sourcepub fn new_percent(percentage: Percentage) -> Self
pub fn new_percent(percentage: Percentage) -> Self
Constructs a percentage value.
sourcepub fn hundred_percent_minus(v: Self, clamping_mode: AllowedNumericType) -> Self
pub fn hundred_percent_minus(v: Self, clamping_mode: AllowedNumericType) -> Self
Given a LengthPercentage
value v
, construct the value representing
calc(100% - v)
.
sourcepub fn hundred_percent_minus_list(
list: &[&Self],
clamping_mode: AllowedNumericType,
) -> Self
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)
.
sourcepub fn new_calc(node: CalcNode, clamping_mode: AllowedNumericType) -> Self
pub fn new_calc(node: CalcNode, clamping_mode: AllowedNumericType) -> Self
Constructs a calc()
value.
sourcefn new_calc_unchecked(calc: Box<CalcLengthPercentage>) -> Self
fn new_calc_unchecked(calc: Box<CalcLengthPercentage>) -> Self
Private version of new_calc() that constructs a calc() variant without checking.
fn tag(&self) -> Tag
fn unpack_mut<'a>(&'a mut self) -> UnpackedMut<'a>
fn unpack<'a>(&'a self) -> Unpacked<'a>
unsafe fn calc_ptr(&self) -> *mut CalcLengthPercentage
fn to_serializable(&self) -> Serializable
fn from_serializable(s: Serializable) -> Self
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 percentage_relative_to(&self, basis: Length) -> Length
pub fn percentage_relative_to(&self, basis: Length) -> Length
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_percentage(&self) -> Option<Percentage>
pub fn to_percentage(&self) -> Option<Percentage>
Converts to a <percentage>
if possible.
sourcepub fn to_percentage_of(&self, basis: Length) -> Option<Percentage>
pub fn to_percentage_of(&self, basis: Length) -> 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) -> Length
pub fn to_pixel_length(&self, containing_length: Au) -> Length
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<Length>,
) -> Option<Length>
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.
sourcepub fn clamp_to_non_negative(self) -> Self
pub fn clamp_to_non_negative(self) -> Self
Returns the clamped non-negative values.
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§impl Clone for LengthPercentage
impl Clone for LengthPercentage
source§impl ComputeSquaredDistance for LengthPercentage
impl ComputeSquaredDistance for LengthPercentage
source§fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()>
fn compute_squared_distance(&self, other: &Self) -> 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<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::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§impl ToAbsoluteLength for LengthPercentage
impl ToAbsoluteLength for LengthPercentage
source§fn to_pixel_length(
&self,
containing_len: Option<ComputedLength>,
) -> Result<CSSFloat, ()>
fn to_pixel_length( &self, containing_len: Option<ComputedLength>, ) -> Result<CSSFloat, ()>
source§impl ToAnimatedValue for LengthPercentage
impl ToAnimatedValue for LengthPercentage
source§type AnimatedValue = LengthPercentage
type AnimatedValue = LengthPercentage
source§fn to_animated_value(self, context: &AnimatedContext<'_>) -> Self::AnimatedValue
fn to_animated_value(self, context: &AnimatedContext<'_>) -> Self::AnimatedValue
source§fn from_animated_value(value: Self::AnimatedValue) -> Self
fn from_animated_value(value: Self::AnimatedValue) -> Self
source§impl ToAnimatedZero for LengthPercentage
impl ToAnimatedZero for LengthPercentage
source§fn to_animated_zero(&self) -> Result<Self, ()>
fn to_animated_zero(&self) -> Result<Self, ()>
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: &ResolvedContext<'_>) -> Self::ResolvedValue
fn to_resolved_value(self, context: &ResolvedContext<'_>) -> Self::ResolvedValue
source§fn from_resolved_value(value: Self::ResolvedValue) -> Self
fn from_resolved_value(value: Self::ResolvedValue) -> Self
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> 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