improved color gradient api
@@ -12,9 +12,20 @@ pub struct GradientPoint {
}
impl GradientPoint {
+ #[inline]
pub fn new(location: f32, color: Color) -> Self {
Self { location, color }
}
+
+ #[inline]
+ pub fn color(&self) -> Color {
+ self.color
+ }
+
+ #[inline]
+ pub fn location(&self) -> f32 {
+ self.location
+ }
}
impl Default for GradientPoint {
@@ -55,6 +66,8 @@ impl Default for ColorGradient {
}
impl ColorGradient {
+ pub const STUB_COLOR: Color = Color::WHITE;
+
pub fn new() -> Self {
Self { points: Vec::new() }
}
@@ -70,8 +83,7 @@ impl ColorGradient {
pub fn get_color(&self, location: f32) -> Color {
if self.points.is_empty() {
- // stub - opaque white
- return Color::WHITE;
+ return Self::STUB_COLOR;
} else if self.points.len() == 1 {
// single point - just return its color
return self.points.first().unwrap().color;
@@ -119,6 +131,10 @@ impl ColorGradient {
}
}
+ pub fn points(&self) -> &[GradientPoint] {
+ &self.points
+ }
+
pub fn clear(&mut self) {
self.points.clear()
}
