pub struct Percentage(NumericUnion<(), f32, CalcNumeric>);Expand description
A specified percentage value, either a plain value or a calc() expression.
Tuple Fields§
§0: NumericUnion<(), f32, CalcNumeric>Implementations§
Source§impl Percentage
impl Percentage
Sourcepub fn new_calc(val: Box<CalcNumeric>) -> Self
pub fn new_calc(val: Box<CalcNumeric>) -> Self
Returns a new percentage calc value with the value val.
Sourcepub fn get(&self) -> Option<f32>
pub fn get(&self) -> Option<f32>
Returns the value if this is a plain (non-calc) percentage, or None otherwise.
Use resolve() to also handle resolvable calc expressions, or to_computed_value()
when computed context is available.
Sourcepub fn resolve(&self) -> Option<CSSFloat>
pub fn resolve(&self) -> Option<CSSFloat>
Returns the value if it can be resolved at parse time, including resolvable calc expressions. Returns None for calc expressions that require computed context (e.g. those using relative lengths or sibling-index()).
Sourcepub fn to_length_percentage(self) -> LengthPercentage
pub fn to_length_percentage(self) -> LengthPercentage
Returns this percentage as a LengthPercentage.
Sourcepub fn reverse(&mut self)
pub fn reverse(&mut self)
Reverses this percentage, preserving calc-ness.
For example: If it was 20%, convert it into 80%.
Sourcepub fn parse_with_clamping_mode<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
num_context: AllowedNumericType,
) -> Result<Self, ParseError<'i>>
pub fn parse_with_clamping_mode<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, num_context: AllowedNumericType, ) -> Result<Self, ParseError<'i>>
Parses a specific kind of percentage.
Sourcepub fn parse_non_negative<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>>
pub fn parse_non_negative<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, ) -> Result<Self, ParseError<'i>>
Parses a percentage token, but rejects it if it’s negative.
Sourcepub fn parse_zero_to_a_hundred<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>>
pub fn parse_zero_to_a_hundred<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, ) -> Result<Self, ParseError<'i>>
Parses a percentage token, but rejects it if it’s negative or more than 100%.
Sourcepub fn clamp_to_hundred(&mut self)
pub fn clamp_to_hundred(&mut self)
Clamp to 100% if the value is over 100%.
Trait Implementations§
Source§impl Clone for Percentage
impl Clone for Percentage
Source§fn clone(&self) -> Percentage
fn clone(&self) -> Percentage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Percentage
impl Debug for Percentage
Source§impl MallocSizeOf for Percentage
impl MallocSizeOf for Percentage
Source§fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
Source§impl Parse for Percentage
impl Parse for Percentage
Source§fn parse<'i, 't>(
context: &ParserContext<'_>,
input: &mut Parser<'i, 't>,
) -> Result<Self, ParseError<'i>>
fn parse<'i, 't>( context: &ParserContext<'_>, input: &mut Parser<'i, 't>, ) -> Result<Self, ParseError<'i>>
Source§impl PartialEq for Percentage
impl PartialEq for Percentage
Source§impl SpecifiedValueInfo for Percentage
impl SpecifiedValueInfo for Percentage
Source§const SUPPORTED_TYPES: u8 = 0
const SUPPORTED_TYPES: u8 = 0
Source§impl ToComputedValue for Percentage
impl ToComputedValue for Percentage
Source§type ComputedValue = Percentage
type ComputedValue = Percentage
Source§fn to_computed_value(&self, context: &Context<'_>) -> Self::ComputedValue
fn to_computed_value(&self, context: &Context<'_>) -> Self::ComputedValue
Context.Source§fn from_computed_value(computed: &Self::ComputedValue) -> Self
fn from_computed_value(computed: &Self::ComputedValue) -> Self
Source§impl ToCss for Percentage
impl ToCss for Percentage
Source§fn to_css<W>(&self, dest: &mut CssWriter<'_, W>) -> Resultwhere
W: Write,
fn to_css<W>(&self, dest: &mut CssWriter<'_, W>) -> Resultwhere
W: Write,
self in CSS syntax, writing to dest.Source§fn to_css_string(&self) -> String
fn to_css_string(&self) -> String
self in CSS syntax and return a string. Read moreSource§fn to_css_cssstring(&self) -> String
fn to_css_cssstring(&self) -> String
self in CSS syntax and return a CssString. Read moreSource§impl ToPercentage for Percentage
impl ToPercentage for Percentage
Source§impl ToShmem for Percentage
impl ToShmem for Percentage
Source§impl ToTyped for Percentage
impl ToTyped for Percentage
Source§fn to_typed_value(&self) -> Option<TypedValue>
fn to_typed_value(&self) -> Option<TypedValue>
Source§fn to_numeric_value(&self) -> Option<NumericValue>
fn to_numeric_value(&self) -> Option<NumericValue>
Source§fn to_typed_value_list(&self) -> Option<TypedValueList>
fn to_typed_value_list(&self) -> Option<TypedValueList>
impl StructuralPartialEq for Percentage
Auto Trait Implementations§
impl Freeze for Percentage
impl RefUnwindSafe for Percentage
impl Send for Percentage
impl Sync for Percentage
impl Unpin for Percentage
impl UnsafeUnpin for Percentage
impl UnwindSafe for Percentage
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§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