A node's color now flows down the lines to its children, mind-map style: Watering's teal colors the lines to Rain barrel and Drip line. It used to color the line from the root down to Watering itself, which also left the shared bus of a parent's branches in whichever child's color was drawn last. Branches follow their parent by default, and stay dim when the parent has no color. Co-Authored-By: Claude Opus 5.5 <[email protected]>
91 lines
2.6 KiB
Rust
91 lines
2.6 KiB
Rust
//! How nodes and lines are drawn: borders, line kinds, arrowheads, colors.
|
|
//!
|
|
//! Each field of [`NodeLook`] and [`LineLook`] is an override, and `None`
|
|
//! means "whatever the theme says". The theme works a look out in layers: its
|
|
//! default, then a style set by one of the node's tags, then a named style,
|
|
//! then these fields. Each layer only states what it changes.
|
|
//!
|
|
//! The plain enums here derive serde, so document files can name them
|
|
//! directly (`border: Dashed`).
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use super::text::{ColorName, StyleName};
|
|
|
|
/// The border around a node's box.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
pub enum Border {
|
|
Rounded,
|
|
Square,
|
|
Double,
|
|
Thick,
|
|
Dashed,
|
|
/// No border: just the text.
|
|
Hidden,
|
|
}
|
|
|
|
/// What a line looks like along its length.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
pub enum Stroke {
|
|
Solid,
|
|
Dashed,
|
|
Dotted,
|
|
Thick,
|
|
Double,
|
|
}
|
|
|
|
/// Which ends of a line have an arrowhead. The end is where a cross-link
|
|
/// points to; for a branch it's the child.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
|
pub enum Arrows {
|
|
Off,
|
|
End,
|
|
Start,
|
|
Both,
|
|
}
|
|
|
|
/// The color of a line.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub enum LineColor {
|
|
/// A color from the theme's palette.
|
|
Named(ColorName),
|
|
/// The color of the node the line comes from: a branch takes its
|
|
/// parent's (so a node's color flows down the lines to its children,
|
|
/// mind-map style), a cross-link its start's.
|
|
FollowNode,
|
|
}
|
|
|
|
/// How a node is drawn, on top of what the theme says.
|
|
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
|
|
pub struct NodeLook {
|
|
pub color: Option<ColorName>,
|
|
pub border: Option<Border>,
|
|
/// A named style from the theme, which can set the color and border.
|
|
pub style: Option<StyleName>,
|
|
}
|
|
|
|
impl NodeLook {
|
|
/// True when nothing is overridden: the node looks the way the theme says.
|
|
pub fn is_default(&self) -> bool {
|
|
*self == NodeLook::default()
|
|
}
|
|
}
|
|
|
|
/// How a line is drawn (a branch or a cross-link), on top of what the theme
|
|
/// says.
|
|
#[derive(Debug, Clone, Default, PartialEq, Eq, Hash)]
|
|
pub struct LineLook {
|
|
pub arrows: Option<Arrows>,
|
|
pub line: Option<Stroke>,
|
|
pub color: Option<LineColor>,
|
|
/// A named style from the theme, which can set all of the above.
|
|
pub style: Option<StyleName>,
|
|
}
|
|
|
|
impl LineLook {
|
|
/// True when nothing is overridden: the line looks the way the theme says.
|
|
pub fn is_default(&self) -> bool {
|
|
*self == LineLook::default()
|
|
}
|
|
}
|