use abstracttui::base::Rgba;
use abstracttui::theme::TokenSet;
use crate::layout::{ForceOpts, LayeredOpts};
#[derive(Clone, Debug, PartialEq)]
pub struct GraphStyle {
pub card_bg: Rgba,
pub card_border: Rgba,
pub card_border_selected: Rgba,
pub card_title: Rgba,
pub badge: Rgba,
pub edge: Rgba,
pub edge_broken: Rgba,
pub edge_label: Rgba,
pub notice: Rgba,
pub kind_accents: Vec<(String, Rgba)>,
}
impl GraphStyle {
pub fn from_tokens(t: &TokenSet) -> GraphStyle {
GraphStyle {
card_bg: t.surface_raised,
card_border: t.border,
card_border_selected: t.border_focus,
card_title: t.text,
badge: t.info,
edge: t.text_muted,
edge_broken: t.error,
edge_label: t.text_faint,
notice: t.warn,
kind_accents: Vec::new(),
}
}
pub fn kind_accent(mut self, kind: impl Into<String>, ink: Rgba) -> GraphStyle {
self.kind_accents.push((kind.into(), ink));
self
}
pub(crate) fn accent_of(&self, kind: Option<&str>) -> Option<Rgba> {
let kind = kind?;
self.kind_accents
.iter()
.find(|(k, _)| k == kind)
.map(|(_, ink)| *ink)
}
}
impl Default for GraphStyle {
fn default() -> Self {
GraphStyle::from_tokens(&abstracttui::theme::default_theme().tokens)
}
}
#[non_exhaustive]
#[derive(Clone, Debug, PartialEq)]
pub enum GraphAlgo {
Layered(LayeredOpts),
Force(ForceOpts),
Grid,
}
impl Default for GraphAlgo {
fn default() -> Self {
GraphAlgo::Layered(LayeredOpts::default())
}
}