Skip to content

Commit

Permalink
floats now deserialize + math funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelselleck committed Feb 23, 2024
1 parent 39d3783 commit d840033
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
10 changes: 5 additions & 5 deletions pax-manifest/src/deserializer/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,14 @@ impl<'de> de::Deserializer<'de> for PrimitiveDeserializer {
where
V: Visitor<'de>,
{
if let Ok(mut ast) = PaxParser::parse(Rule::literal_number_integer, &self.input) {
visitor.visit_i64(ast.next().unwrap().as_str().parse::<i64>().unwrap())
} else if let Ok(mut ast) = PaxParser::parse(Rule::literal_number_float, &self.input) {
if let Ok(mut ast) = PaxParser::parse(Rule::literal_number_float, &self.input) {
visitor.visit_f64(ast.next().unwrap().as_str().parse::<f64>().unwrap())
} else if let Ok(mut ast) = PaxParser::parse(Rule::inner, &self.input) {
visitor.visit_str(ast.next().unwrap().as_str())
} else if let Ok(mut ast) = PaxParser::parse(Rule::literal_number_integer, &self.input) {
visitor.visit_i64(ast.next().unwrap().as_str().parse::<i64>().unwrap())
} else if let Ok(mut ast) = PaxParser::parse(Rule::literal_boolean, &self.input) {
visitor.visit_bool(ast.next().unwrap().as_str().parse::<bool>().unwrap())
} else if let Ok(mut ast) = PaxParser::parse(Rule::inner, &self.input) {
visitor.visit_str(ast.next().unwrap().as_str())
} else {
panic!("Failed to parse: {}", &self.input)
}
Expand Down
3 changes: 2 additions & 1 deletion pax-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ description = "Core shared runtime and rendering engine for Pax"


[dependencies]
log = "0.4.20"
piet = "0.6.0"
piet-common = "0.6.0"
kurbo = "0.9.0"
Expand All @@ -18,4 +19,4 @@ lazy_static = "1.4.0"
mut_static = "5.0.0"
pax-message = {path = "../pax-message", version="0.12.0"}
wasm-bindgen = {version = "0.2.30", features=["serde-serialize"]}
pax-manifest = {version="0.12.0", path = "../pax-manifest"}
pax-manifest = {version="0.12.0", path = "../pax-manifest"}
1 change: 1 addition & 0 deletions pax-runtime/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub fn compute_tab(node: &ExpandedNode, container_tab: &TransformAndBounds) -> T
//get the size of this node (calc'd or otherwise) and use
//it as the new accumulated bounds: both for this node's children (their parent container bounds)
//and for this node itself (e.g. for specifying the size of a Rectangle node)

let new_accumulated_bounds_and_current_node_size =
{ node.get_size_computed(container_tab.bounds) };

Expand Down
21 changes: 21 additions & 0 deletions pax-runtime/src/math/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,30 @@ impl<W: Space> Sub for Vector2<W> {
}
}

impl<W: Space> Sub<f64> for Vector2<W> {
type Output = Vector2<W>;
fn sub(self, rhs: f64) -> Self::Output {
Self::Output::new(self.x - rhs, self.y - rhs)
}
}

impl<W: Space> Add<f64> for Vector2<W> {
type Output = Vector2<W>;
fn add(self, rhs: f64) -> Self::Output {
Self::Output::new(self.x + rhs, self.y + rhs)
}
}

impl<W: Space> Div<f64> for Vector2<W> {
type Output = Vector2<W>;
fn div(self, rhs: f64) -> Self::Output {
Self::Output::new(self.x / rhs, self.y / rhs)
}
}

impl<W: Space> Div for Vector2<W> {
type Output = Vector2<W>;
fn div(self, rhs: Vector2<W>) -> Self::Output {
Self::Output::new(self.x / rhs.x, self.y / rhs.y)
}
}
1 change: 1 addition & 0 deletions pax-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ serde_json = {version="1.0.95", optional = true}
pax-manifest = {path = "../pax-manifest", version="0.12.0"}
pax-runtime = {path = "../pax-runtime", version="0.12.0"}
serde = { version = "1.0.159", features=["derive"]}
log = "0.4.20"

[features]
parser = ["pax-engine/parser", "dep:pax-compiler", "dep:serde_json"]
4 changes: 1 addition & 3 deletions pax-std/pax-std-primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,4 @@ pax-message = {path = "../../pax-message", version="0.12.0" }
piet = "0.6.0"
piet-common = "0.6.0"
kurbo = "0.9.0"

[features]
Text = []
log = "0.4.20"

0 comments on commit d840033

Please sign in to comment.