Initial commit

This commit is contained in:
Breadway 2026-07-03 13:37:31 +08:00
commit 9f97f2c989
37 changed files with 4871 additions and 0 deletions

32
breadlock-ui/src/theme.rs Normal file
View file

@ -0,0 +1,32 @@
pub use bread_theme::{ink_on, load_palette, Palette};
/// Parse a `#rrggbb` hex colour. Falls back to opaque black on malformed input
/// (palette slots are always produced by [`bread_theme`], which guarantees
/// valid hex, but a user-supplied override in a future config field might not).
pub fn parse_hex(hex: &str) -> (u8, u8, u8) {
let h = hex.trim_start_matches('#');
let byte = |i: usize| u8::from_str_radix(h.get(i..i + 2).unwrap_or("00"), 16).unwrap_or(0);
(byte(0), byte(2), byte(4))
}
#[cfg(feature = "paint")]
pub fn tiny_skia_color(hex: &str) -> tiny_skia::Color {
let (r, g, b) = parse_hex(hex);
tiny_skia::Color::from_rgba8(r, g, b, 255)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn parses_known_hex() {
assert_eq!(parse_hex("#1e1e2e"), (0x1e, 0x1e, 0x2e));
assert_eq!(parse_hex("89b4fa"), (0x89, 0xb4, 0xfa));
}
#[test]
fn malformed_hex_falls_back_to_black() {
assert_eq!(parse_hex("nope"), (0, 0, 0));
}
}