mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Introduce a macro to define Interpolate trait for tuple struct which has Option<T>.
The computed value of word-spacing is T(pub Option<LengthOrPercentage>), the computed value of letter-spacing is similar to this, T(pub Option<Au>). It would be nice to have re-usable macro for these kind of struct.
This commit is contained in:
parent
8c2548a0c4
commit
c120b0b701
2 changed files with 24 additions and 20 deletions
|
@ -736,3 +736,26 @@
|
||||||
%>
|
%>
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
|
/// Macro for defining Interpolate trait for tuple struct which has Option<T>,
|
||||||
|
/// e.g. struct T(pub Option<Au>).
|
||||||
|
<%def name="impl_interpolate_for_option_tuple(value_for_none)">
|
||||||
|
impl Interpolate for T {
|
||||||
|
#[inline]
|
||||||
|
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||||
|
match (self, other) {
|
||||||
|
(&T(Some(ref this)), &T(Some(ref other))) => {
|
||||||
|
Ok(T(this.interpolate(other, progress).ok()))
|
||||||
|
},
|
||||||
|
(&T(Some(ref this)), &T(None)) => {
|
||||||
|
Ok(T(this.interpolate(&${value_for_none}, progress).ok()))
|
||||||
|
},
|
||||||
|
(&T(None), &T(Some(ref other))) => {
|
||||||
|
Ok(T(${value_for_none}.interpolate(other, progress).ok()))
|
||||||
|
},
|
||||||
|
(&T(None), &T(None)) => {
|
||||||
|
Ok(T(None))
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</%def>
|
||||||
|
|
|
@ -445,26 +445,7 @@ ${helpers.single_keyword("text-align-last",
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
pub struct T(pub Option<Au>);
|
pub struct T(pub Option<Au>);
|
||||||
|
|
||||||
impl Interpolate for T {
|
${helpers.impl_interpolate_for_option_tuple('Au(0)')}
|
||||||
#[inline]
|
|
||||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
|
||||||
match (self, other) {
|
|
||||||
(&T(Some(ref this)), &T(Some(ref other))) => {
|
|
||||||
Ok(T(this.interpolate(other, progress).ok()))
|
|
||||||
},
|
|
||||||
(&T(Some(ref this)), &T(None)) => {
|
|
||||||
Ok(T(this.interpolate(&Au(0), progress).ok()))
|
|
||||||
},
|
|
||||||
(&T(None), &T(Some(ref other))) => {
|
|
||||||
Ok(T(Au(0).interpolate(other, progress).ok()))
|
|
||||||
},
|
|
||||||
(&T(None), &T(None)) => {
|
|
||||||
Ok(T(None))
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCss for computed_value::T {
|
impl ToCss for computed_value::T {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue