Struct style::values::specified::percentage::Percentage
source · pub struct Percentage {
value: CSSFloat,
calc_clamping_mode: Option<AllowedNumericType>,
}
Expand description
A percentage value.
Fields§
§value: CSSFloat
The percentage value as a float.
[0 .. 100%] maps to [0.0 .. 1.0]
calc_clamping_mode: Option<AllowedNumericType>
If this percentage came from a calc() expression, this tells how clamping should be done on the value.
Implementations§
source§impl Percentage
impl Percentage
sourcepub(super) fn new_with_clamping_mode(
value: CSSFloat,
calc_clamping_mode: Option<AllowedNumericType>,
) -> Self
pub(super) fn new_with_clamping_mode( value: CSSFloat, calc_clamping_mode: Option<AllowedNumericType>, ) -> Self
Creates a percentage from a numeric value.
sourcepub fn calc_clamping_mode(&self) -> Option<AllowedNumericType>
pub fn calc_clamping_mode(&self) -> Option<AllowedNumericType>
Returns the calc() clamping mode for this percentage.
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(self) -> Self
pub fn clamp_to_hundred(self) -> 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
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for Percentage
impl Debug for Percentage
source§impl Default for Percentage
impl Default for Percentage
source§fn default() -> Percentage
fn default() -> Percentage
Returns the “default value” for a type. Read more
source§impl From<Percentage> for LengthPercentage
impl From<Percentage> for LengthPercentage
source§fn from(pc: Percentage) -> Self
fn from(pc: Percentage) -> Self
Converts to this type from the input type.
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
Measure the heap usage of all descendant heap-allocated structures, but
not the space taken up by the value itself.
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>>
Parse a value of this type. Read more
source§impl PartialEq for Percentage
impl PartialEq for Percentage
source§impl SpecifiedValueInfo for Percentage
impl SpecifiedValueInfo for Percentage
source§const SUPPORTED_TYPES: u8 = 0u8
const SUPPORTED_TYPES: u8 = 0u8
Supported CssTypes by the given value type. Read more
source§impl ToComputedValue for Percentage
impl ToComputedValue for Percentage
source§type ComputedValue = Percentage
type ComputedValue = Percentage
The computed value type we’re going to be converted to.
source§fn to_computed_value(&self, _: &Context<'_>) -> Self::ComputedValue
fn to_computed_value(&self, _: &Context<'_>) -> Self::ComputedValue
Convert a specified value to a computed value, using itself and the data
inside the
Context
.source§fn from_computed_value(computed: &Self::ComputedValue) -> Self
fn from_computed_value(computed: &Self::ComputedValue) -> Self
Convert a computed value to specified value form. Read more
source§impl ToCss for Percentage
impl ToCss for Percentage
source§impl ToPercentage for Percentage
impl ToPercentage for Percentage
source§impl ToShmem for Percentage
impl ToShmem for Percentage
impl Copy for Percentage
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 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
Mutably borrows from an owned value. Read more
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)
🔬This is a nightly-only experimental API. (
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>
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 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>
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 moresource§impl<T> MaybeBoxed<Box<T>> for T
impl<T> MaybeBoxed<Box<T>> for T
source§fn maybe_boxed(self) -> Box<T>
fn maybe_boxed(self) -> Box<T>
Convert
source§impl<T> MaybeBoxed<T> for T
impl<T> MaybeBoxed<T> for T
source§fn maybe_boxed(self) -> T
fn maybe_boxed(self) -> T
Convert