faststep 0.1.0

UIKit-inspired embedded UI framework built on embedded-graphics
Documentation
use embedded_graphics::{prelude::Point, primitives::Rectangle};

/// Padding values applied around a view's content area.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct EdgeInsets {
    /// Top padding in pixels.
    pub top: u32,
    /// Left padding in pixels.
    pub left: u32,
    /// Bottom padding in pixels.
    pub bottom: u32,
    /// Right padding in pixels.
    pub right: u32,
}

impl EdgeInsets {
    /// Creates explicit inset values.
    pub const fn new(top: u32, left: u32, bottom: u32, right: u32) -> Self {
        Self {
            top,
            left,
            bottom,
            right,
        }
    }

    /// Creates insets with the same value on every side.
    pub const fn all(value: u32) -> Self {
        Self::new(value, value, value, value)
    }

    /// Insets `rect` and clamps the size at zero.
    pub fn inset_rect(self, rect: Rectangle) -> Rectangle {
        let horizontal = self.left.saturating_add(self.right);
        let vertical = self.top.saturating_add(self.bottom);
        Rectangle::new(
            rect.top_left + Point::new(self.left as i32, self.top as i32),
            embedded_graphics::geometry::Size::new(
                rect.size.width.saturating_sub(horizontal),
                rect.size.height.saturating_sub(vertical),
            ),
        )
    }
}