rlvgl_core/
style.rs

1/// Visual appearance attributes applied to widgets.
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub struct Style {
4    pub bg_color: crate::widget::Color,
5    pub border_color: crate::widget::Color,
6    pub border_width: u8,
7}
8
9impl Default for Style {
10    fn default() -> Self {
11        Self {
12            bg_color: crate::widget::Color(255, 255, 255),
13            border_color: crate::widget::Color(0, 0, 0),
14            border_width: 0,
15        }
16    }
17}
18
19/// Builder pattern for constructing [`Style`] instances.
20pub struct StyleBuilder {
21    style: Style,
22}
23
24impl Default for StyleBuilder {
25    fn default() -> Self {
26        Self::new()
27    }
28}
29
30impl StyleBuilder {
31    /// Create a new builder with [`Style::default`] values.
32    pub fn new() -> Self {
33        Self {
34            style: Style::default(),
35        }
36    }
37
38    /// Set the background color.
39    pub fn bg_color(mut self, color: crate::widget::Color) -> Self {
40        self.style.bg_color = color;
41        self
42    }
43
44    /// Set the border color.
45    pub fn border_color(mut self, color: crate::widget::Color) -> Self {
46        self.style.border_color = color;
47        self
48    }
49
50    /// Set the border width in pixels.
51    pub fn border_width(mut self, width: u8) -> Self {
52        self.style.border_width = width;
53        self
54    }
55
56    /// Consume the builder and return the constructed [`Style`].
57    pub fn build(self) -> Style {
58        self.style
59    }
60}