penlib/
posca.rs

1use std::hash::Hash;
2
3use palette::rgb::LinSrgb;
4
5use crate::Pen;
6
7pub trait ColorPalette: Clone + Eq + PartialEq + Hash {
8    fn available_colors() -> Vec<Self>;
9    fn rgb_color(&self) -> LinSrgb;
10}
11
12#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
13pub enum UniPosca12Pk {
14    Black,
15    White,
16    Brown,
17    Blue,
18    LightBlue,
19    Green,
20    LightGreen,
21    SunshineYellow,
22    Orange,
23    Red,
24    Pink,
25    Violet,
26}
27
28impl ColorPalette for UniPosca12Pk {
29    fn available_colors() -> Vec<Self> {
30        vec![
31            Self::Black,
32            Self::White,
33            Self::Brown,
34            Self::Blue,
35            Self::LightBlue,
36            Self::Green,
37            Self::LightGreen,
38            Self::SunshineYellow,
39            Self::Orange,
40            Self::Red,
41            Self::Pink,
42            Self::Violet,
43        ]
44    }
45
46    fn rgb_color(&self) -> LinSrgb {
47        let (r, g, b) = match self {
48            Self::Black => (0x00, 0x00, 0x00),
49            Self::White => (0xf6, 0xf7, 0xf9),
50            Self::Brown => (0x8c, 0x3a, 0x0a),
51            Self::Blue => (0x00, 0x00, 0xcb),
52            Self::LightBlue => (0x51, 0xaf, 0xf7),
53            Self::Green => (0x00, 0x7f, 0x2f),
54            Self::LightGreen => (0x67, 0xcb, 0x57),
55            Self::SunshineYellow => (0xfb, 0xfb, 0x76),
56            Self::Orange => (0xf4, 0x67, 0x2c),
57            Self::Red => (0xd3, 0x0a, 0x0a),
58            Self::Pink => (0xfa, 0x54, 0xac),
59            Self::Violet => (0x69, 0x3d, 0xae),
60        };
61        LinSrgb::new(r as f32 / 255.0, g as f32 / 255.0, b as f32 / 255.0).into_linear()
62    }
63}
64
65#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
66pub struct UniPosca1MC<T: ColorPalette> {
67    pub color: T,
68}
69
70impl<T: ColorPalette> UniPosca1MC<T> {
71    pub fn new(color: T) -> UniPosca1MC<T> {
72        UniPosca1MC { color }
73    }
74}
75
76impl<T: ColorPalette> Pen for UniPosca1MC<T> {
77    fn available_colors() -> Vec<Self> {
78        T::available_colors().into_iter()
79            .map(Self::new)
80            .collect()
81    }
82
83    fn nib_size_mm() -> f64 {
84        0.7
85    }
86
87    fn rgb_color(&self) -> LinSrgb {
88        self.color.rgb_color()
89    }
90}