eg_seven_segment/
seven_segment_style_builder.rs

1use crate::SevenSegmentStyle;
2use embedded_graphics::prelude::*;
3
4/// Seven-segment character style builder.
5#[derive(Debug)]
6pub struct SevenSegmentStyleBuilder<C> {
7    style: SevenSegmentStyle<C>,
8}
9
10impl<C: PixelColor> SevenSegmentStyleBuilder<C> {
11    /// Creates a new builder.
12    pub fn new() -> Self {
13        // TODO: set better default values
14        // TODO: add default values to docs
15        Self {
16            style: SevenSegmentStyle {
17                digit_size: Size::new(12, 24),
18                digit_spacing: 5,
19                segment_width: 3,
20                segment_color: None,
21                inactive_segment_color: None,
22            },
23        }
24    }
25
26    /// Sets the digit size.
27    pub fn digit_size(mut self, digit_size: Size) -> Self {
28        self.style.digit_size = digit_size;
29
30        self
31    }
32
33    /// Sets the digit spacing.
34    pub fn digit_spacing(mut self, digit_spacing: u32) -> Self {
35        self.style.digit_spacing = digit_spacing;
36
37        self
38    }
39
40    /// Sets the segment width.
41    pub fn segment_width(mut self, segment_width: u32) -> Self {
42        self.style.segment_width = segment_width;
43
44        self
45    }
46
47    /// Sets the segment color.
48    pub fn segment_color(mut self, segment_color: C) -> Self {
49        self.style.segment_color = Some(segment_color);
50
51        self
52    }
53
54    /// Resets the segment color to transparent.
55    pub fn reset_segment_color(mut self) -> Self {
56        self.style.segment_color = None;
57
58        self
59    }
60
61    /// Sets the inactive segment color.
62    pub fn inactive_segment_color(mut self, inactive_segment_color: C) -> Self {
63        self.style.inactive_segment_color = Some(inactive_segment_color);
64
65        self
66    }
67
68    /// Resets the inactive segment color to transparent.
69    pub fn reset_inactive_segment_color(mut self) -> Self {
70        self.style.inactive_segment_color = None;
71
72        self
73    }
74
75    /// Builds the text style.
76    pub fn build(self) -> SevenSegmentStyle<C> {
77        self.style
78    }
79}
80
81impl<C: PixelColor> Default for SevenSegmentStyleBuilder<C> {
82    fn default() -> Self {
83        Self::new()
84    }
85}
86
87impl<C: PixelColor> From<&SevenSegmentStyle<C>> for SevenSegmentStyleBuilder<C> {
88    fn from(style: &SevenSegmentStyle<C>) -> Self {
89        Self { style: *style }
90    }
91}