Implement "outer min/max-content" (based on a given min/max-content)

https://dbaron.org/css/intrinsic/#outer-intrinsic
This commit is contained in:
Simon Sapin 2019-12-02 17:36:33 +01:00
parent aa925a5984
commit 8fe37f3ed6
3 changed files with 80 additions and 1 deletions

View file

@ -186,6 +186,16 @@ impl LengthPercentage {
}
}
/// Returns the length component if this could be represented as a
/// non-calc length.
pub fn as_length(&self) -> Option<Length> {
if !self.has_percentage {
Some(self.length_component())
} else {
None
}
}
/// Returns the percentage component if this could be represented as a
/// non-calc percentage.
pub fn as_percentage(&self) -> Option<Percentage> {

View file

@ -92,7 +92,7 @@ where
}
/// Maps the length of this value.
pub fn map(&self, f: impl FnOnce(LengthPercentage) -> LengthPercentage) -> Self {
pub fn map<T>(&self, f: impl FnOnce(LengthPercentage) -> T) -> LengthPercentageOrAuto<T> {
match self {
LengthPercentageOrAuto::LengthPercentage(l) => {
LengthPercentageOrAuto::LengthPercentage(f(l.clone()))