use std::fmt;
use std::fmt::{Debug, Display};
pub struct Options<O, A> {
pub orientation: Orientation,
pub theme: Theme,
pub node_label: Box<dyn Fn(&O) -> String>,
pub edge_label: Box<dyn Fn(&A) -> String>,
}
impl<O: Debug, A: Debug> Default for Options<O, A> {
fn default() -> Self {
Self {
orientation: Default::default(),
theme: Default::default(),
node_label: Box::new(|n| format!("{:?}", n)),
edge_label: Box::new(|e| format!("{:?}", e)),
}
}
}
impl<O: Display, A: Display> Options<O, A> {
pub fn display(mut self) -> Self {
self.node_label = Box::new(|n| format!("{}", n));
self.edge_label = Box::new(|e| format!("{}", e));
self
}
}
impl<O, A> Options<O, A> {
pub fn lr(mut self) -> Self {
self.orientation = Orientation::LR;
self
}
pub fn tb(mut self) -> Self {
self.orientation = Orientation::TB;
self
}
}
#[derive(Debug, Clone, Copy, Default)]
pub enum Orientation {
LR,
#[default]
TB,
}
impl fmt::Display for Orientation {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Orientation::LR => write!(f, "LR"),
Orientation::TB => write!(f, "TB"),
}
}
}
pub struct Theme {
pub bgcolor: String,
pub fontcolor: String,
pub color: String,
pub orientation: Orientation,
}
pub fn light_theme() -> Theme {
Theme {
bgcolor: String::from("white"),
fontcolor: String::from("black"),
color: String::from("black"),
orientation: Orientation::LR,
}
}
pub fn dark_theme() -> Theme {
Theme {
bgcolor: String::from("#4a4a4a"),
fontcolor: String::from("white"),
color: String::from("white"),
orientation: Orientation::LR,
}
}
impl Default for Theme {
fn default() -> Self {
dark_theme()
}
}