diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2017-08-10 10:54:56 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2017-08-11 10:25:03 +0200 |
commit | c4e33d9dca12a0434bdeed4fe9844226093e5ce0 (patch) | |
tree | 531888d4f7c5c16050745969cc524aa169293e28 /components/style/values/generics/border.rs | |
parent | 56f5fc41fae732ba28f63acec6755559da31d47f (diff) | |
download | servo-c4e33d9dca12a0434bdeed4fe9844226093e5ce0.tar.gz servo-c4e33d9dca12a0434bdeed4fe9844226093e5ce0.zip |
Animate basic shapes
Diffstat (limited to 'components/style/values/generics/border.rs')
-rw-r--r-- | components/style/values/generics/border.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/components/style/values/generics/border.rs b/components/style/values/generics/border.rs index 5d8c9032e6a..e70504e7e87 100644 --- a/components/style/values/generics/border.rs +++ b/components/style/values/generics/border.rs @@ -5,6 +5,7 @@ //! Generic types for CSS values related to borders. use euclid::Size2D; +use properties::animated_properties::Animatable; use std::fmt; use style_traits::ToCss; use values::generics::rect::Rect; @@ -112,6 +113,37 @@ impl<L> BorderRadius<L> } } +impl<L> Animatable for BorderRadius<L> +where + L: Animatable + Copy, +{ + fn add_weighted( + &self, + other: &Self, + self_portion: f64, + other_portion: f64, + ) -> Result<Self, ()> { + let tl = self.top_left.add_weighted(&other.top_left, self_portion, other_portion)?; + let tr = self.top_right.add_weighted(&other.top_right, self_portion, other_portion)?; + let br = self.bottom_right.add_weighted(&other.bottom_right, self_portion, other_portion)?; + let bl = self.bottom_left.add_weighted(&other.bottom_left, self_portion, other_portion)?; + Ok(BorderRadius::new(tl, tr, br, bl)) + } + + fn compute_distance(&self, other: &Self) -> Result<f64, ()> { + Ok(self.compute_squared_distance(other)?.sqrt()) + } + + fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> { + Ok( + self.top_left.compute_squared_distance(&other.top_left)? + + self.top_right.compute_squared_distance(&other.top_right)? + + self.bottom_right.compute_squared_distance(&other.bottom_right)? + + self.bottom_left.compute_squared_distance(&other.bottom_left)?, + ) + } +} + impl<L> ToCss for BorderRadius<L> where L: PartialEq + ToCss { @@ -144,6 +176,31 @@ impl<L: Clone> From<L> for BorderCornerRadius<L> { } } +impl<L> Animatable for BorderCornerRadius<L> +where + L: Animatable + Copy, +{ + #[inline] + fn add_weighted( + &self, + other: &Self, + self_portion: f64, + other_portion: f64, + ) -> Result<Self, ()> { + Ok(BorderCornerRadius(self.0.add_weighted(&other.0, self_portion, other_portion)?)) + } + + #[inline] + fn compute_distance(&self, other: &Self) -> Result<f64, ()> { + self.0.compute_distance(&other.0) + } + + #[inline] + fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> { + self.0.compute_squared_distance(&other.0) + } +} + impl<L> ToCss for BorderCornerRadius<L> where L: ToCss, { |