mirror of
https://github.com/servo/servo.git
synced 2025-08-08 06:55:31 +01:00
Derive Animate for computed::Angle
This commit is contained in:
parent
b543b17cf0
commit
1ace6d4c7f
1 changed files with 6 additions and 19 deletions
|
@ -12,8 +12,10 @@ use values::animated::{Animate, Procedure};
|
||||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||||
|
|
||||||
/// A computed angle.
|
/// A computed angle.
|
||||||
|
#[animate(fallback = "Self::animate_fallback")]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf, Deserialize, Serialize))]
|
||||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, PartialOrd, ToAnimatedZero)]
|
#[derive(Animate, Clone, Copy, Debug, HasViewportPercentage, PartialEq)]
|
||||||
|
#[derive(PartialOrd, ToAnimatedZero)]
|
||||||
pub enum Angle {
|
pub enum Angle {
|
||||||
/// An angle with degree unit.
|
/// An angle with degree unit.
|
||||||
Degree(CSSFloat),
|
Degree(CSSFloat),
|
||||||
|
@ -62,26 +64,11 @@ impl Angle {
|
||||||
pub fn zero() -> Self {
|
pub fn zero() -> Self {
|
||||||
Angle::Radian(0.0)
|
Angle::Radian(0.0)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-transitions/#animtype-number
|
/// https://drafts.csswg.org/css-transitions/#animtype-number
|
||||||
impl Animate for Angle {
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
fn animate_fallback(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
||||||
match (self, other) {
|
Ok(Angle::from_radians(self.radians().animate(&other.radians(), procedure)?))
|
||||||
(&Angle::Degree(ref this), &Angle::Degree(ref other)) => {
|
|
||||||
Ok(Angle::Degree(this.animate(other, procedure)?))
|
|
||||||
},
|
|
||||||
(&Angle::Gradian(ref this), &Angle::Gradian(ref other)) => {
|
|
||||||
Ok(Angle::Gradian(this.animate(other, procedure)?))
|
|
||||||
},
|
|
||||||
(&Angle::Turn(ref this), &Angle::Turn(ref other)) => {
|
|
||||||
Ok(Angle::Turn(this.animate(other, procedure)?))
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
Ok(Angle::from_radians(self.radians().animate(&other.radians(), procedure)?))
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue