use crate::dml::fill::FillFormat;
use crate::dml::line::LineFormat;
use crate::enums::chart::XlMarkerStyle;
#[derive(Debug, Clone)]
pub struct MarkerFormat {
pub fill: Option<FillFormat>,
pub line: Option<LineFormat>,
}
impl MarkerFormat {
#[must_use]
pub const fn new() -> Self {
Self {
fill: None,
line: None,
}
}
}
impl Default for MarkerFormat {
fn default() -> Self {
Self::new()
}
}
#[derive(Debug, Clone)]
pub struct Marker {
style: XlMarkerStyle,
size: Option<u32>,
format: Option<MarkerFormat>,
}
impl Marker {
#[must_use]
pub const fn new(style: XlMarkerStyle) -> Self {
Self {
style,
size: None,
format: None,
}
}
#[must_use]
pub const fn with_size(style: XlMarkerStyle, size: u32) -> Self {
Self {
style,
size: Some(size),
format: None,
}
}
#[must_use]
pub const fn style(&self) -> XlMarkerStyle {
self.style
}
pub fn set_style(&mut self, style: XlMarkerStyle) {
self.style = style;
}
#[must_use]
pub const fn size(&self) -> Option<u32> {
self.size
}
pub fn set_size(&mut self, size: Option<u32>) {
self.size = size;
}
#[must_use]
pub const fn format(&self) -> Option<&MarkerFormat> {
self.format.as_ref()
}
pub fn format_mut(&mut self) -> &mut MarkerFormat {
self.format.get_or_insert_with(MarkerFormat::new)
}
pub fn set_format(&mut self, format: MarkerFormat) {
self.format = Some(format);
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::dml::color::ColorFormat;
#[test]
fn test_marker_format() {
let mut marker = Marker::new(XlMarkerStyle::Circle);
assert!(marker.format().is_none());
let fmt = marker.format_mut();
fmt.fill = Some(FillFormat::solid(ColorFormat::rgb(255, 0, 0)));
assert!(marker.format().is_some());
}
#[test]
fn test_marker_with_line_format() {
let mut marker = Marker::with_size(XlMarkerStyle::Diamond, 8);
let fmt = marker.format_mut();
fmt.line = Some(LineFormat {
color: Some(ColorFormat::rgb(0, 0, 0)),
width: Some(crate::units::Emu(12700)),
..LineFormat::default()
});
assert!(marker.format().unwrap().line.is_some());
}
}