use super::mode::Mode;
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct Context<Num, Color> {
pub fill: Color,
pub stroke: Color,
pub weight: Num,
pub rectangle_mode: Mode,
pub ellipse_mode: Mode,
pub rotation: Num,
}
impl<Num, Color> Default for Context<Num, Color>
where
Num: Default,
Color: Default,
{
#[inline]
fn default() -> Self {
Self {
ellipse_mode: Mode::Corner,
rectangle_mode: Mode::Corner,
fill: Color::default(),
stroke: Color::default(),
weight: Num::default(),
rotation: Num::default(),
}
}
}
pub trait FromWithContext<T, Num, Color> {
fn from_with_context(value: T, context: &Context<Num, Color>) -> Self;
}
pub trait IntoWithContext<T, Num, Color> {
fn into_with_context(self, context: &Context<Num, Color>) -> T;
}
impl<T, U, Num, Color> FromWithContext<U, Num, Color> for T
where
T: From<U>,
{
#[inline]
fn from_with_context(value: U, _context: &Context<Num, Color>) -> T {
value.into()
}
}
impl<T, U, Num, Color> IntoWithContext<U, Num, Color> for T
where
U: FromWithContext<T, Num, Color>,
{
#[inline]
fn into_with_context(self, context: &Context<Num, Color>) -> U {
U::from_with_context(self, context)
}
}