use iced_nodegraph_sdf::Pattern;
use iced_widget::core::{Color, Theme};
use super::defaults::default_node_style;
use super::roles::Roles;
use super::{ColorQuad, NodeStatus, ramp};
const PRESET_TINT: f32 = 0.18;
#[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(theme: &Theme, status: NodeStatus) -> Self {
Self::tinted(theme, status, theme.extended_palette().primary.base.color)
}
pub fn process(theme: &Theme, status: NodeStatus) -> Self {
Self::tinted(theme, status, theme.extended_palette().success.base.color)
}
pub fn output(theme: &Theme, status: NodeStatus) -> Self {
Self::tinted(theme, status, theme.extended_palette().warning.base.color)
}
pub fn comment(theme: &Theme, status: NodeStatus) -> Self {
let roles = Roles::of(theme);
let base = default_node_style(theme, status);
let border_pattern = match status {
NodeStatus::Idle => Pattern::dashed(1.0, 6.0, 4.0),
NodeStatus::Selected => Pattern::dashed(2.0, 6.0, 4.0),
};
Self {
fill_color: Color {
a: 0.6,
..roles.canvas
}
.into(),
border_pattern,
shadow_color: Color::TRANSPARENT,
shadow_distance: 0.0,
shadow_offset: (0.0, 0.0),
..base
}
}
fn tinted(theme: &Theme, status: NodeStatus, hue: Color) -> Self {
let roles = Roles::of(theme);
let hue = roles.legible(hue);
let base = default_node_style(theme, status);
let fill_color = ColorQuad::solid(ramp::blend(roles.body, hue, PRESET_TINT));
match status {
NodeStatus::Idle => Self {
fill_color,
border_color: hue.into(),
..base
},
NodeStatus::Selected => Self { fill_color, ..base },
}
}
}