rlvgl-core 0.1.7

Core runtime, widget tree, renderer, style, and plugin interfaces for rlvgl.
Documentation
//! Visual appearance attributes applied to widgets.

/// Collection of styling properties for a widget.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Style {
    /// Background color of the widget.
    pub bg_color: crate::widget::Color,
    /// Border color of the widget.
    pub border_color: crate::widget::Color,
    /// Border width in pixels.
    pub border_width: u8,
    /// Widget-level opacity (`255` = fully opaque, `0` = fully transparent).
    ///
    /// Applied as a multiplier to all colors when the widget draws itself.
    pub alpha: u8,
    /// Corner radius in pixels (`0` = sharp corners).
    pub radius: u8,
}

impl Default for Style {
    fn default() -> Self {
        Self {
            bg_color: crate::widget::Color(255, 255, 255, 255),
            border_color: crate::widget::Color(0, 0, 0, 255),
            border_width: 0,
            alpha: 255,
            radius: 0,
        }
    }
}

/// Builder pattern for constructing [`Style`] instances.
pub struct StyleBuilder {
    style: Style,
}

impl Default for StyleBuilder {
    fn default() -> Self {
        Self::new()
    }
}

impl StyleBuilder {
    /// Create a new builder with [`Style::default`] values.
    pub fn new() -> Self {
        Self {
            style: Style::default(),
        }
    }

    /// Set the background color.
    pub fn bg_color(mut self, color: crate::widget::Color) -> Self {
        self.style.bg_color = color;
        self
    }

    /// Set the border color.
    pub fn border_color(mut self, color: crate::widget::Color) -> Self {
        self.style.border_color = color;
        self
    }

    /// Set the border width in pixels.
    pub fn border_width(mut self, width: u8) -> Self {
        self.style.border_width = width;
        self
    }

    /// Set the widget-level opacity (`255` = opaque, `0` = transparent).
    pub fn alpha(mut self, alpha: u8) -> Self {
        self.style.alpha = alpha;
        self
    }

    /// Set the corner radius in pixels (`0` = sharp corners).
    pub fn radius(mut self, radius: u8) -> Self {
        self.style.radius = radius;
        self
    }

    /// Consume the builder and return the constructed [`Style`].
    pub fn build(self) -> Style {
        self.style
    }
}