use iced::Color;
use iced_nodegraph_sdf::Pattern;
use super::ColorQuad;
#[derive(Debug, Clone, PartialEq)]
pub struct NodeStyle {
pub fill_color: ColorQuad,
pub corner_radius: f32,
pub opacity: f32,
pub border_color: ColorQuad,
pub border_pattern: Pattern,
pub border_outline_width: f32,
pub border_outline_color: ColorQuad,
pub shadow_color: Color,
pub shadow_distance: f32,
pub shadow_offset: (f32, f32),
}
impl NodeStyle {
pub fn input() -> Self {
Self::preset(
Color::from_rgb(0.15, 0.20, 0.30),
Color::from_rgb(0.30, 0.45, 0.70),
1.5,
6.0,
0.85,
Color::from_rgba(0.0, 0.0, 0.0, 0.3),
8.0,
(4.0, 4.0),
)
}
pub fn process() -> Self {
Self::preset(
Color::from_rgb(0.18, 0.28, 0.18),
Color::from_rgb(0.35, 0.60, 0.35),
1.5,
4.0,
0.80,
Color::from_rgba(0.0, 0.0, 0.0, 0.3),
8.0,
(4.0, 4.0),
)
}
pub fn output() -> Self {
Self::preset(
Color::from_rgb(0.30, 0.22, 0.15),
Color::from_rgb(0.75, 0.55, 0.30),
2.0,
8.0,
0.85,
Color::from_rgba(0.0, 0.0, 0.0, 0.4),
16.0,
(6.0, 8.0),
)
}
pub fn comment() -> Self {
Self::preset(
Color::from_rgba(0.20, 0.20, 0.22, 0.5),
Color::from_rgba(0.40, 0.40, 0.44, 0.5),
1.0,
3.0,
0.60,
Color::TRANSPARENT,
0.0,
(0.0, 0.0),
)
}
#[allow(clippy::too_many_arguments)]
fn preset(
fill: Color,
border: Color,
border_width: f32,
corner_radius: f32,
opacity: f32,
shadow: Color,
shadow_distance: f32,
shadow_offset: (f32, f32),
) -> Self {
Self {
fill_color: ColorQuad::solid(fill),
corner_radius,
opacity,
border_color: ColorQuad::solid(border),
border_pattern: Pattern::solid(border_width),
border_outline_width: 0.0,
border_outline_color: ColorQuad::solid(Color::TRANSPARENT),
shadow_color: shadow,
shadow_distance,
shadow_offset,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn struct_update_overrides_over_default() {
use crate::style::{NodeStatus, default_node_style};
let base = default_node_style(&iced::Theme::Dark, NodeStatus::Idle);
let style = NodeStyle {
fill_color: Color::WHITE.into(),
opacity: 1.0,
..base
};
assert_eq!(style.fill_color, ColorQuad::solid(Color::WHITE)); assert_eq!(style.opacity, 1.0); assert_eq!(style.corner_radius, 5.0); assert_eq!(style.border_pattern, Pattern::solid(1.0)); }
}