summaryrefslogblamecommitdiffstats
path: root/graphics/src/gradient.rs
blob: 1446d7cf7ef6ef37993930b2efe3358f4cabc02c (plain) (tree)
1
2
3
4
5
6
7
8
9
                            

           

                                                              

                                  

                                                                                                     





                                                                                                 






                                                                               



                                                 

                                                                     
     
 


                                                                                  


         
//! For creating a Gradient.
mod linear;

pub use crate::gradient::linear::{Linear, Location, Position};
use crate::{Color, Point};

#[derive(Debug, Clone, PartialEq)]
/// A fill which transitions colors progressively along a direction, either linearly, radially (TBD),
/// or conically (TBD).
pub enum Gradient {
    /// A linear gradient interpolates colors along a direction from its [`start`] to its [`end`]
    /// point.
    Linear(Linear),
}

#[derive(Debug, Clone, Copy, PartialEq)]
/// A point along the gradient vector where the specified [`color`] is unmixed.
pub struct ColorStop {
    /// Offset along the gradient vector.
    pub offset: f32,
    /// The color of the gradient at the specified [`offset`].
    pub color: Color,
}

impl Gradient {
    /// Creates a new linear [`linear::Builder`].
    pub fn linear(position: impl Into<Position>) -> linear::Builder {
        linear::Builder::new(position.into())
    }

    pub(crate) fn coords(&mut self) -> (&mut Point, &mut Point) {
        match self {
            Gradient::Linear(gradient) => (&mut gradient.start, &mut gradient.end)
        }
    }
}