Skip to content

Commit

Permalink
handover deserializer to Warfa (boxed Enum in PaxValue)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelselleck authored and zackbrown committed Oct 31, 2024
1 parent c05a134 commit ddfd883
Show file tree
Hide file tree
Showing 16 changed files with 495 additions and 708 deletions.
205 changes: 0 additions & 205 deletions examples/src/starter-project/src/lib.pax
Original file line number Diff line number Diff line change
@@ -1,208 +1,3 @@
<Text y=56.43% x=96.88% height=12.40% text="Every visual change is code." style={
font: Font::Web(
"Roboto",
"https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap",
FontStyle::Normal,
FontWeight::Bold)
font_size: 35.00px
fill: rgba(254, 254, 254, 255)
align_vertical: TextAlignVertical::Bottom
align_horizontal: TextAlignHorizontal::Left
align_multiline: TextAlignHorizontal::Left
underline: false
}
width=46.40% rotate=-4.88deg/>
<Link y=6.38% width=11.93% x=55.79% height=5.17% url="https://docs.pax.dev/get-started/" target=Target::New>
<Text y=0.00% x=100.00% text="Get Started" style={
font: Font::Web(
"Roboto",
"https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap",
FontStyle::Normal,
FontWeight::Bold)
font_size: 24px
fill: rgba(254, 254, 254, 255)
align_vertical: TextAlignVertical::Center
align_horizontal: TextAlignHorizontal::Center
align_multiline: TextAlignHorizontal::Center
underline: false
}
width=100% height=100%/>
<Rectangle height=100% width=100% corner_radii={
top_left: 10
top_right: 10
bottom_left: 10
bottom_right: 10
}
y=0.00% x=0.00% fill=INDIGO/>
</Link>
<Link y=6.17% width=11.87% x=39.96% height=5.63% url="https://docs.pax.dev" target=Target::New>
<Text y=0.00% x=0.00% text="Docs" style={
font: Font::Web(
"Roboto",
"https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap",
FontStyle::Normal,
FontWeight::Light)
font_size: 24px
fill: rgba(254, 254, 254, 255)
align_vertical: TextAlignVertical::Center
align_horizontal: TextAlignHorizontal::Center
align_multiline: TextAlignHorizontal::Center
underline: false
}
width=100% height=100%/>
</Link>
<Link y=6.17% width=11.87% x=27.01% height=5.63% url="https://discord.com/invite/Eq8KWAUc6b" target=Target::New>
<Text y=0.00% x=0.00% text="Discord" style={
font: Font::Web(
"Roboto",
"https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap",
FontStyle::Normal,
FontWeight::Light)
font_size: 24px
fill: rgba(254, 254, 254, 255)
align_vertical: TextAlignVertical::Center
align_horizontal: TextAlignHorizontal::Center
align_multiline: TextAlignHorizontal::Center
underline: false
}
width=100% height=100%/>
</Link>
<Link y=6.17% width=11.87% x=14.67% height=5.63% url="https://github.com/paxdotdev/pax" target=Target::New>
<Text y=0.00% x=0.00% text="GitHub" style={
font: Font::Web(
"Roboto",
"https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap",
FontStyle::Normal,
FontWeight::Light)
font_size: 24px
fill: rgba(254, 254, 254, 255)
align_vertical: TextAlignVertical::Center
align_horizontal: TextAlignHorizontal::Center
align_multiline: TextAlignHorizontal::Center
underline: false
}
width=100% height=100%/>
</Link>
<Image source=ImageSource::Url("assets/pax-logo-white-on-black.png") x=2.72% height=8.88% y=5.97% width=9.71%/>
<Carousel width=45.41% x=24.32% y=56.84% height=78.32% anchor_x=50.00% anchor_y=50.00%>
<Group>
<Calculator />
<Rectangle fill=rgba(30, 30, 30, 255)/>
</Group>
<Group>
<Fireworks />
<Rectangle fill=WHITE/>
</Group>
<ColorPickerExample />
<BreakoutGame />
</Carousel>
<Group x=95.19% scale_x=100% y=39.88% width=44.39% scale_y=100% height=36.88% anchor_x=100% rotate=-4.79deg>
<Text y=71.71% x=108.62% height=39.59%
text="Build mobile apps, websites, business tools, games, digital art, interactive cartoons, desktop &amp; embedded applications, data visualizations, and more."
style={
font: Font::Web(
"Roboto",
"https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap",
FontStyle::Normal,
FontWeight::Light)
font_size: 24.00px
fill: rgba(254, 254, 254, 255)
align_vertical: TextAlignVertical::Center
align_horizontal: TextAlignHorizontal::Left
align_multiline: TextAlignHorizontal::Left
underline: false
}
width=108.20%/>
<Text y=18.84% x=0.15% height=42.85% text="Build user interfaces with the creative freedom of a vector design tool." style={
font: Font::Web(
"Roboto",
"https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap",
FontStyle::Normal,
FontWeight::Bold)
font_size: 38px
fill: rgba(254, 254, 254, 255)
align_vertical: TextAlignVertical::Top
align_horizontal: TextAlignHorizontal::Left
align_multiline: TextAlignHorizontal::Left
underline: false
}
width=110.45%/>
</Group>
<Link width=38.25% y=92.58% x=96.84% height=17.30% url="https://airtable.com/appCUQtUS9g4kuQZL/pagGMVOPv9AH1cNJS/form"
target=Target::New>
<Group y=-0.83% height=79.81% x=49.99% width=90.90%>
<Text y=9.36% x=55.62% height=66.15% text="Be a pilot for Pax Pro" style={
font: Font::Web(
"Roboto",
"https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap",
FontStyle::Normal,
FontWeight::Bold)
font_size: 42px
fill: rgba(1, 1, 1, 255)
align_vertical: TextAlignVertical::Bottom
align_horizontal: TextAlignHorizontal::Left
align_multiline: TextAlignHorizontal::Left
underline: false
}
width=99.46%/>
<Text y=92.00% x=110.62% height=54.86% text="Your whole team, building together on GitHub" style={
font: Font::Web(
"Roboto",
"https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap",
FontStyle::Normal,
FontWeight::Normal)
font_size: 26px
fill: rgba(1, 1, 1, 255)
align_vertical: TextAlignVertical::Bottom
align_horizontal: TextAlignHorizontal::Left
align_multiline: TextAlignHorizontal::Left
underline: false
}
width=109.92%/>
</Group>
<Group x=79.65% scale_y=140.00% height=81.05% scale_x=139.99% y=99.99% width=76.34%>
<Rectangle y=100.00% height=123.35% x=94.95% corner_radii={
top_left: 30
top_right: 30
bottom_left: 30
bottom_right: 30
}
stroke={
color: rgba(99, 102, 241, 255)
width: 15.00px
} fill=rgba(246, 247, 248, 255) scale_x=71.42%
width=132.33% scale_y=71.42%/>
<Rectangle y=72.04% height=130.98% x=73.65% corner_radii={
top_left: 30
top_right: 30
bottom_left: 30
bottom_right: 30
}
stroke={
color: rgba(99, 102, 241, 255)
width: 0.00px
} fill=rgba(0, 0, 0, 40) width=134.69% rotate=-0.01deg
scale_x=71.42% scale_y=71.42%/>
</Group>
</Link>
<Image source=ImageSource::Url("assets/Frame 2.png") y=-30.44% width=21.73% scale_y=139.99% x=116.58% scale_x=139.99%
height=21.37%/>
<Image source=ImageSource::Url("assets/Frame 1.png") x=-11.85% scale_y=139.99% width=24.22% y=-27.14% scale_x=139.99%
height=16.65%/>
<Image source=ImageSource::Url("assets/Frame 3.png") y=130.59% height=19.53% x=55.19% scale_x=139.98% scale_y=139.98%
width=25.86%/>
<Group width=74.83% height=80.63% scale_x=139.99% scale_y=139.99% x=49.10% y=48.14% rotate=-3.80deg>
<Rectangle x=100.00% height=43.76% y=99.99% fill=rgba(206, 207, 207, 255) width=139.95% scale_y=71.41% scale_x=71.41%/>
<Rectangle x=58.65% height=51.06% y=50.47% fill=rgba(46, 49, 49, 255) width=139.88% scale_x=71.41% scale_y=71.41%/>
<Rectangle x=0.00% height=45.02% y=0.00% fill=rgba(12, 12, 12, 255) corner_radii={
top_left: 0
top_right: 0
bottom_left: 0
bottom_right: 0
}
width=139.96% scale_y=71.41% scale_x=71.41%/>
</Group>

@settings {
@pre_render: handle_pre_render
#text {
Expand Down
19 changes: 8 additions & 11 deletions pax-designer/src/model/tools/paintbrush_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ impl ToolBehavior for PaintbrushTool {
&PathElement::Point(x, y) => points.push((x, y)),
PathElement::Line => (),
&PathElement::Quadratic(x, y) => points.push((x, y)),
PathElement::Cubic(sizes) => {
points.push((sizes.0, sizes.1));
points.push((sizes.2, sizes.3));
&PathElement::Cubic(v1, v2, v3, v4) => {
points.push((v1, v2));
points.push((v3, v4));
}
PathElement::Close => (),
PathElement::Empty => (),
Expand Down Expand Up @@ -272,12 +272,9 @@ impl ToolBehavior for PaintbrushTool {
PathElement::Point(x, y) => PathElement::Point(conv_x(x), conv_y(y)),
PathElement::Line => PathElement::Line,
PathElement::Quadratic(x, y) => PathElement::Quadratic(conv_x(x), conv_y(y)),
PathElement::Cubic(sizes) => PathElement::Cubic(Box::new((
conv_x(sizes.0),
conv_y(sizes.1),
conv_x(sizes.2),
conv_y(sizes.3),
))),
PathElement::Cubic(v1, v2, v3, v4) => {
PathElement::Cubic(conv_x(v1), conv_y(v2), conv_x(v3), conv_y(v4))
}
PathElement::Close => PathElement::Close,
})
.collect();
Expand Down Expand Up @@ -411,12 +408,12 @@ fn to_pax_path(path: &CompoundPath, bounds: (f64, f64)) -> Vec<PathElement> {
handle_start: ctrl1,
handle_end: ctrl2,
} => {
pax_segs.push(PathElement::Cubic(Box::new((
pax_segs.push(PathElement::Cubic(
Size::Percent((100.0 * ctrl1.x / bounds.0).into()),
Size::Percent((100.0 * ctrl1.y / bounds.1).into()),
Size::Percent((100.0 * ctrl2.x / bounds.0).into()),
Size::Percent((100.0 * ctrl2.y / bounds.1).into()),
))));
));
pax_segs.push(PathElement::Point(
Size::Percent((100.0 * seg.end.x / bounds.0).into()),
Size::Percent((100.0 * seg.end.y / bounds.1).into()),
Expand Down
1 change: 1 addition & 0 deletions pax-lang/src/deserializer/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ impl<'de> VariantAccess<'de> for PaxEnum<'de> {
T: DeserializeSeed<'de>,
{
let ast = self.args.unwrap();
eprintln!("AST: {:?}: {:?}", ast.to_string(), ast.as_str());
seed.deserialize(PaxDeserializer::from(ast))
}

Expand Down
8 changes: 4 additions & 4 deletions pax-lang/src/deserializer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ fn test_vec() {
#[test]
fn test_enum() {
let enum_pax = "Test::Enum(10, 20, 30)".to_string();
let expected = PaxValue::Enum(
let expected = PaxValue::Enum(Box::new((
"Test".to_string(),
"Enum".to_string(),
vec![
PaxValue::Numeric(Numeric::I64(10)),
PaxValue::Numeric(Numeric::I64(20)),
PaxValue::Numeric(Numeric::I64(30)),
],
);
)));
let v = from_pax(&enum_pax).unwrap();
assert_eq!(expected, v);
}
Expand Down Expand Up @@ -148,7 +148,7 @@ fn test_complex_vec() {
#[test]
fn test_complex_enum() {
let enum_pax = "Test::Enum(10, 20, 30, [40, 50], { a: 60 })".to_string();
let expected = PaxValue::Enum(
let expected = PaxValue::Enum(Box::new((
"Test".to_string(),
"Enum".to_string(),
vec![
Expand All @@ -165,7 +165,7 @@ fn test_complex_enum() {
.collect(),
),
],
);
)));
let v = from_pax(&enum_pax).unwrap();
assert_eq!(expected, v);
}
Expand Down
6 changes: 5 additions & 1 deletion pax-lang/src/interpreter/computable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ impl Computable for PaxPrimary {
return call_function(scope.clone(), name_or_variant.clone(), args);
}

Ok(PaxValue::Enum(scope.clone(), name_or_variant.clone(), args))
Ok(PaxValue::Enum(Box::new((
scope.clone(),
name_or_variant.clone(),
args,
))))
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions pax-macro/templates/derive_pax.stpl
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ impl <%= engine_import_path %>::api::CoercionRules for <%= pascal_identifier %>
fn try_coerce(value: <%= engine_import_path %>::PaxValue) -> Result<Self, String> {
<% if let InternalDefinitions::Enum(variant_definitions) = &internal_definitions { %>
match value {
<%= engine_import_path %>::PaxValue::Enum(_, variant_name, values) => {
<%= engine_import_path %>::PaxValue::Enum(contents) => {
let (_, variant_name, values) = *contents;
match variant_name.as_str() {
<% for vd in variant_definitions { %>
"<%= vd.variant_name %>" => {
Expand Down Expand Up @@ -367,15 +368,15 @@ impl <%= engine_import_path %>::api::ToPaxValue for <%= pascal_identifier %> {
<% } %>
)
<% } %> => {
<%= engine_import_path %>::PaxValue::Enum(
<%= engine_import_path %>::PaxValue::Enum(Box::new((
"<%= pascal_identifier %>".to_string(),
"<%= vd.variant_name %>".to_string(),
vec![
<% for spd in &vd.variant_fields { %>
<<%=spd.root_scoped_resolvable_type%> as <%= engine_import_path %>::api::ToPaxValue>::to_pax_value(<%= spd.field_name %>),
<% } %>
].into_iter().collect()
)
)))
},
<% } %>
}
Expand Down
Loading

0 comments on commit ddfd883

Please sign in to comment.