use std::fmt;
use crate::{Color, NodeShape, NodeStyle};
#[derive(Debug, Clone, PartialEq)]
pub struct NodeAttributes {
pub label: Option<String>,
pub color: Option<Color>,
pub style: Option<NodeStyle>,
pub shape: Option<NodeShape>,
}
impl NodeAttributes {
pub fn new(
label: Option<String>,
color: Option<Color>,
style: Option<NodeStyle>,
shape: Option<NodeShape>,
) -> Self {
Self { label, color, style, shape }
}
pub fn attributes(&self) -> Option<String> {
crate::details::encode::encode_attributes(&[
("label", self.label.as_ref().map(|s| s as &dyn ToString)),
("color", self.color.as_ref().map(|c| c as &dyn ToString)),
("style", self.style.as_ref().map(|s| s as &dyn ToString)),
("shape", self.shape.as_ref().map(|s| s as &dyn ToString)),
], true)
}
}
impl Default for NodeAttributes {
fn default() -> Self {
Self::new(None, None, None, None)
}
}
impl fmt::Display for NodeAttributes {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(encoded) = self.attributes() {
write!(f, "{}", encoded)
} else {
Ok(())
}
}
}