sar_core/core/
sa.rs

1use std::fmt::Debug;
2
3use super::symbol::Symbol;
4
5/// Represents a position in 2D space
6#[derive(Debug, Clone, Copy, PartialEq)]
7pub struct Position {
8    /// X coordinate
9    pub x: u8,
10    /// Y coordinate
11    pub y: u8,
12}
13
14/// Represents a complete SymbolArt composition
15///
16/// A SymbolArt is a user-created artwork composed of multiple layers of symbols.
17/// Each layer contains a symbol positioned and colored according to the layer's properties.
18pub trait SymbolArt: Send + Sync {
19    type Layer: SymbolArtLayer + Send + Sync;
20    fn author_id(&self) -> u32;
21    fn height(&self) -> u8;
22    fn width(&self) -> u8;
23    fn layers(&self) -> Vec<Self::Layer>;
24    fn name(&self) -> String;
25}
26
27/// Represents a single layer in a SymbolArt composition
28///
29/// A SymbolArt is composed of multiple layers stacked on top of each other,
30/// where each layer contains a symbol positioned and colored according to the
31/// layer's properties. The order of layers determines their visual stacking
32/// order in the final composition.
33pub trait SymbolArtLayer {
34    fn top_left(&self) -> Position;
35    fn bottom_left(&self) -> Position;
36    fn top_right(&self) -> Position;
37    fn bottom_right(&self) -> Position;
38    fn symbol(&self) -> Symbol;
39    fn color(&self) -> Color;
40    fn is_hidden(&self) -> bool;
41}
42
43/// Represents a color in RGBA format
44///
45/// Each component (red, green, blue, alpha) is represented as an 8-bit unsigned integer,
46/// allowing for values between 0 and 255. The alpha channel controls transparency,
47/// where 0 is fully transparent and 255 is fully opaque.
48#[derive(Debug, Clone, Copy)]
49pub struct Color {
50    pub a: u8,
51    pub r: u8,
52    pub g: u8,
53    pub b: u8,
54}
55
56impl Color {
57    pub fn new(a: u8, r: u8, g: u8, b: u8) -> Self {
58        Self { a, r, g, b }
59    }
60}
61
62impl From<Color> for image::Rgba<u8> {
63    fn from(value: Color) -> Self {
64        image::Rgba([value.r, value.g, value.b, value.a])
65    }
66}