1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
use pax::*;
use pax::api::{PropertyInstance, PropertyLiteral, Interpolatable, SizePixels};
#[cfg(feature = "parser")]
use pax_compiler_api::PathQualifiable;
#[derive(Clone)]
#[pax_type]
pub struct Stroke {
pub color: Box<dyn PropertyInstance<Color>>,
pub width: Box<dyn PropertyInstance<SizePixels>>,
}
impl Default for Stroke {
fn default() -> Self {
Self {
color: Box::new(PropertyLiteral::new(Default::default())),
width: Box::new(PropertyLiteral::new(SizePixels(0.0))),
}
}
}
#[derive(Default, Clone)]
#[pax_type]
pub struct Text {
pub content: Box<dyn PropertyInstance<String>>,
}
#[derive(Clone)]
#[pax_type]
pub struct StackerCellProperties {
pub x_px: f64,
pub y_px: f64,
pub width_px: f64,
pub height_px: f64,
}
#[derive(Clone)]
#[pax_type]
pub enum StackerDirection {
Vertical,
Horizontal,
}
impl Default for StackerDirection {
fn default() -> Self {
StackerDirection::Horizontal
}
}
impl Interpolatable for StackerDirection {}
#[derive(Clone)]
#[pax_type]
pub struct Font {
pub family: Box<dyn pax::api::PropertyInstance<String>>,
pub variant: Box<dyn pax::api::PropertyInstance<String>>,
pub size: Box<dyn pax::api::PropertyInstance<SizePixels>>,
}
impl Into<FontPatch> for &Font {
fn into(self) -> FontPatch {
FontPatch {
family: Some(self.family.get().clone()),
variant: Some(self.variant.get().clone()),
size: Some(self.size.get().0),
}
}
}
impl PartialEq<FontPatch> for Font {
fn eq(&self, other: &FontPatch) -> bool {
matches!(&other.family, Some(family) if family.eq(self.family.get()))
&& matches!(&other.variant, Some(variant) if variant.eq(self.variant.get()))
&& matches!(&other.size, Some(size) if size.eq(self.size.get()))
}
}
impl Default for Font {
fn default() -> Self {
Self {
family: Box::new(PropertyLiteral::new("Courier New".to_string())),
variant: Box::new(PropertyLiteral::new("Regular".to_string())),
size: Box::new(PropertyLiteral::new(SizePixels(14.0))),
}
}
}
impl Interpolatable for Font {}
#[derive(Clone)]
#[pax_type]
pub struct Color{
pub color_variant: ColorVariant,
}
impl Default for Color {
fn default() -> Self {
Self {
color_variant: ColorVariant::Rgba([0.0, 0.0, 1.0, 1.0])
}
}
}
impl Into<ColorVariantMessage> for &Color {
fn into(self) -> ColorVariantMessage {
match self.color_variant {
ColorVariant::Hlca(channels) => {
ColorVariantMessage::Hlca(channels)
},
ColorVariant::Rgba(channels) => {
ColorVariantMessage::Rgba(channels)
}
}
}
}
impl PartialEq<ColorVariantMessage> for Color {
fn eq(&self, other: &ColorVariantMessage) -> bool {
match self.color_variant {
ColorVariant::Hlca(channels_self) => {
if matches!(other, ColorVariantMessage::Hlca(channels_other) if channels_other.eq(&channels_self)) {
return true;
}
},
ColorVariant::Rgba(channels_self) => {
if matches!(other, ColorVariantMessage::Rgba(channels_other) if channels_other.eq(&channels_self)) {
return true;
}
}
}
false
}
}
impl Interpolatable for Color {
}
impl Color {
pub fn hlca(h:f64, l:f64, c:f64, a:f64) -> Self {
Self {color_variant: ColorVariant::Hlca([h,l,c,a])}
}
pub fn rgba(r:f64, g:f64, b:f64, a:f64) -> Self {
Self {color_variant: ColorVariant::Rgba([r,g,b,a])}
}
pub fn to_piet_color(&self) -> piet::Color {
match self.color_variant {
ColorVariant::Hlca(slice) => {
piet::Color::hlca(slice[0], slice[1], slice[2], slice[3])
},
ColorVariant::Rgba(slice) => {
piet::Color::rgba(slice[0], slice[1], slice[2], slice[3])
}
}
}
}
#[derive(Clone)]
#[pax_type]
pub enum ColorVariant {
Hlca([f64; 4]),
Rgba([f64; 4]),
}
pub use pax::api::Size;
use pax_message::{ColorVariantMessage, FontPatch};