rlvgl_core/
style.rs

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