Skip to main content

sequoia_style/
avatar_style.rs

1use sequoia_core::Color;
2
3#[derive(Clone, Copy, Debug, Default, PartialEq)]
4pub struct AvatarStyle {
5    pub background: Option<Color>,
6    pub text: Option<Color>,
7    pub font_size: Option<f32>,
8    pub radius: Option<f32>,
9}
10
11impl AvatarStyle {
12    pub const fn new() -> Self {
13        Self {
14            background: None,
15            text: None,
16            font_size: None,
17            radius: None,
18        }
19    }
20
21    pub const fn background(mut self, color: Color) -> Self {
22        self.background = Some(color);
23        self
24    }
25
26    pub const fn text(mut self, color: Color) -> Self {
27        self.text = Some(color);
28        self
29    }
30
31    pub const fn font_size(mut self, size: f32) -> Self {
32        self.font_size = Some(size);
33        self
34    }
35
36    pub const fn radius(mut self, radius: f32) -> Self {
37        self.radius = Some(radius);
38        self
39    }
40}
41
42#[cfg(test)]
43mod tests {
44    use super::*;
45
46    #[test]
47    fn const_composition_keeps_base() {
48        const CUSTOM: AvatarStyle = AvatarStyle::new().font_size(13.0);
49        assert_eq!(CUSTOM.font_size, Some(13.0));
50        assert_eq!(CUSTOM.radius, None);
51    }
52}