#[repr(transparent)]pub struct CompactLength(CompactLengthInner);Expand description
A representation of a length as a compact 64-bit tagged pointer
Tuple Fields§
§0: CompactLengthInnerImplementations§
Source§impl CompactLength
Tag layout
impl CompactLength
Tag layout
Tags are 8 bits. The low 3 bits are shared with pointer variants (such as calc()), which require
an 8-byte aligned pointer and so always have those bits clear. They are assigned as follows:
- Bit 0 (
NON_POINTER_BIT): set for every variant that is not a pointer. Pointer variants (calc()) have this bit clear, sois_plain_calc()is a single bit test. - Bit 1 (
KEYWORD_BIT): set for every variant that is not a plain length, percentage or calc() value (i.e. everything that cannot be resolved to a length given only a percentage basis). - Bit 2 (
PERCENTAGE_BIT): set for every variant whose resolved value depends on a percentage basis, including allcalc()variants.uses_percentage()is a single bit test.
Pointer variants are distinguished by bit 1: calc() is 0b100 and fit-content(calc()) is 0b110.
Any pointer variant’s tag() includes address bits 3..7, so pointer variants must be tested with low-bit
masks (is_plain_calc(), is_fit_content_calc(), has_calc()) rather than as match arms.
Within the keyword class, bit 3 (SIZING_KEYWORD_BIT) is set for the CSS sizing keywords
(min-content, max-content, fit-content, fit-content(), stretch) and clear for auto,
fr and content. The remaining high bits distinguish variants within a class.
Sourcepub const NON_POINTER_BIT: usize = 0b0001
pub const NON_POINTER_BIT: usize = 0b0001
Bit set for all non-pointer (i.e. not calc()) tags
Sourcepub const KEYWORD_BIT: usize = 0b0010
pub const KEYWORD_BIT: usize = 0b0010
Bit set for all tags that are not a plain length, percentage or calc() value
Sourcepub const PERCENTAGE_BIT: usize = 0b0100
pub const PERCENTAGE_BIT: usize = 0b0100
Bit set for all tags whose value depends on a percentage basis (including calc())
Sourcepub const SIZING_KEYWORD_BIT: usize = 0b1000
pub const SIZING_KEYWORD_BIT: usize = 0b1000
Bit set (in addition to KEYWORD_BIT) for all CSS sizing keyword tags
Sourcepub const FIT_CONTENT_CALC_TAG: usize = 0b0000_0110
pub const FIT_CONTENT_CALC_TAG: usize = 0b0000_0110
The tag indicating a fit-content() value with a calc() limit
Sourcepub const LENGTH_TAG: usize = 0b0000_0001
pub const LENGTH_TAG: usize = 0b0000_0001
The tag indicating a length value
Sourcepub const PERCENT_TAG: usize = 0b0000_0101
pub const PERCENT_TAG: usize = 0b0000_0101
The tag indicating a percentage value
Sourcepub const CONTENT_TAG: usize = 0b0010_0011
pub const CONTENT_TAG: usize = 0b0010_0011
The tag indicating a content keyword value
Sourcepub const MIN_CONTENT_TAG: usize = 0b0000_1011
pub const MIN_CONTENT_TAG: usize = 0b0000_1011
The tag indicating a min-content value
Sourcepub const MAX_CONTENT_TAG: usize = 0b0001_1011
pub const MAX_CONTENT_TAG: usize = 0b0001_1011
The tag indicating a max-content value
Sourcepub const FIT_CONTENT_PX_TAG: usize = 0b0010_1011
pub const FIT_CONTENT_PX_TAG: usize = 0b0010_1011
The tag indicating a fit-content value with px limit
Sourcepub const FIT_CONTENT_KEYWORD_TAG: usize = 0b0011_1011
pub const FIT_CONTENT_KEYWORD_TAG: usize = 0b0011_1011
The tag indicating a plain fit-content keyword value (no limit)
Sourcepub const STRETCH_TAG: usize = 0b0100_1011
pub const STRETCH_TAG: usize = 0b0100_1011
The tag indicating a stretch keyword value
Sourcepub const FIT_CONTENT_PERCENT_TAG: usize = 0b0000_1111
pub const FIT_CONTENT_PERCENT_TAG: usize = 0b0000_1111
The tag indicating a fit-content value with percent limit
Source§impl CompactLength
impl CompactLength
Sourcepub const fn length(val: f32) -> Self
pub const fn length(val: f32) -> Self
An absolute length in some abstract units. Users of Taffy may define what they correspond to in their application (pixels, logical pixels, mm, etc) as they see fit.
Sourcepub const fn percent(val: f32) -> Self
pub const fn percent(val: f32) -> Self
A percentage length relative to the size of the containing block.
NOTE: percentages are represented as a f32 value in the range [0.0, 1.0] NOT the range [0.0, 100.0]
Sourcepub fn calc(ptr: *const ()) -> Self
pub fn calc(ptr: *const ()) -> Self
A calc() value. The value passed here is treated as an opaque handle to
the actual calc representation and may be a pointer, index, etc.
The low 3 bits are used as a tag value and will be returned as 0.
Sourcepub fn fit_content_calc(ptr: *const ()) -> Self
pub fn fit_content_calc(ptr: *const ()) -> Self
A fit-content(calc()) value. The value passed here is treated as an opaque handle to
the actual calc representation of the limit and may be a pointer, index, etc.
The low 3 bits are used as a tag value and will be returned as 0.
Sourcepub const fn auto() -> Self
pub const fn auto() -> Self
The dimension should be automatically computed according to algorithm-specific rules regarding the default size of boxes.
Sourcepub const fn fr(val: f32) -> Self
pub const fn fr(val: f32) -> Self
The dimension as a fraction of the total available grid space (fr units in CSS)
Specified value is the numerator of the fraction. Denominator is the sum of all fraction specified in that grid dimension
Spec: https://www.w3.org/TR/css3-grid-layout/#fr-unit
Sourcepub const fn min_content() -> Self
pub const fn min_content() -> Self
The size should be the “min-content” size. This is the smallest size that can fit the item’s contents with ALL soft line-wrapping opportunities taken
Sourcepub const fn max_content() -> Self
pub const fn max_content() -> Self
The size should be the “max-content” size. This is the smallest size that can fit the item’s contents with NO soft line-wrapping opportunities taken
Sourcepub const fn fit_content_px(limit: f32) -> Self
pub const fn fit_content_px(limit: f32) -> Self
The size should be computed according to the “fit content” formula:
max(min_content, min(max_content, limit))
where:
min_contentis the min-content sizemax_contentis the max-content sizelimitis a LENGTH value passed to this function
The effect of this is that the item takes the size of limit clamped
by the min-content and max-content sizes.
Sourcepub const fn fit_content_percent(limit: f32) -> Self
pub const fn fit_content_percent(limit: f32) -> Self
The size should be computed according to the “fit content” formula:
max(min_content, min(max_content, limit))
where:
min_contentis the min-content sizemax_contentis the max-content sizelimitis a PERCENTAGE value passed to this function
The effect of this is that the item takes the size of limit clamped
by the min-content and max-content sizes.
Sourcepub const fn fit_content_keyword() -> Self
pub const fn fit_content_keyword() -> Self
The size should be computed according to the “fit content” formula:
max(min_content, min(max_content, stretch))
where:
min_contentis the min-content sizemax_contentis the max-content sizestretchis the “stretch-fit” size (the size the box would take if it filled the available space)
Sourcepub const fn stretch() -> Self
pub const fn stretch() -> Self
The size should be the “stretch-fit” size: the size the box would take if it filled the available space (https://www.w3.org/TR/css-sizing-4/#stretch-fit-sizing)
Sourcepub const fn content() -> Self
pub const fn content() -> Self
The size should be an automatic size based on the box’s content (https://www.w3.org/TR/css-flexbox-1/#valdef-flex-basis-content)
This keyword is only valid for flex-basis. In any other context it behaves as auto.
Sourcepub fn value(self) -> f32
pub fn value(self) -> f32
Get the numeric value associated with the CompactLength
(e.g. the pixel value for a LENGTH variant)
Sourcepub fn calc_value(self) -> *const ()
pub fn calc_value(self) -> *const ()
Get the calc pointer of the CompactLength
Sourcepub fn is_plain_calc(self) -> bool
pub fn is_plain_calc(self) -> bool
Returns true if the value is a plain calc() value (not a fit-content(calc()) value)
Sourcepub fn is_fit_content_calc(self) -> bool
pub fn is_fit_content_calc(self) -> bool
Returns true if the value is a fit-content() value with a calc() limit
Sourcepub fn has_calc(self) -> bool
pub fn has_calc(self) -> bool
Returns true if the value holds a calc() pointer: either a plain calc() value or a
fit-content() value with a calc() limit. calc_value() is valid for exactly these values.
Sourcepub fn is_length_or_percentage(self) -> bool
pub fn is_length_or_percentage(self) -> bool
Returns true if the value is a length or percentage value
Sourcepub fn is_length_percentage_or_calc(self) -> bool
pub fn is_length_percentage_or_calc(self) -> bool
Returns true if the value is a length, a percentage or a plain calc() value (not a
fit-content(calc()) value): anything that resolves to a length given a percentage basis
Sourcepub fn is_content(self) -> bool
pub fn is_content(self) -> bool
Returns true if the value is the content keyword
Sourcepub fn is_min_content(self) -> bool
pub fn is_min_content(self) -> bool
Returns true if the value is min-content
Sourcepub fn is_max_content(self) -> bool
pub fn is_max_content(self) -> bool
Returns true if the value is max-content
Sourcepub fn is_fit_content(self) -> bool
pub fn is_fit_content(self) -> bool
Returns true if the value is a fit-content(…) value
Sourcepub fn is_sizing_keyword(self) -> bool
pub fn is_sizing_keyword(self) -> bool
Returns true if the value is min-content, max-content, fit-content, fit-content(…), or stretch
Sourcepub fn is_max_or_fit_content(self) -> bool
pub fn is_max_or_fit_content(self) -> bool
Returns true if the value is max-content or a fit-content(…) value
Sourcepub fn is_max_content_alike(&self) -> bool
pub fn is_max_content_alike(&self) -> bool
Returns true if the max track sizing function is MaxContent, FitContent or Auto else false.
“In all cases, treat auto and fit-content() as max-content, except where specified otherwise for fit-content().”
See: https://www.w3.org/TR/css-grid-1/#algo-terms
Sourcepub fn is_min_or_max_content(&self) -> bool
pub fn is_min_or_max_content(&self) -> bool
Returns true if the min track sizing function is MinContent or MaxContent, else false.
Sourcepub fn is_intrinsic(self) -> bool
pub fn is_intrinsic(self) -> bool
Returns true if the value is auto, min-content, max-content, or fit-content(…)
Sourcepub fn uses_percentage(self) -> bool
pub fn uses_percentage(self) -> bool
Whether the track sizing functions depends on the size of the parent node
Trait Implementations§
Source§impl Clone for CompactLength
impl Clone for CompactLength
Source§fn clone(&self) -> CompactLength
fn clone(&self) -> CompactLength
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more