mod grid_process;
mod render_grid;
mod render_node;
mod svg;
use std::fmt::Debug;
pub use svg::{render_to_svg, render_to_svg_file};
use triple_arena::{Link, Ptr};
pub mod internal {
pub use crate::{
grid_process::{grid_process, ANode},
render_grid::RenderGrid,
render_node::RenderNode,
};
}
pub(crate) const PAD: i32 = 128;
pub(crate) const FONT_WX: i32 = 256;
pub(crate) const FONT_WY: i32 = 512;
pub(crate) const FONT_FAMILY: &str = "monospace";
pub(crate) const FONT_SIZE: i32 = 512 - 48;
pub(crate) const FONT_ADJUST_Y: i32 = -192;
pub(crate) const INPUT_PAD: i32 = 0;
pub(crate) const INPUT_FONT_WX: i32 = 128;
pub(crate) const INPUT_FONT_WY: i32 = 256;
pub(crate) const INPUT_FONT_SIZE: i32 = 256 - 24;
pub(crate) const INPUT_FONT_ADJUST_Y: i32 = -48;
pub(crate) const RELATION_WIDTH: i32 = 48;
pub(crate) const NODE_PAD: i32 = 1024;
pub(crate) const COLORS: [&str; 7] = [
"a0a0a0", "00b2ff", "00cb9d", "c49d00", "ff8080", "ff2adc", "a35bff",
];
pub(crate) const NODE_FILL: &str = "171717";
pub(crate) const TEXT_COLOR: &str = "a0a0a0";
#[derive(Debug, Hash, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct DebugNode<P: Ptr> {
pub sources: Vec<(P, String)>,
pub center: Vec<String>,
pub sinks: Vec<(P, String)>,
}
impl<P: Ptr> Default for DebugNode<P> {
fn default() -> Self {
Self {
sources: vec![],
center: vec![],
sinks: vec![],
}
}
}
impl<P: Ptr> DebugNode<P> {
pub fn new(sources: Vec<(P, String)>, center: Vec<String>, sinks: Vec<(P, String)>) -> Self {
Self {
sources,
center,
sinks,
}
}
}
pub trait DebugNodeTrait<P: Ptr> {
fn debug_node(p_this: P, this: &Self) -> DebugNode<P>;
}
impl<P: Ptr> DebugNodeTrait<P> for DebugNode<P> {
fn debug_node(_p_this: P, this: &Self) -> DebugNode<P> {
this.clone()
}
}
impl<P: Ptr, T: Debug> DebugNodeTrait<P> for Link<P, T> {
fn debug_node(_p_this: P, this: &Self) -> DebugNode<P> {
DebugNode {
sources: if let Some(prev) = Link::prev(this) {
vec![(prev, String::new())]
} else {
vec![]
},
center: format!("{:?}", this.t)
.lines()
.map(|l| l.to_owned())
.collect(),
sinks: if let Some(next) = Link::prev(this) {
vec![(next, String::new())]
} else {
vec![]
},
}
}
}
#[derive(Debug)]
#[non_exhaustive]
pub enum RenderError<P: Ptr> {
InvalidPtr(P),
IoError(std::io::Error),
}