1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//! Chart-level format and title types.
use crate::dml::fill::FillFormat;
use crate::dml::line::LineFormat;
use crate::text::TextFrame;
/// Chart-level format (fill + line for the chart area).
#[derive(Debug, Clone)]
pub struct ChartFormat {
/// Fill for the chart area.
pub fill: Option<FillFormat>,
/// Line (border) for the chart area.
pub line: Option<LineFormat>,
}
impl ChartFormat {
/// Create an empty format (inherited).
#[must_use]
pub const fn new() -> Self {
Self {
fill: None,
line: None,
}
}
}
/// Creates an empty chart format with no fill or line.
impl Default for ChartFormat {
fn default() -> Self {
Self::new()
}
}
/// Represents the title of a chart, with optional rich text and formatting.
#[derive(Debug, Clone)]
pub struct ChartTitle {
/// Rich text content for the chart title.
pub text_frame: Option<TextFrame>,
/// Whether the title has a text frame.
has_text_frame: bool,
/// Visual formatting (fill + line) for the title area.
pub format: Option<ChartFormat>,
}
impl ChartTitle {
/// Create a new empty chart title.
#[must_use]
pub const fn new() -> Self {
Self {
text_frame: None,
has_text_frame: false,
format: None,
}
}
/// Create a chart title from a plain text string.
#[must_use]
pub fn from_text(text: &str) -> Self {
let mut tf = TextFrame::new();
tf.set_text(text);
Self {
text_frame: Some(tf),
has_text_frame: true,
format: None,
}
}
/// Whether the title has a text frame.
#[must_use]
pub const fn has_text_frame(&self) -> bool {
self.has_text_frame
}
/// Get the text frame, if present.
#[must_use]
pub const fn text_frame(&self) -> Option<&TextFrame> {
self.text_frame.as_ref()
}
/// Get or create a mutable text frame.
pub fn text_frame_mut(&mut self) -> &mut TextFrame {
self.has_text_frame = true;
self.text_frame.get_or_insert_with(TextFrame::new)
}
/// Set the text frame.
pub fn set_text_frame(&mut self, tf: TextFrame) {
self.has_text_frame = true;
self.text_frame = Some(tf);
}
/// Get the plain text of the title, if a text frame is present.
#[must_use]
pub fn text(&self) -> Option<String> {
self.text_frame.as_ref().map(TextFrame::text)
}
}
/// Creates an empty chart title with no text content.
impl Default for ChartTitle {
fn default() -> Self {
Self::new()
}
}