x11-overlay 0.1.0

A library for creating overlay interfaces on X11 systems using Cairo for rendering
Documentation
#![allow(dead_code)] // Allow unused code for future functionality

pub mod context;
pub mod dynamic_color;
#[cfg(test)]
pub mod dynamic_color_tests;
pub mod font;
pub mod layout;
pub mod renderer;
pub mod text;

pub use context::GraphicsContext;
pub use dynamic_color::{ColorProperty, DynamicColor};
pub use font::FontDesc;
pub use layout::{Alignment, TextLayout, VerticalAlignment};
pub use renderer::Rectangle;
pub use text::TextRenderer;

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Color {
    pub r: f64,
    pub g: f64,
    pub b: f64,
    pub a: f64,
}

impl Color {
    pub fn rgba(r: f64, g: f64, b: f64, a: f64) -> Self {
        Self { r, g, b, a }
    }

    pub fn rgb(r: f64, g: f64, b: f64) -> Self {
        Self { r, g, b, a: 1.0 }
    }

    pub fn white() -> Self {
        Self::rgb(1.0, 1.0, 1.0)
    }

    pub fn black() -> Self {
        Self::rgb(0.0, 0.0, 0.0)
    }

    pub fn transparent() -> Self {
        Self::rgba(0.0, 0.0, 0.0, 0.0)
    }

    pub fn to_renderer_color(self) -> renderer::Color {
        renderer::Color {
            argb: ((self.a * 255.0) as u32) << 24
                | ((self.r * 255.0) as u32) << 16
                | ((self.g * 255.0) as u32) << 8
                | ((self.b * 255.0) as u32),
        }
    }

    pub const WHITE: Color = Color {
        r: 1.0,
        g: 1.0,
        b: 1.0,
        a: 1.0,
    };
    pub const BLACK: Color = Color {
        r: 0.0,
        g: 0.0,
        b: 0.0,
        a: 1.0,
    };
    pub const GREEN: Color = Color {
        r: 0.0,
        g: 1.0,
        b: 0.0,
        a: 1.0,
    };
    pub const TRANSPARENT: Color = Color {
        r: 0.0,
        g: 0.0,
        b: 0.0,
        a: 0.0,
    };

    // Modern color palette for better aesthetics
    pub const SLATE_900: Color = Color {
        r: 0.059,
        g: 0.071,
        b: 0.090,
        a: 1.0,
    }; // #0f1419
    pub const SLATE_800: Color = Color {
        r: 0.118,
        g: 0.145,
        b: 0.180,
        a: 1.0,
    }; // #1e252d
    pub const SLATE_700: Color = Color {
        r: 0.204,
        g: 0.243,
        b: 0.298,
        a: 1.0,
    }; // #343e4c
    pub const SLATE_600: Color = Color {
        r: 0.294,
        g: 0.341,
        b: 0.400,
        a: 1.0,
    }; // #4b5766

    pub const BLUE_500: Color = Color {
        r: 0.235,
        g: 0.561,
        b: 0.969,
        a: 1.0,
    }; // #3c8ff7
    pub const BLUE_400: Color = Color {
        r: 0.376,
        g: 0.647,
        b: 0.984,
        a: 1.0,
    }; // #60a5fb
    pub const EMERALD_500: Color = Color {
        r: 0.063,
        g: 0.725,
        b: 0.384,
        a: 1.0,
    }; // #10b962
    pub const EMERALD_400: Color = Color {
        r: 0.200,
        g: 0.831,
        b: 0.522,
        a: 1.0,
    }; // #34d485

    pub const AMBER_500: Color = Color {
        r: 0.957,
        g: 0.620,
        b: 0.039,
        a: 1.0,
    }; // #f59e0a
    pub const ORANGE_500: Color = Color {
        r: 0.973,
        g: 0.447,
        b: 0.094,
        a: 1.0,
    }; // #f87218
    pub const RED_500: Color = Color {
        r: 0.937,
        g: 0.267,
        b: 0.267,
        a: 1.0,
    }; // #ef4444

    pub const PURPLE_500: Color = Color {
        r: 0.663,
        g: 0.408,
        b: 0.992,
        a: 1.0,
    }; // #a968fd
    pub const PINK_500: Color = Color {
        r: 0.925,
        g: 0.286,
        b: 0.631,
        a: 1.0,
    }; // #ec49a1
}

#[derive(Debug, Clone, Copy)]
pub struct Rect {
    pub x: i32,
    pub y: i32,
    pub width: u32,
    pub height: u32,
}

impl Rect {
    pub fn new(x: i32, y: i32, width: u32, height: u32) -> Self {
        Self {
            x,
            y,
            width,
            height,
        }
    }
}