use super::*;
use crate::styles::{Gradient, Image};
use std::ops::AddAssign;
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct BackgroundStyle {
pub background_texture: Texture,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct CircleStyle {
pub circle_width: f32,
pub circle_texture: Texture,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct DiskStyle {
pub disk_fill_color: Color,
pub disk_edge_width: f32,
pub disk_edge_color: Color,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct EdgeColor {
pub disk_edge_color: Color,
pub triangle_edge_color: Color,
pub square_edge_color: Color,
pub rectangle_edge_color: Color,
pub polygon_edge_color: Color,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct EdgeStyle {
pub disk_edge_width: f32,
pub triangle_edge_color: Color,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct EdgeWidth {
pub disk_edge_width: f32,
pub triangle_edge_width: f32,
pub square_edge_width: f32,
pub rectangle_edge_width: f32,
pub polygon_edge_width: f32,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct FillColor {
pub disk_fill_color: Color,
pub triangle_fill_color: Color,
pub square_fill_color: Color,
pub rectangle_fill_color: Color,
pub polygon_fill_color: Color,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct LineStyle {
pub line_width: f32,
pub line_color: Color,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct PointStyle {
pub point_size: f32,
pub point_color: Color,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct PolygonStyle {
pub polygon_fill_color: Color,
pub polygon_edge_width: f32,
pub polygon_edge_color: Color,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct PolylineStyle {
pub polyline_width: f32,
pub polyline_color: Color,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct RectangleStyle {
pub fill_texture: Color,
pub edge_width: f32,
pub rectangle_edge_color: Color,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct SquareStyle {
pub square_fill_color: Color,
pub square_edge_width: f32,
pub square_edge_color: Color,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct TextStyle {
pub text_color: Color,
pub text_size: f32,
pub text_font: f32,
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub struct TriangleStyle {
pub triangle_fill_color: Color,
pub triangle_edge_width: f32,
pub triangle_edge_color: Color,
}
impl StyleContext {
pub fn resolve_background_style(&self, style: crate::BackgroundStyle) -> BackgroundStyle {
BackgroundStyle { background_texture: style.background_color.unwrap_or(self.background_color()).value }
}
pub fn resolve_circle_style(&self, style: crate::CircleStyle) -> CircleStyle {
CircleStyle {
circle_width: style.circle_width.unwrap_or(self.circle_width()).value,
circle_color: style.circle_texture.unwrap_or(self.circle_color()).value,
}
}
pub fn resolve_disk_style(&self, style: crate::DiskStyle) -> DiskStyle {
DiskStyle {
disk_fill_color: style.disk_fill_color.unwrap_or(self.disk_fill_color()).value,
disk_edge_width: style.disk_edge_width.unwrap_or(self.disk_edge_width()).value,
disk_edge_color: style.disk_edge_color.unwrap_or(self.disk_edge_color()).value,
}
}
pub fn resolve_edge_color(&self, style: crate::EdgeColor) -> EdgeColor {
EdgeColor {
disk_edge_color: style.disk_edge_color.unwrap_or(self.disk_edge_color()).value,
triangle_edge_color: style.triangle_edge_color.unwrap_or(self.triangle_edge_color()).value,
square_edge_color: style.square_edge_color.unwrap_or(self.square_edge_color()).value,
rectangle_edge_color: style.rectangle_edge_color.unwrap_or(self.rectangle_edge_color()).value,
polygon_edge_color: style.polygon_edge_color.unwrap_or(self.polygon_edge_color()).value,
}
}
pub fn resolve_edge_style(&self, style: crate::EdgeStyle) -> EdgeStyle {
EdgeStyle {
disk_edge_width: style.disk_edge_width.unwrap_or(self.disk_edge_width()).value,
triangle_edge_color: style.triangle_edge_color.unwrap_or(self.triangle_edge_color()).value,
}
}
pub fn resolve_edge_width(&self, style: crate::EdgeWidth) -> EdgeWidth {
EdgeWidth {
disk_edge_width: style.disk_edge_width.unwrap_or(self.disk_edge_width()).value,
triangle_edge_width: style.triangle_edge_width.unwrap_or(self.triangle_edge_width()).value,
square_edge_width: style.square_edge_width.unwrap_or(self.square_edge_width()).value,
rectangle_edge_width: style.rectangle_edge_width.unwrap_or(self.rectangle_edge_width()).value,
polygon_edge_width: style.polygon_edge_width.unwrap_or(self.polygon_edge_width()).value,
}
}
pub fn resolve_fill_color(&self, style: crate::FillColor) -> FillColor {
FillColor {
disk_fill_color: style.disk_fill_color.unwrap_or(self.disk_fill_color()).value,
triangle_fill_color: style.triangle_fill_color.unwrap_or(self.triangle_fill_color()).value,
square_fill_color: style.square_fill_color.unwrap_or(self.square_fill_color()).value,
rectangle_fill_color: style.rectangle_fill_color.unwrap_or(self.rectangle_fill_color()).value,
polygon_fill_color: style.polygon_fill_color.unwrap_or(self.polygon_fill_color()).value,
}
}
pub fn resolve_line_style(&self, style: crate::LineStyle) -> LineStyle {
LineStyle {
line_width: style.line_width.unwrap_or(self.line_width()).value,
line_color: style.line_color.unwrap_or(self.line_color()).value,
}
}
pub fn resolve_point_style(&self, style: crate::PointStyle) -> PointStyle {
PointStyle {
point_size: style.point_size.unwrap_or(self.point_size()).value,
point_color: style.point_color.unwrap_or(self.point_color()).value,
}
}
pub fn resolve_polygon_style(&self, style: crate::PolygonStyle) -> PolygonStyle {
PolygonStyle {
polygon_fill_color: style.polygon_fill_color.unwrap_or(self.polygon_fill_color()).value,
polygon_edge_width: style.polygon_edge_width.unwrap_or(self.polygon_edge_width()).value,
polygon_edge_color: style.polygon_edge_color.unwrap_or(self.polygon_edge_color()).value,
}
}
pub fn resolve_polyline_style(&self, style: crate::PolylineStyle) -> PolylineStyle {
PolylineStyle {
polyline_width: style.polyline_width.unwrap_or(self.polyline_width()).value,
polyline_color: style.polyline_color.unwrap_or(self.polyline_color()).value,
}
}
pub fn resolve_rectangle_style(&self, style: crate::RectangleStyle) -> RectangleStyle {
RectangleStyle {
fill_texture: style.rectangle_fill_color.unwrap_or(self.rectangle_fill_color()).value,
edge_width: style.rectangle_edge_width.unwrap_or(self.rectangle_edge_width()).value,
rectangle_edge_color: style.rectangle_edge_color.unwrap_or(self.rectangle_edge_color()).value,
}
}
pub fn resolve_square_style(&self, style: crate::SquareStyle) -> SquareStyle {
SquareStyle {
square_fill_color: style.square_fill_color.unwrap_or(self.square_fill_color()).value,
square_edge_width: style.square_edge_width.unwrap_or(self.square_edge_width()).value,
square_edge_color: style.square_edge_color.unwrap_or(self.square_edge_color()).value,
}
}
pub fn resolve_text_style(&self, style: crate::TextStyle) -> TextStyle {
TextStyle {
text_color: style.text_color.unwrap_or(self.text_color()).value,
text_size: style.text_size.unwrap_or(self.text_size()).value,
text_font: style.text_font.unwrap_or(self.text_font()).value,
}
}
pub fn resolve_triangle_style(&self, style: crate::TriangleStyle) -> TriangleStyle {
TriangleStyle {
triangle_fill_color: style.triangle_fill_color.unwrap_or(self.triangle_fill_color()).value,
triangle_edge_width: style.triangle_edge_width.unwrap_or(self.triangle_edge_width()).value,
triangle_edge_color: style.triangle_edge_color.unwrap_or(self.triangle_edge_color()).value,
}
}
}