euv-core 0.43.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Identity default for `Transform2D`.
impl Default for Transform2D {
    /// Creates an identity 2D transform (`scale = 1.0`, `translate = 0.0`, `rotation = 0.0`).
    ///
    /// # Returns
    ///
    /// - `Self` - Identity `Transform2D`.
    fn default() -> Self {
        Self::new(0.0, 0.0, 1.0, 1.0, 0.0)
    }
}

/// Default paint properties (`opacity = 1.0`, transparent background).
impl Default for PaintStyle {
    /// Creates default transparent paint properties.
    ///
    /// # Returns
    ///
    /// - `Self` - Default `PaintStyle`.
    fn default() -> Self {
        Self {
            background: None,
            gradient: None,
            border: Border::default(),
            radius: CornerRadius::default(),
            shadow: None,
            focus_ring: None,
            opacity: 1.0,
            transform: Transform2D::default(),
            cursor: CursorIcon::Default,
            pointer_events: PointerEvents::Auto,
            stop_scroll_propagation: false,
            stop_event_propagation: false,
        }
    }
}

/// Inspection helpers for `Transform2D`.
impl Transform2D {
    /// Returns true when the transform is the exact identity transform.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Transform to inspect.
    ///
    /// # Returns
    ///
    /// - `bool` - True when translation and rotation are zero and scale is one.
    #[must_use]
    pub fn is_identity(&self) -> bool {
        self.get_translate_x() == 0.0
            && self.get_translate_y() == 0.0
            && self.get_scale_x() == 1.0
            && self.get_scale_y() == 1.0
            && self.get_rotation_rad() == 0.0
    }
}

/// Non-panicking optional field readers for `PaintStyle`.
impl PaintStyle {
    /// Returns the optional background color.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Paint style.
    ///
    /// # Returns
    ///
    /// - `Option<Color>` - Background color if set.
    #[must_use]
    pub fn background_color(&self) -> Option<Color> {
        let Self { background, .. } = *self;
        background
    }

    /// Returns the optional linear gradient fill.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Paint style.
    ///
    /// # Returns
    ///
    /// - `Option<LinearGradient>` - Linear gradient if set.
    #[must_use]
    pub fn background_gradient(&self) -> Option<LinearGradient> {
        let Self { gradient, .. } = *self;
        gradient
    }

    /// Returns the optional drop shadow.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Paint style.
    ///
    /// # Returns
    ///
    /// - `Option<Shadow>` - Drop shadow if set.
    #[must_use]
    pub fn box_shadow(&self) -> Option<Shadow> {
        let Self { shadow, .. } = *self;
        shadow
    }

    /// Returns the optional focus ring stroke.
    ///
    /// # Arguments
    ///
    /// - `&Self` - Paint style.
    ///
    /// # Returns
    ///
    /// - `Option<Border>` - Focus ring stroke if set.
    #[must_use]
    pub fn focus_ring_border(&self) -> Option<Border> {
        let Self { focus_ring, .. } = *self;
        focus_ring
    }
}