Skip to content

Commit

Permalink
remove custom(Import)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelselleck committed Feb 6, 2024
1 parent 44a082b commit 01b7e95
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 90 deletions.
2 changes: 1 addition & 1 deletion docs
Submodule docs updated from c748d9 to 8569b2
15 changes: 9 additions & 6 deletions examples/src/camera/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![allow(unused_imports)]
use pax_lang::api::{ArgsClick, EasingCurve, NodeContext, Property};
use pax_lang::Pax;
use pax_std::primitives::{Rectangle, Group, Frame, Text, Ellipse};
use pax_std::primitives::{Ellipse, Frame, Group, Rectangle, Text};

#[pax]
#[main]
Expand All @@ -15,7 +15,6 @@ pub struct Camera {
}

#[pax]
#[custom(Imports)]
pub struct TypeExample {
pub foo: Property<usize>,
}
Expand All @@ -28,12 +27,16 @@ impl Camera {
}

pub fn handle_click(&mut self, _: NodeContext, args: ArgsClick) {
let delta_pan = (args.mouse.x - self.pan_x.get(), args.mouse.y - self.pan_y.get());
self.pan_x.ease_to(self.pan_x.get() + delta_pan.0, 200, EasingCurve::Linear);
self.pan_y.ease_to(self.pan_y.get() + delta_pan.1, 200, EasingCurve::Linear);
let delta_pan = (
args.mouse.x - self.pan_x.get(),
args.mouse.y - self.pan_y.get(),
);
self.pan_x
.ease_to(self.pan_x.get() + delta_pan.0, 200, EasingCurve::Linear);
self.pan_y
.ease_to(self.pan_y.get() + delta_pan.1, 200, EasingCurve::Linear);

self.zoom.ease_to(0.5, 100, EasingCurve::OutQuad);
self.zoom.ease_to_later(2.0, 100, EasingCurve::InQuad)
}

}
1 change: 0 additions & 1 deletion examples/src/pax-intro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub struct DynamicObject {
}

#[pax]
#[custom(Imports)]
pub struct Rect {
pub x: Size,
pub y: Size,
Expand Down
33 changes: 11 additions & 22 deletions examples/src/three-repeats/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#![allow(unused_imports)]

use pax_lang::*;
use pax_lang::api::*;
use pax_lang::*;
use pax_std::components::Stacker;
use pax_std::components::*;
use pax_std::primitives::*;
use pax_std::types::*;
use pax_std::types::text::*;
use pax_std::components::*;
use pax_std::components::Stacker;
use pax_std::types::*;

#[pax]
#[main]
Expand All @@ -20,28 +20,17 @@ impl Default for ThreeRepeats {
fn default() -> Self {
Self {
some_data: Box::new(PropertyLiteral::new(vec![
CustomStruct{
x: 250
},
CustomStruct{
x: 300
},
CustomStruct{
x: 450
},
CustomStruct{
x: 550
},
CustomStruct{
x: 850
}
]))
CustomStruct { x: 250 },
CustomStruct { x: 300 },
CustomStruct { x: 450 },
CustomStruct { x: 550 },
CustomStruct { x: 850 },
])),
}
}
}

#[pax]
#[custom(Imports)]
pub struct CustomStruct {
pub x: isize,
}
}
15 changes: 1 addition & 14 deletions pax-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use syn::{
fn pax_primitive(
input_parsed: &DeriveInput,
primitive_instance_import_path: String,
include_imports: bool,
is_custom_interpolatable: bool,
) -> proc_macro2::TokenStream {
let _original_tokens = quote! { #input_parsed }.to_string();
Expand All @@ -43,7 +42,6 @@ fn pax_primitive(
args_full_component: None,
static_property_definitions,
pascal_identifier,
include_imports,
is_custom_interpolatable,
}
.render_once()
Expand All @@ -55,7 +53,6 @@ fn pax_primitive(

fn pax_struct_only_component(
input_parsed: &DeriveInput,
include_imports: bool,
is_custom_interpolatable: bool,
) -> proc_macro2::TokenStream {
let pascal_identifier = input_parsed.ident.to_string();
Expand All @@ -70,7 +67,6 @@ fn pax_struct_only_component(

pascal_identifier: pascal_identifier.clone(),
static_property_definitions,
include_imports,
is_custom_interpolatable,
}
.render_once()
Expand Down Expand Up @@ -273,7 +269,6 @@ fn pax_full_component(
input_parsed: &DeriveInput,
is_main_component: bool,
include_fix: Option<TokenStream>,
include_imports: bool,
is_custom_interpolatable: bool,
associated_pax_file_path: Option<String>,
) -> proc_macro2::TokenStream {
Expand Down Expand Up @@ -303,7 +298,6 @@ fn pax_full_component(
associated_pax_file_path,
}),
pascal_identifier,
include_imports,
static_property_definitions,
is_custom_interpolatable,
}
Expand Down Expand Up @@ -455,17 +449,13 @@ pub fn pax(

let mut trait_impls = vec!["Clone", "Default", "Serialize", "Deserialize"];

let mut include_imports = true;
let mut is_custom_interpolatable = false;

//wipe out the above derives if `#[custom(...)]` attrs are set
if let Some(custom) = config.custom_values {
let custom_str: Vec<&str> = custom.iter().map(String::as_str).collect();
trait_impls.retain(|v| !custom_str.contains(v));

if custom.contains(&"Imports".to_string()) {
include_imports = false;
}
if custom.contains(&"Interpolatable".to_string()) {
is_custom_interpolatable = true;
}
Expand All @@ -490,7 +480,6 @@ pub fn pax(
&input,
config.is_main_component,
Some(include_fix),
include_imports,
is_custom_interpolatable,
associated_pax_file,
)
Expand All @@ -502,19 +491,17 @@ pub fn pax(
&input,
config.is_main_component,
None,
include_imports,
is_custom_interpolatable,
None,
)
} else if config.is_primitive {
pax_primitive(
&input,
config.primitive_instance_import_path.unwrap(),
include_imports,
is_custom_interpolatable,
)
} else {
pax_struct_only_component(&input, include_imports, is_custom_interpolatable)
pax_struct_only_component(&input, is_custom_interpolatable)
};

let derives: proc_macro2::TokenStream = trait_impls
Expand Down
1 change: 0 additions & 1 deletion pax-macro/src/templating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,5 @@ pub struct TemplateArgsDerivePax {
/// Shared properties
pub static_property_definitions: Vec<StaticPropertyDefinition>,
pub pascal_identifier: String,
pub include_imports: bool,
pub is_custom_interpolatable: bool,
}
19 changes: 6 additions & 13 deletions pax-macro/templates/derive_pax.stpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
<% if include_imports { %>
#[cfg(feature = "parser")]
use pax_compiler::parsing::Reflectable;
#[cfg(feature = "parser")]
use serde_json;
<% } %>

<% if args_full_component.as_ref().is_some() && args_full_component.as_ref().unwrap().is_main_component { %>
// For the main (application-root) component only, a `main` is generated for the `parser` bin target.
// This method bootstraps the parsing process, parsing not only the main/application-root component
Expand All @@ -15,14 +8,14 @@

let mut ctx = pax_compiler::parsing::ParsingContext::default();

let (mut ctx, _) = <%= pascal_identifier %>::parse_to_manifest(ctx);
let (mut ctx, _) = <<%= pascal_identifier %> as pax_compiler::parsing::Reflectable>::parse_to_manifest(ctx);

//Special-case pax_runtime_api built-ins, ensure they're imported at least once because it's a built-in but must be surfaced through
//the userland project in order to ensure deduping
ctx.import_paths.insert(pax_lang::api::Size::get_import_path());
ctx.import_paths.insert(pax_lang::api::Numeric::get_import_path());
ctx.import_paths.insert(pax_lang::api::Rotation::get_import_path());
ctx.import_paths.insert(pax_lang::api::Transform2D::get_import_path());
ctx.import_paths.insert(<pax_lang::api::Size as pax_compiler::parsing::Reflectable>::get_import_path());
ctx.import_paths.insert(<pax_lang::api::Numeric as pax_compiler::parsing::Reflectable>::get_import_path());
ctx.import_paths.insert(<pax_lang::api::Rotation as pax_compiler::parsing::Reflectable>::get_import_path());
ctx.import_paths.insert(<pax_lang::api::Transform2D as pax_compiler::parsing::Reflectable>::get_import_path());

let manifest = pax_manifest::PaxManifest {
components: ctx.component_definitions,
Expand Down Expand Up @@ -184,4 +177,4 @@ impl pax_compiler::parsing::Reflectable for <%= pascal_identifier %> {
}
}

}
}
10 changes: 0 additions & 10 deletions pax-std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ pub mod primitives {
pub struct Frame {}

#[pax]
#[custom(Imports)]
#[primitive("pax_std_primitives::group::GroupInstance")]
pub struct Group {}

#[pax]
#[custom(Imports)]
#[primitive("pax_std_primitives::scroller::ScrollerInstance")]
pub struct Scroller {
pub size_inner_pane_x: Property<Size>,
Expand All @@ -36,7 +34,6 @@ pub mod primitives {
}

#[pax]
#[custom(Imports)]
#[primitive("pax_std_primitives::rectangle::RectangleInstance")]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct Rectangle {
Expand All @@ -46,7 +43,6 @@ pub mod primitives {
}

#[pax]
#[custom(Imports)]
#[primitive("pax_std_primitives::ellipse::EllipseInstance")]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct Ellipse {
Expand All @@ -55,7 +51,6 @@ pub mod primitives {
}

#[pax]
#[custom(Imports)]
#[primitive("pax_std_primitives::path::PathInstance")]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct Path {
Expand All @@ -65,7 +60,6 @@ pub mod primitives {
}

#[pax]
#[custom(Imports)]
#[primitive("pax_std_primitives::text::TextInstance")]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct Text {
Expand All @@ -75,29 +69,25 @@ pub mod primitives {
}

#[pax]
#[custom(Imports)]
#[primitive("pax_std_primitives::checkbox::CheckboxInstance")]
pub struct Checkbox {
pub checked: Property<bool>,
}

#[pax]
#[custom(Imports)]
#[primitive("pax_std_primitives::textbox::TextboxInstance")]
pub struct Textbox {
pub text: Property<StringBox>,
}

#[pax]
#[custom(Imports)]
#[primitive("pax_std_primitives::button::ButtonInstance")]
pub struct Button {
pub label: Property<StringBox>,
pub style: Property<TextStyle>,
}

#[pax]
#[custom(Imports)]
#[primitive("pax_std_primitives::image::ImageInstance")]
pub struct Image {
pub path: Property<StringBox>,
Expand Down
Loading

0 comments on commit 01b7e95

Please sign in to comment.