use iced::{Color, Theme};
mod defaults;
mod edge;
mod node;
mod pin;
mod sdf;
pub use defaults::{default_edge_style, default_node_style, default_pin_style};
pub use edge::EdgeStyle;
pub use node::NodeStyle;
pub use pin::PinStyle;
pub use iced_nodegraph_sdf::ColorQuad;
pub(crate) use sdf::EdgeGeometry;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u32)]
pub enum PinShape {
#[default]
Circle = 0,
Square = 1,
Diamond = 2,
Triangle = 3,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum NodeStatus {
#[default]
Idle,
Selected,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum PinStatus {
#[default]
Idle,
ValidTarget,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum EdgeStatus {
#[default]
Idle,
PendingCut,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub enum EdgeCurve {
#[default]
BezierCubic,
Line,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TilingKind {
#[default]
Grid,
Dots,
Triangles,
Hex,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct TilingBackground {
pub kind: TilingKind,
pub spacing: f32,
pub thickness: f32,
pub color: Color,
}
impl TilingBackground {
pub fn grid(spacing: f32, thickness: f32, color: Color) -> Self {
Self {
kind: TilingKind::Grid,
spacing,
thickness,
color,
}
}
pub fn dots(spacing: f32, radius: f32, color: Color) -> Self {
Self {
kind: TilingKind::Dots,
spacing,
thickness: radius,
color,
}
}
pub fn triangles(spacing: f32, thickness: f32, color: Color) -> Self {
Self {
kind: TilingKind::Triangles,
spacing,
thickness,
color,
}
}
pub fn hex(spacing: f32, thickness: f32, color: Color) -> Self {
Self {
kind: TilingKind::Hex,
spacing,
thickness,
color,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GraphStyle {
pub background_color: Color,
pub tiling: Option<TilingBackground>,
pub selection_style: SelectionStyle,
}
impl Default for GraphStyle {
fn default() -> Self {
Self {
background_color: Color::from_rgb(0.08, 0.08, 0.09),
tiling: None,
selection_style: SelectionStyle::default(),
}
}
}
impl GraphStyle {
pub fn new() -> Self {
Self::default()
}
pub fn background_color(mut self, color: Color) -> Self {
self.background_color = color;
self
}
pub fn selection_style(mut self, style: SelectionStyle) -> Self {
self.selection_style = style;
self
}
pub fn tiling(mut self, tiling: TilingBackground) -> Self {
self.tiling = Some(tiling);
self
}
pub fn dark() -> Self {
Self::default()
}
pub fn light() -> Self {
Self {
background_color: Color::from_rgb(0.95, 0.95, 0.96),
tiling: None,
selection_style: SelectionStyle::default(),
}
}
pub fn from_theme(theme: &Theme) -> Self {
let palette = theme.extended_palette();
let grid = TilingBackground::grid(
40.0,
1.0,
Color {
a: 0.35,
..palette.background.strong.color
},
);
Self {
background_color: palette.background.base.color,
tiling: Some(grid),
selection_style: SelectionStyle::from_theme(theme),
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct SelectionStyle {
pub selected_border_color: Color,
pub selected_border_width: f32,
pub box_select_fill: Color,
pub box_select_border: Color,
pub edge_cutting_color: Color,
}
impl Default for SelectionStyle {
fn default() -> Self {
Self {
selected_border_color: Color::from_rgb(0.3, 0.6, 1.0),
selected_border_width: 2.5,
box_select_fill: Color::from_rgba(0.3, 0.6, 1.0, 0.15),
box_select_border: Color::from_rgba(0.3, 0.6, 1.0, 0.6),
edge_cutting_color: Color::from_rgb(1.0, 0.3, 0.3),
}
}
}
impl SelectionStyle {
pub fn new() -> Self {
Self::default()
}
pub fn selected_border_color(mut self, color: Color) -> Self {
self.selected_border_color = color;
self
}
pub fn selected_border_width(mut self, width: f32) -> Self {
self.selected_border_width = width;
self
}
pub fn box_select_fill(mut self, color: Color) -> Self {
self.box_select_fill = color;
self
}
pub fn box_select_border(mut self, color: Color) -> Self {
self.box_select_border = color;
self
}
pub fn from_theme(theme: &Theme) -> Self {
let palette = theme.extended_palette();
let primary = palette.primary.base.color;
Self {
selected_border_color: primary,
selected_border_width: 2.5,
box_select_fill: Color { a: 0.15, ..primary },
box_select_border: Color { a: 0.6, ..primary },
edge_cutting_color: palette.danger.base.color,
}
}
}