rust_texas/component/
beamer.rs

1use crate::prelude::*;
2
3#[derive(Debug, Clone)]
4pub struct Block {
5    title: String,
6    components: Vec<Component>,
7}
8
9impl AsLatex for Block {
10    fn to_string(&self) -> String {
11        let comps = self
12            .components
13            .iter()
14            .map(|s| s.to_string())
15            .collect::<String>();
16        format!(
17            "\\begin{{block}}{{{}}} \n {} \\end{{block}} \n ",
18            self.title, comps
19        )
20    }
21}
22
23impl Populate for Block {
24    fn attach(&mut self, other: Component) -> TexResult<&mut Self> {
25        self.components.push(other);
26        Ok(self)
27    }
28    fn attach_vec(&mut self, mut other: Vec<Component>) -> TexResult<&mut Self> {
29        self.components.append(&mut other);
30        Ok(self)
31    }
32
33    fn attach_iter<I: Iterator<Item = Component>>(&mut self, other: I) -> TexResult<&mut Self> {
34        // todo!()
35        self.components.extend(other);
36        Ok(self)
37    }
38}
39
40impl Block {
41    pub fn new(title: &str) -> Self {
42        Self {
43            title: title.to_string(),
44            components: vec![],
45        }
46    }
47
48    pub fn new_untitled() -> Self {
49        Self::new("")
50    }
51
52    pub fn untitled_with_components(components: Vec<Component>) -> Self {
53        Self::with_components("", components)
54    }
55
56    pub fn with_components(title: &str, components: Vec<Component>) -> Self {
57        Self {
58            title: title.to_string(),
59            components,
60        }
61    }
62}
63
64#[derive(Debug, Clone)]
65pub struct Frame {
66    title: String,
67    components: Vec<Component>,
68}
69
70impl AsLatex for Frame {
71    fn to_string(&self) -> String {
72        let comps = self
73            .components
74            .iter()
75            .map(|s| s.to_string())
76            .collect::<String>();
77        format!(
78            "\\begin{{frame}}{{{}}} \n {} \\end{{frame}} \n ",
79            self.title, comps
80        )
81    }
82}
83
84impl Populate for Frame {
85    fn attach(&mut self, other: Component) -> TexResult<&mut Self> {
86        self.components.push(other);
87        Ok(self)
88    }
89    fn attach_vec(&mut self, mut other: Vec<Component>) -> TexResult<&mut Self> {
90        self.components.append(&mut other);
91        Ok(self)
92    }
93
94    fn attach_iter<I: Iterator<Item = Component>>(&mut self, other: I) -> TexResult<&mut Self> {
95        self.components.extend(other);
96        Ok(self)
97    }
98}
99
100impl Frame {
101    pub fn new(title: &str) -> Self {
102        Self {
103            title: title.to_string(),
104            components: vec![],
105        }
106    }
107
108    pub fn new_untitled() -> Self {
109        Self::new("")
110    }
111
112    pub fn untitled_with_components(components: Vec<Component>) -> Self {
113        Self::with_components("", components)
114    }
115
116    pub fn with_components(title: &str, components: Vec<Component>) -> Self {
117        Self {
118            title: title.to_string(),
119            components,
120        }
121    }
122}