From f5e3ab53e74d35d8017a63636f575dd01b82ad66 Mon Sep 17 00:00:00 2001 From: Samuel Selleck Date: Wed, 14 Feb 2024 14:23:47 -0800 Subject: [PATCH 01/10] fixed button type during pointer move --- pax-chassis-web/interface/src/events/listeners.ts | 10 ++++++++-- pax-runtime/src/rendering.rs | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pax-chassis-web/interface/src/events/listeners.ts b/pax-chassis-web/interface/src/events/listeners.ts index a78ff3f08..8956f70d2 100644 --- a/pax-chassis-web/interface/src/events/listeners.ts +++ b/pax-chassis-web/interface/src/events/listeners.ts @@ -41,6 +41,7 @@ export function setupEventListeners(chassis: PaxChassisWeb, layer: any) { // @ts-ignore layer.addEventListener('click', (evt) => { + let clickEvent = { "Click": { "x": evt.clientX, @@ -72,11 +73,13 @@ export function setupEventListeners(chassis: PaxChassisWeb, layer: any) { }, true); // @ts-ignore layer.addEventListener('mousemove', (evt) => { + // @ts-ignore + let button = window.current_button || 'Left'; let event = { "MouseMove": { "x": evt.clientX, "y": evt.clientY, - "button": getMouseButton(evt), + "button": button, "modifiers": convertModifiers(evt) } }; @@ -97,6 +100,9 @@ export function setupEventListeners(chassis: PaxChassisWeb, layer: any) { }, {"passive": true, "capture": true}); // @ts-ignore layer.addEventListener('mousedown', (evt) => { + let button = getMouseButton(evt); + // @ts-ignore + window.current_button = button; let event = { "MouseDown": { "x": evt.clientX, @@ -231,4 +237,4 @@ export function setupEventListeners(chassis: PaxChassisWeb, layer: any) { }; chassis.interrupt(JSON.stringify(event), []); }, true); -} \ No newline at end of file +} diff --git a/pax-runtime/src/rendering.rs b/pax-runtime/src/rendering.rs index cfe1d5e32..b77a0d724 100644 --- a/pax-runtime/src/rendering.rs +++ b/pax-runtime/src/rendering.rs @@ -6,7 +6,8 @@ use std::ops::{Add, Div, Mul, Sub}; use std::rc::Rc; use crate::api::{CommonProperties, RenderContext}; -pub use kurbo::Affine; +pub use kurbo; +use kurbo::Affine; use piet::{Color, StrokeStyle}; use crate::api::{ArgsScroll, Layer, Size}; From 066e782fc4d778480ebb3054f0594fe7d9cd2144 Mon Sep 17 00:00:00 2001 From: Samuel Selleck Date: Wed, 14 Feb 2024 19:39:42 -0800 Subject: [PATCH 02/10] WIP new point/vector/transform system --- pax-engine/src/lib.rs | 1 + pax-runtime/src/lib.rs | 1 + pax-runtime/src/math.rs | 31 +++++++++ pax-runtime/src/math/point.rs | 60 ++++++++++++++++++ pax-runtime/src/math/transform.rs | 19 ++++++ pax-runtime/src/math/vector.rs | 92 +++++++++++++++++++++++++++ pax-runtime/src/rendering.rs | 102 ++++-------------------------- 7 files changed, 217 insertions(+), 89 deletions(-) create mode 100644 pax-runtime/src/math.rs create mode 100644 pax-runtime/src/math/point.rs create mode 100644 pax-runtime/src/math/transform.rs create mode 100644 pax-runtime/src/math/vector.rs diff --git a/pax-engine/src/lib.rs b/pax-engine/src/lib.rs index 666ece346..144ca5e5c 100644 --- a/pax-engine/src/lib.rs +++ b/pax-engine/src/lib.rs @@ -2,6 +2,7 @@ pub extern crate pax_macro; pub use pax_macro::*; pub use pax_runtime::api; +pub use pax_runtime::math; pub use pax_runtime::rendering; pub use pax_runtime::api::log; diff --git a/pax-runtime/src/lib.rs b/pax-runtime/src/lib.rs index 1291eab70..957089d70 100644 --- a/pax-runtime/src/lib.rs +++ b/pax-runtime/src/lib.rs @@ -10,6 +10,7 @@ pub mod engine; pub mod expressions; pub mod form_event; pub mod layout; +pub mod math; pub mod numeric; pub mod properties; pub mod rendering; diff --git a/pax-runtime/src/math.rs b/pax-runtime/src/math.rs new file mode 100644 index 000000000..7fac61bea --- /dev/null +++ b/pax-runtime/src/math.rs @@ -0,0 +1,31 @@ +use std::ops::Mul; + +use kurbo::Affine; + +mod point; +mod transform; +mod vector; + +pub use point::Point2; +pub use vector::Vector2; + +pub trait Space: Copy + Clone {} + +#[derive(Copy, Clone)] +pub struct Generic; + +impl Space for Generic {} + +// TODO remove after Affine not used +impl Mul> for Affine { + type Output = Point2; + + #[inline] + fn mul(self, other: Point2) -> Point2 { + let coeffs = self.as_coeffs(); + Self::Output::new( + coeffs[0] * other.x + coeffs[2] * other.y + coeffs[4], + coeffs[1] * other.x + coeffs[3] * other.y + coeffs[5], + ) + } +} diff --git a/pax-runtime/src/math/point.rs b/pax-runtime/src/math/point.rs new file mode 100644 index 000000000..86b2f3877 --- /dev/null +++ b/pax-runtime/src/math/point.rs @@ -0,0 +1,60 @@ +use std::{ + marker::PhantomData, + ops::{Add, Sub}, +}; + +use super::{vector::Vector2, Generic, Space}; + +#[derive(Copy, Clone, Default, Debug)] +pub struct Point2 { + pub x: f64, + pub y: f64, + _panthom: PhantomData, +} + +impl Point2 { + pub fn new(x: f64, y: f64) -> Self { + Point2 { + x, + y, + _panthom: PhantomData, + } + } + + pub fn to_vector(self) -> Vector2 { + Vector2::new(self.x, self.y) + } + + pub fn to_world(self) -> Point2 { + Point2::new(self.x, self.y) + } + + pub fn midpoint_towards(self, other: Self) -> Self { + self.lerp_towards(other, 1.0 / 2.0) + } + + pub fn lerp_towards(self, other: Self, l: f64) -> Self { + let v = other - self; + self + l * v + } +} + +impl Sub for Point2 { + type Output = Vector2; + fn sub(self, rhs: Point2) -> Self::Output { + Self::Output::new(self.x - rhs.x, self.y - rhs.y) + } +} + +impl Add> for Point2 { + type Output = Point2; + fn add(self, rhs: Vector2) -> Self::Output { + Self::Output::new(self.x + rhs.x, self.y + rhs.y) + } +} +impl Add> for Vector2 { + type Output = Point2; + fn add(self, rhs: Point2) -> Self::Output { + Self::Output::new(self.x + rhs.x, self.y + rhs.y) + } +} diff --git a/pax-runtime/src/math/transform.rs b/pax-runtime/src/math/transform.rs new file mode 100644 index 000000000..176f81314 --- /dev/null +++ b/pax-runtime/src/math/transform.rs @@ -0,0 +1,19 @@ +use std::marker::PhantomData; + +use super::{vector::Vector2, Space}; + +pub struct Transform2 { + m: [f64; 6], + _panthom_from: PhantomData, + _panthom_to: PhantomData, +} + +impl Transform2 { + pub fn from_coefs(m: [f64; 6]) -> Self { + Self { + m, + _panthom_from: PhantomData, + _panthom_to: PhantomData, + } + } +} diff --git a/pax-runtime/src/math/vector.rs b/pax-runtime/src/math/vector.rs new file mode 100644 index 000000000..12e62e4a1 --- /dev/null +++ b/pax-runtime/src/math/vector.rs @@ -0,0 +1,92 @@ +use std::{ + marker::PhantomData, + ops::{Add, Div, Mul, Sub}, +}; + +use super::{Generic, Point2, Space}; + +#[derive(Copy, Clone, Default, Debug)] +pub struct Vector2 { + pub x: f64, + pub y: f64, + _panthom: PhantomData, +} + +impl Vector2 { + pub fn new(x: f64, y: f64) -> Self { + Vector2 { + x, + y, + _panthom: PhantomData, + } + } + pub fn normal(&self) -> Self { + Self::new(-self.y, self.x) + } + + pub fn length_squared(&self) -> f64 { + self.x * self.x + self.y * self.y + } + + pub fn length(&self) -> f64 { + self.length_squared().sqrt() + } + + pub fn project_onto(self, axis: Vector2) -> f64 { + let dot_product = self * axis; + dot_product / axis.length_squared() + } + + pub fn to_point(self) -> Point2 { + Point2::new(self.x, self.y) + } + + pub fn to_world(self) -> Point2 { + Point2::new(self.x, self.y) + } +} + +impl Mul for Vector2 { + type Output = f64; + + fn mul(self, rhs: Vector2) -> Self::Output { + self.x * rhs.x + self.y * rhs.y + } +} + +impl Mul for Vector2 { + type Output = Self; + + fn mul(self, rhs: f64) -> Self::Output { + Vector2::new(self.x * rhs, self.y * rhs) + } +} +impl Mul> for f64 { + type Output = Vector2; + + fn mul(self, rhs: Vector2) -> Self::Output { + Vector2::new(rhs.x * self, rhs.y * self) + } +} + +impl Add for Vector2 { + type Output = Vector2; + + fn add(self, rhs: Vector2) -> Self::Output { + Self::Output::new(self.x + rhs.x, self.y + rhs.y) + } +} + +impl Sub for Vector2 { + type Output = Vector2; + fn sub(self, rhs: Vector2) -> Self::Output { + Self::Output::new(self.x - rhs.x, self.y - rhs.y) + } +} + +impl Div for Vector2 { + type Output = Vector2; + fn div(self, rhs: f64) -> Self::Output { + Self::Output::new(self.x / rhs, self.y / rhs) + } +} diff --git a/pax-runtime/src/rendering.rs b/pax-runtime/src/rendering.rs index b77a0d724..99d7b6677 100644 --- a/pax-runtime/src/rendering.rs +++ b/pax-runtime/src/rendering.rs @@ -1,11 +1,12 @@ use std::any::Any; use std::cell::RefCell; +use super::math::Point2; use std::iter; -use std::ops::{Add, Div, Mul, Sub}; use std::rc::Rc; use crate::api::{CommonProperties, RenderContext}; +use crate::math::Generic; pub use kurbo; use kurbo::Affine; use piet::{Color, StrokeStyle}; @@ -34,81 +35,6 @@ pub struct InstantiationArgs { pub component_type_id: String, } -#[derive(Copy, Clone, Default, Debug)] -pub struct Point2D { - pub x: f64, - pub y: f64, -} - -impl Add for Point2D { - type Output = Point2D; - - fn add(self, rhs: Point2D) -> Self::Output { - Self::Output { - x: self.x + rhs.x, - y: self.y + rhs.y, - } - } -} - -impl Sub for Point2D { - type Output = Point2D; - fn sub(self, rhs: Point2D) -> Self::Output { - Self::Output { - x: self.x - rhs.x, - y: self.y - rhs.y, - } - } -} - -impl Div for Point2D { - type Output = Point2D; - fn div(self, rhs: f64) -> Self::Output { - Self::Output { - x: self.x / rhs, - y: self.y / rhs, - } - } -} - -impl Point2D { - fn subtract(self, other: Point2D) -> Self { - Self { - x: self.x - other.x, - y: self.y - other.y, - } - } - - fn dot(self, other: Point2D) -> f64 { - self.x * other.x + self.y * other.y - } - - fn normal(self) -> Self { - Self { - x: -self.y, - y: self.x, - } - } - - fn project_onto(self, axis: Point2D) -> f64 { - let dot_product = self.dot(axis); - dot_product / (axis.x.powi(2) + axis.y.powi(2)) - } -} - -impl Mul for Affine { - type Output = Point2D; - - #[inline] - fn mul(self, other: Point2D) -> Point2D { - let coeffs = self.as_coeffs(); - Point2D { - x: coeffs[0] * other.x + coeffs[2] * other.y + coeffs[4], - y: coeffs[1] * other.x + coeffs[3] * other.y + coeffs[5], - } - } -} - /// Stores the computed transform and the pre-transform bounding box (where the /// other corner is the origin). Useful for ray-casting, along with #[cfg_attr(debug_assertions, derive(Debug))] @@ -120,18 +46,14 @@ pub struct TransformAndBounds { } impl TransformAndBounds { - pub fn corners(&self) -> [Point2D; 4] { + pub fn corners(&self) -> [Point2; 4] { let width = self.bounds.0; let height = self.bounds.1; - let top_left = self.transform * Point2D { x: 0.0, y: 0.0 }; - let top_right = self.transform * Point2D { x: width, y: 0.0 }; - let bottom_left = self.transform * Point2D { x: 0.0, y: height }; - let bottom_right = self.transform - * Point2D { - x: width, - y: height, - }; + let top_left = self.transform * Point2::new(0.0, 0.0); + let top_right = self.transform * Point2::new(width, 0.0); + let bottom_left = self.transform * Point2::new(0.0, height); + let bottom_right = self.transform * Point2::new(width, height); [top_left, top_right, bottom_right, bottom_left] } @@ -142,13 +64,15 @@ impl TransformAndBounds { let corners_other = other.corners(); for i in 0..2 { - let axis = corners_self[i].subtract(corners_self[(i + 1) % 4]).normal(); + let axis = (corners_self[i] - corners_self[(i + 1) % 4]).normal(); - let self_projections: Vec<_> = - corners_self.iter().map(|&p| p.project_onto(axis)).collect(); + let self_projections: Vec<_> = corners_self + .iter() + .map(|&p| p.to_vector().project_onto(axis)) + .collect(); let other_projections: Vec<_> = corners_other .iter() - .map(|&p| p.project_onto(axis)) + .map(|&p| p.to_vector().project_onto(axis)) .collect(); let (min_self, max_self) = min_max_projections(&self_projections); From 01ba5ef40e7ce703dd645c70f645d32d6d183455 Mon Sep 17 00:00:00 2001 From: Samuel Selleck Date: Wed, 14 Feb 2024 20:15:38 -0800 Subject: [PATCH 03/10] minimal transform type finished --- pax-runtime/src/math.rs | 1 + pax-runtime/src/math/transform.rs | 90 +++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/pax-runtime/src/math.rs b/pax-runtime/src/math.rs index 7fac61bea..9b0047865 100644 --- a/pax-runtime/src/math.rs +++ b/pax-runtime/src/math.rs @@ -7,6 +7,7 @@ mod transform; mod vector; pub use point::Point2; +pub use transform::Transform2; pub use vector::Vector2; pub trait Space: Copy + Clone {} diff --git a/pax-runtime/src/math/transform.rs b/pax-runtime/src/math/transform.rs index 176f81314..69b975e7a 100644 --- a/pax-runtime/src/math/transform.rs +++ b/pax-runtime/src/math/transform.rs @@ -1,19 +1,101 @@ -use std::marker::PhantomData; +use std::{marker::PhantomData, ops::Mul}; -use super::{vector::Vector2, Space}; +//----------------------------------------------------------- +// Pax matrix/transform class heavily borrows from kurbos +// transform impl (copy/pasted initially with some modifications) +// curbo crate: https://www.michaelfbryan.com/arcs/kurbo/index.html +// original source code: https://www.michaelfbryan.com/arcs/src/kurbo/affine.rs.html#10 +// kurbo is distributed under the following (MIT) license: +// "Copyright (c) 2018 Raph Levien -pub struct Transform2 { +// Permission is hereby granted, free of charge, to any +// person obtaining a copy of this software and associated +// documentation files (the "Software"), to deal in the +// Software without restriction, including without +// limitation the rights to use, copy, modify, merge, +// publish, distribute, sublicense, and/or sell copies of +// the Software, and to permit persons to whom the Software +// is furnished to do so, subject to the following +// conditions: +// The above copyright notice and this permission notice +// shall be included in all copies or substantial portions +// of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE." +//----------------------------------------------------------- + +use super::{Space, Vector2}; + +#[derive(Clone, Copy, Debug, PartialEq)] +pub struct Transform2 { m: [f64; 6], _panthom_from: PhantomData, _panthom_to: PhantomData, } impl Transform2 { - pub fn from_coefs(m: [f64; 6]) -> Self { + pub fn new(m: [f64; 6]) -> Self { Self { m, _panthom_from: PhantomData, _panthom_to: PhantomData, } } + + pub fn unit() -> Self { + Self::new([1.0, 0.0, 0.0, 1.0, 0.0, 0.0]) + } + + pub fn scale(s: f64) -> Self { + Self::new([s, 0.0, 0.0, s, 0.0, 0.0]) + } + + pub fn rotate(th: f64) -> Self { + let (s, c) = th.sin_cos(); + Self::new([c, s, -s, c, 0.0, 0.0]) + } + + pub fn translate(p: Vector2) -> Self { + Self::new([1.0, 0.0, 0.0, 1.0, p.x, p.y]) + } + + pub fn determinant(self) -> f64 { + self.m[0] * self.m[3] - self.m[1] * self.m[2] + } + + /// Produces NaN values when the determinant is zero. + pub fn inverse(self) -> Transform2 { + let inv_det = self.determinant().recip(); + Transform2::::new([ + inv_det * self.m[3], + -inv_det * self.m[1], + -inv_det * self.m[2], + inv_det * self.m[0], + inv_det * (self.m[2] * self.m[5] - self.m[3] * self.m[4]), + inv_det * (self.m[1] * self.m[4] - self.m[0] * self.m[5]), + ]) + } +} + +impl Mul> for Transform2 { + type Output = Transform2; + + fn mul(self, rhs: Transform2) -> Self::Output { + Self::Output::new([ + self.m[0] * rhs.m[0] + self.m[2] * rhs.m[1], + self.m[1] * rhs.m[0] + self.m[3] * rhs.m[1], + self.m[0] * rhs.m[2] + self.m[2] * rhs.m[3], + self.m[1] * rhs.m[2] + self.m[3] * rhs.m[3], + self.m[0] * rhs.m[4] + self.m[2] * rhs.m[5] + self.m[4], + self.m[1] * rhs.m[4] + self.m[3] * rhs.m[5] + self.m[5], + ]) + } } From 92af8327fbf01bf0799211e5ce54594d392c0e4e Mon Sep 17 00:00:00 2001 From: Samuel Selleck Date: Thu, 15 Feb 2024 22:16:01 -0800 Subject: [PATCH 04/10] new math module done --- .../src/core_graphics_c_bridge.rs | 3 +- pax-chassis-web/src/lib.rs | 27 ++--- pax-engine/src/lib.rs | 1 + pax-runtime/src/engine/design_utils.rs | 3 + pax-runtime/src/engine/expanded_node.rs | 17 ++- pax-runtime/src/engine/mod.rs | 17 ++- pax-runtime/src/layout.rs | 14 +-- pax-runtime/src/lib.rs | 2 +- pax-runtime/src/math/point.rs | 28 ++++- pax-runtime/src/math/transform.rs | 108 +++++++++++++----- pax-runtime/src/math/vector.rs | 44 ++++++- pax-runtime/src/properties.rs | 10 +- pax-runtime/src/rendering.rs | 11 +- pax-std/pax-std-primitives/src/button.rs | 2 +- pax-std/pax-std-primitives/src/checkbox.rs | 2 +- pax-std/pax-std-primitives/src/ellipse.rs | 2 +- pax-std/pax-std-primitives/src/image.rs | 6 +- pax-std/pax-std-primitives/src/path.rs | 5 +- pax-std/pax-std-primitives/src/rectangle.rs | 2 +- pax-std/pax-std-primitives/src/text.rs | 2 +- pax-std/pax-std-primitives/src/textbox.rs | 2 +- 21 files changed, 222 insertions(+), 86 deletions(-) create mode 100644 pax-runtime/src/engine/design_utils.rs diff --git a/pax-chassis-common/src/core_graphics_c_bridge.rs b/pax-chassis-common/src/core_graphics_c_bridge.rs index 049fa1269..cbaf8abb3 100644 --- a/pax-chassis-common/src/core_graphics_c_bridge.rs +++ b/pax-chassis-common/src/core_graphics_c_bridge.rs @@ -8,6 +8,7 @@ use std::mem::{transmute, ManuallyDrop}; use std::os::raw::c_char; use core_graphics::context::CGContext; +use pax_runtime::math::Point2; use piet_coregraphics::CoreGraphicsContext; use flexbuffers; @@ -95,7 +96,7 @@ pub extern "C" fn pax_interrupt( NativeInterrupt::Click(args) => { let prospective_hit = engine .runtime_context - .get_topmost_element_beneath_ray((args.x, args.y)); + .get_topmost_element_beneath_ray(Point2::new(args.x, args.y)); match prospective_hit { Some(topmost_node) => { let modifiers = args diff --git a/pax-chassis-web/src/lib.rs b/pax-chassis-web/src/lib.rs index b4c4a5bdf..4fc0a61fe 100644 --- a/pax-chassis-web/src/lib.rs +++ b/pax-chassis-web/src/lib.rs @@ -5,6 +5,7 @@ use pax_runtime::api::ArgsButtonClick; use pax_runtime::api::ArgsCheckboxChange; use pax_runtime::api::ArgsTextboxChange; use pax_runtime::api::RenderContext; +use pax_runtime::math::Point2; use pax_runtime::ExpressionTable; use std::cell::RefCell; @@ -215,7 +216,7 @@ impl PaxChassisWeb { NativeInterrupt::Click(args) => { let prospective_hit = engine .runtime_context - .get_topmost_element_beneath_ray((args.x, args.y)); + .get_topmost_element_beneath_ray(Point2::new(args.x, args.y)); if let Some(topmost_node) = prospective_hit { let args_click = ArgsClick { mouse: MouseEventArgs { @@ -245,7 +246,7 @@ impl PaxChassisWeb { NativeInterrupt::Clap(args) => { let prospective_hit = engine .runtime_context - .get_topmost_element_beneath_ray((args.x, args.y)); + .get_topmost_element_beneath_ray(Point2::new(args.x, args.y)); if let Some(topmost_node) = prospective_hit { let args_clap = ArgsClap { x: args.x, @@ -258,7 +259,7 @@ impl PaxChassisWeb { let first_touch = args.touches.get(0).unwrap(); let prospective_hit = engine .runtime_context - .get_topmost_element_beneath_ray((first_touch.x, first_touch.y)); + .get_topmost_element_beneath_ray(Point2::new(first_touch.x, first_touch.y)); if let Some(topmost_node) = prospective_hit { let touches = args.touches.iter().map(|x| Touch::from(x)).collect(); let args_touch_start = ArgsTouchStart { touches }; @@ -273,7 +274,7 @@ impl PaxChassisWeb { let first_touch = args.touches.get(0).unwrap(); let prospective_hit = engine .runtime_context - .get_topmost_element_beneath_ray((first_touch.x, first_touch.y)); + .get_topmost_element_beneath_ray(Point2::new(first_touch.x, first_touch.y)); if let Some(topmost_node) = prospective_hit { let touches = args.touches.iter().map(|x| Touch::from(x)).collect(); let args_touch_move = ArgsTouchMove { touches }; @@ -288,7 +289,7 @@ impl PaxChassisWeb { let first_touch = args.touches.get(0).unwrap(); let prospective_hit = engine .runtime_context - .get_topmost_element_beneath_ray((first_touch.x, first_touch.y)); + .get_topmost_element_beneath_ray(Point2::new(first_touch.x, first_touch.y)); if let Some(topmost_node) = prospective_hit { let touches = args.touches.iter().map(|x| Touch::from(x)).collect(); let args_touch_end = ArgsTouchEnd { touches }; @@ -360,7 +361,7 @@ impl PaxChassisWeb { NativeInterrupt::DoubleClick(args) => { let prospective_hit = engine .runtime_context - .get_topmost_element_beneath_ray((args.x, args.y)); + .get_topmost_element_beneath_ray(Point2::new(args.x, args.y)); if let Some(topmost_node) = prospective_hit { let args_double_click = ArgsDoubleClick { mouse: MouseEventArgs { @@ -384,7 +385,7 @@ impl PaxChassisWeb { NativeInterrupt::MouseMove(args) => { let prospective_hit = engine .runtime_context - .get_topmost_element_beneath_ray((args.x, args.y)); + .get_topmost_element_beneath_ray(Point2::new(args.x, args.y)); if let Some(topmost_node) = prospective_hit { let args_mouse_move = ArgsMouseMove { mouse: MouseEventArgs { @@ -408,7 +409,7 @@ impl PaxChassisWeb { NativeInterrupt::Wheel(args) => { let prospective_hit = engine .runtime_context - .get_topmost_element_beneath_ray((args.x, args.y)); + .get_topmost_element_beneath_ray(Point2::new(args.x, args.y)); if let Some(topmost_node) = prospective_hit { let modifiers = args .modifiers @@ -428,7 +429,7 @@ impl PaxChassisWeb { NativeInterrupt::MouseDown(args) => { let prospective_hit = engine .runtime_context - .get_topmost_element_beneath_ray((args.x, args.y)); + .get_topmost_element_beneath_ray(Point2::new(args.x, args.y)); if let Some(topmost_node) = prospective_hit { let args_mouse_down = ArgsMouseDown { mouse: MouseEventArgs { @@ -452,7 +453,7 @@ impl PaxChassisWeb { NativeInterrupt::MouseUp(args) => { let prospective_hit = engine .runtime_context - .get_topmost_element_beneath_ray((args.x, args.y)); + .get_topmost_element_beneath_ray(Point2::new(args.x, args.y)); if let Some(topmost_node) = prospective_hit { let args_mouse_up = ArgsMouseUp { mouse: MouseEventArgs { @@ -472,7 +473,7 @@ impl PaxChassisWeb { NativeInterrupt::MouseOver(args) => { let prospective_hit = engine .runtime_context - .get_topmost_element_beneath_ray((args.x, args.y)); + .get_topmost_element_beneath_ray(Point2::new(args.x, args.y)); if let Some(topmost_node) = prospective_hit { let args_mouse_over = ArgsMouseOver { mouse: MouseEventArgs { @@ -496,7 +497,7 @@ impl PaxChassisWeb { NativeInterrupt::MouseOut(args) => { let prospective_hit = engine .runtime_context - .get_topmost_element_beneath_ray((args.x, args.y)); + .get_topmost_element_beneath_ray(Point2::new(args.x, args.y)); if let Some(topmost_node) = prospective_hit { let args_mouse_out = ArgsMouseOut { mouse: MouseEventArgs { @@ -520,7 +521,7 @@ impl PaxChassisWeb { NativeInterrupt::ContextMenu(args) => { let prospective_hit = engine .runtime_context - .get_topmost_element_beneath_ray((args.x, args.y)); + .get_topmost_element_beneath_ray(Point2::new(args.x, args.y)); if let Some(topmost_node) = prospective_hit { let args_context_menu = ArgsContextMenu { mouse: MouseEventArgs { diff --git a/pax-engine/src/lib.rs b/pax-engine/src/lib.rs index 144ca5e5c..7c264a5d4 100644 --- a/pax-engine/src/lib.rs +++ b/pax-engine/src/lib.rs @@ -2,6 +2,7 @@ pub extern crate pax_macro; pub use pax_macro::*; pub use pax_runtime::api; +pub use pax_runtime::design_utils; pub use pax_runtime::math; pub use pax_runtime::rendering; diff --git a/pax-runtime/src/engine/design_utils.rs b/pax-runtime/src/engine/design_utils.rs new file mode 100644 index 000000000..f3b0c1bf7 --- /dev/null +++ b/pax-runtime/src/engine/design_utils.rs @@ -0,0 +1,3 @@ +// For the designer +// What should be exposed to the user? +pub use crate::ExpandedNode; diff --git a/pax-runtime/src/engine/expanded_node.rs b/pax-runtime/src/engine/expanded_node.rs index 73475df8a..0b820b466 100644 --- a/pax-runtime/src/engine/expanded_node.rs +++ b/pax-runtime/src/engine/expanded_node.rs @@ -5,6 +5,7 @@ use crate::constants::{ MOUSE_OVER_HANDLERS, MOUSE_UP_HANDLERS, SCROLL_HANDLERS, TEXTBOX_CHANGE_HANDLERS, TOUCH_END_HANDLERS, TOUCH_MOVE_HANDLERS, TOUCH_START_HANDLERS, WHEEL_HANDLERS, }; +use crate::math::{Point2, Transform2}; use crate::Globals; #[cfg(debug_assertions)] use core::fmt; @@ -12,8 +13,6 @@ use std::any::Any; use std::cell::RefCell; use std::rc::{Rc, Weak}; -use kurbo::Point; - use crate::api::{ ArgsButtonClick, ArgsCheckboxChange, ArgsClap, ArgsClick, ArgsContextMenu, ArgsDoubleClick, ArgsKeyDown, ArgsKeyPress, ArgsKeyUp, ArgsMouseDown, ArgsMouseMove, ArgsMouseOut, @@ -349,6 +348,16 @@ impl ExpandedNode { self.instance_node.render(&self, context, rcs); } + pub fn local_raycast(&self, context: &RuntimeContext, point: Point2) -> Vec> { + let lp = self.layout_properties.borrow(); + let transform = if let Some(v) = lp.as_ref() { + v.computed_tab.transform + } else { + Transform2::identity() + }; + context.get_elements_beneath_ray(transform * point, false, vec![]) + } + /// Manages unpacking an Rc>, downcasting into /// the parameterized `target_type`, and executing a provided closure `body` in the /// context of that unwrapped variant (including support for mutable operations), @@ -412,7 +421,7 @@ impl ExpandedNode { /// Determines whether the provided ray, orthogonal to the view plane, /// intersects this `ExpandedNode`. - pub fn ray_cast_test(&self, ray: &(f64, f64)) -> bool { + pub fn ray_cast_test(&self, ray: Point2) -> bool { // Don't vacuously hit for `invisible_to_raycasting` nodes if self.instance_node.base().flags().invisible_to_raycasting { return false; @@ -422,7 +431,7 @@ impl ExpandedNode { let computed_tab = &props.as_ref().unwrap().computed_tab; let inverted_transform = computed_tab.transform.inverse(); - let transformed_ray = inverted_transform * Point { x: ray.0, y: ray.1 }; + let transformed_ray = inverted_transform * ray; let relevant_bounds = computed_tab.bounds; diff --git a/pax-runtime/src/engine/mod.rs b/pax-runtime/src/engine/mod.rs index 1cfbc6332..b667077ee 100644 --- a/pax-runtime/src/engine/mod.rs +++ b/pax-runtime/src/engine/mod.rs @@ -8,17 +8,20 @@ use std::rc::Rc; use pax_message::{NativeMessage, OcclusionPatch}; use crate::api::{ - log, CommonProperties, Interpolatable, Layer, NodeContext, OcclusionLayerGen, RenderContext, + CommonProperties, Interpolatable, Layer, NodeContext, OcclusionLayerGen, RenderContext, TransitionManager, }; +use crate::math::Point2; use piet::InterpolationMode; use crate::declarative_macros::{handle_vtable_update, handle_vtable_update_optional}; use crate::{ - Affine, ComponentInstance, ExpressionContext, InstanceNode, RuntimeContext, + ComponentInstance, ExpressionContext, InstanceNode, RuntimeContext, RuntimePropertiesStackFrame, TransformAndBounds, }; +pub mod design_utils; + /// The atomic unit of rendering; also the container for each unique tuple of computed properties. /// Represents an expanded node, that is "expanded" in the context of computed properties and repeat expansion. /// For example, a Rectangle inside `for i in 0..3` and a `for j in 0..4` would have 12 expanded nodes representing the 12 virtual Rectangles in the @@ -253,12 +256,14 @@ impl PaxEngine { logger: crate::api::PlatformSpecificLogger, viewport_size: (f64, f64), ) -> Self { + use crate::math::Transform2; + crate::api::register_logger(logger); let globals = Globals { frames_elapsed: 0, viewport: TransformAndBounds { - transform: Affine::default(), + transform: Transform2::identity(), bounds: viewport_size, }, }; @@ -281,12 +286,14 @@ impl PaxEngine { viewport_size: (f64, f64), designtime: Rc>, ) -> Self { + use crate::math::Transform2; + crate::api::register_logger(logger); let globals = Globals { frames_elapsed: 0, viewport: TransformAndBounds { - transform: Affine::default(), + transform: Transform2::default(), bounds: viewport_size, }, designtime: designtime.clone(), @@ -388,7 +395,7 @@ impl PaxEngine { pub fn get_focused_element(&self) -> Option> { let (x, y) = self.runtime_context.globals().viewport.bounds; self.runtime_context - .get_topmost_element_beneath_ray((x / 2.0, y / 2.0)) + .get_topmost_element_beneath_ray(Point2::new(x / 2.0, y / 2.0)) } /// Called by chassis when viewport size changes, e.g. with native window resizes diff --git a/pax-runtime/src/layout.rs b/pax-runtime/src/layout.rs index 0c182efa9..28903787c 100644 --- a/pax-runtime/src/layout.rs +++ b/pax-runtime/src/layout.rs @@ -1,6 +1,6 @@ use crate::api::{Axis, Size, Transform2D}; +use crate::math::{Generic, Transform2, Vector2}; use crate::{ExpandedNode, TransformAndBounds}; -use kurbo::Affine; /// For the `current_expanded_node` attached to `ptc`, calculates and returns a new [`crate::rendering::TransformAndBounds`] a.k.a. "tab". /// Intended as a helper method to be called during properties computation, for creating a new tab to attach to `ptc` for downstream calculations. @@ -119,7 +119,7 @@ pub trait ComputableTransform { &self, node_size: (f64, f64), container_bounds: (f64, f64), - ) -> Affine; + ) -> Transform2; } impl ComputableTransform for Transform2D { @@ -129,7 +129,7 @@ impl ComputableTransform for Transform2D { &self, node_size: (f64, f64), container_bounds: (f64, f64), - ) -> Affine { + ) -> Transform2 { //Three broad strokes: // a.) compute anchor // b.) decompose "vanilla" affine matrix @@ -137,7 +137,7 @@ impl ComputableTransform for Transform2D { // Compute anchor let anchor_transform = match &self.anchor { - Some(anchor) => Affine::translate(( + Some(anchor) => Transform2::::translate(Vector2::new( match anchor[0] { Size::Pixels(pix) => -pix.get_as_float(), Size::Percent(per) => -node_size.0 * (per / 100.0), @@ -154,7 +154,7 @@ impl ComputableTransform for Transform2D { }, )), //No anchor applied: treat as 0,0; identity matrix - None => Affine::default(), + None => Transform2::default(), }; //decompose vanilla affine matrix and pack into `Affine` @@ -199,12 +199,12 @@ impl ComputableTransform for Transform2D { let f = translate_y; let coeffs = [a, b, c, d, e, f]; - let transform = Affine::new(coeffs); + let transform = Transform2::new(coeffs); // Compute and combine previous_transform let previous_transform = match &self.previous { Some(previous) => (*previous).compute_transform2d_matrix(node_size, container_bounds), - None => Affine::default(), + None => Transform2::default(), }; transform * anchor_transform * previous_transform diff --git a/pax-runtime/src/lib.rs b/pax-runtime/src/lib.rs index 957089d70..48b1fac0e 100644 --- a/pax-runtime/src/lib.rs +++ b/pax-runtime/src/lib.rs @@ -1,4 +1,3 @@ -pub use kurbo::Affine; pub use piet::{Color, Error, StrokeStyle}; pub mod api; @@ -26,3 +25,4 @@ pub use crate::properties::*; pub use crate::rendering::*; pub use crate::repeat::*; pub use crate::slot::*; +pub use engine::design_utils; diff --git a/pax-runtime/src/math/point.rs b/pax-runtime/src/math/point.rs index 86b2f3877..9caf065c4 100644 --- a/pax-runtime/src/math/point.rs +++ b/pax-runtime/src/math/point.rs @@ -5,13 +5,39 @@ use std::{ use super::{vector::Vector2, Generic, Space}; -#[derive(Copy, Clone, Default, Debug)] pub struct Point2 { pub x: f64, pub y: f64, _panthom: PhantomData, } +// Implement Clone, Copy, PartialEq, etc manually, as +// to not require the Space to implement these. + +impl Clone for Point2 { + fn clone(&self) -> Self { + Self { + x: self.x, + y: self.y, + _panthom: PhantomData, + } + } +} + +impl Copy for Point2 {} + +impl PartialEq for Point2 { + fn eq(&self, other: &Self) -> bool { + self.x == other.x && self.y == other.y + } +} + +impl Default for Point2 { + fn default() -> Self { + Self::new(0.0, 0.0) + } +} + impl Point2 { pub fn new(x: f64, y: f64) -> Self { Point2 { diff --git a/pax-runtime/src/math/transform.rs b/pax-runtime/src/math/transform.rs index 69b975e7a..93dfae459 100644 --- a/pax-runtime/src/math/transform.rs +++ b/pax-runtime/src/math/transform.rs @@ -1,3 +1,4 @@ +use super::{Generic, Point2, Space, Vector2}; use std::{marker::PhantomData, ops::Mul}; //----------------------------------------------------------- @@ -5,42 +6,49 @@ use std::{marker::PhantomData, ops::Mul}; // transform impl (copy/pasted initially with some modifications) // curbo crate: https://www.michaelfbryan.com/arcs/kurbo/index.html // original source code: https://www.michaelfbryan.com/arcs/src/kurbo/affine.rs.html#10 -// kurbo is distributed under the following (MIT) license: -// "Copyright (c) 2018 Raph Levien - -// Permission is hereby granted, free of charge, to any -// person obtaining a copy of this software and associated -// documentation files (the "Software"), to deal in the -// Software without restriction, including without -// limitation the rights to use, copy, modify, merge, -// publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software -// is furnished to do so, subject to the following -// conditions: -// The above copyright notice and this permission notice -// shall be included in all copies or substantial portions -// of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -// SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE." +// Kurbo is distributed under an MIT license. //----------------------------------------------------------- -use super::{Space, Vector2}; - -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct Transform2 { +pub struct Transform2 { m: [f64; 6], _panthom_from: PhantomData, _panthom_to: PhantomData, } +// Implement Clone, Copy, PartialEq, etc manually, as +// to not require the Space to implement these. + +impl Clone for Transform2 { + fn clone(&self) -> Self { + Self { + m: self.m, + _panthom_from: PhantomData, + _panthom_to: PhantomData, + } + } +} + +impl std::fmt::Debug for Transform2 { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{} {} {}", self.m[0], self.m[1], self.m[2])?; + write!(f, "{} {} {}", self.m[3], self.m[4], self.m[5]) + } +} + +impl PartialEq for Transform2 { + fn eq(&self, other: &Self) -> bool { + self.m == other.m + } +} + +impl Copy for Transform2 {} + +impl Default for Transform2 { + fn default() -> Self { + Self::identity() + } +} + impl Transform2 { pub fn new(m: [f64; 6]) -> Self { Self { @@ -50,7 +58,7 @@ impl Transform2 { } } - pub fn unit() -> Self { + pub fn identity() -> Self { Self::new([1.0, 0.0, 0.0, 1.0, 0.0, 0.0]) } @@ -71,6 +79,18 @@ impl Transform2 { self.m[0] * self.m[3] - self.m[1] * self.m[2] } + pub fn coeffs(&self) -> [f64; 6] { + self.m + } + + pub fn get_translation(self) -> Vector2 { + (self * Point2::::default()).to_vector() + } + + pub fn between_worlds(self) -> Transform2 { + Transform2::new(self.m) + } + /// Produces NaN values when the determinant is zero. pub fn inverse(self) -> Transform2 { let inv_det = self.determinant().recip(); @@ -99,3 +119,31 @@ impl Mul> for Transform2 Mul> for Transform2 { + type Output = Point2; + + fn mul(self, other: Point2) -> Self::Output { + Self::Output::new( + self.m[0] * other.x + self.m[2] * other.y + self.m[4], + self.m[1] * other.x + self.m[3] * other.y + self.m[5], + ) + } +} + +impl Mul> for Transform2 { + type Output = Vector2; + + fn mul(self, other: Vector2) -> Self::Output { + Self::Output::new( + self.m[0] * other.x + self.m[2] * other.y, + self.m[1] * other.x + self.m[3] * other.y, + ) + } +} + +impl From> for kurbo::Affine { + fn from(value: Transform2) -> Self { + Self::new(value.m) + } +} diff --git a/pax-runtime/src/math/vector.rs b/pax-runtime/src/math/vector.rs index 12e62e4a1..bdc367fc0 100644 --- a/pax-runtime/src/math/vector.rs +++ b/pax-runtime/src/math/vector.rs @@ -1,20 +1,46 @@ use std::{ marker::PhantomData, - ops::{Add, Div, Mul, Sub}, + ops::{Add, Div, Mul, Neg, Sub}, }; use super::{Generic, Point2, Space}; -#[derive(Copy, Clone, Default, Debug)] pub struct Vector2 { pub x: f64, pub y: f64, _panthom: PhantomData, } +// Implement Clone, Copy, PartialEq, etc manually, as +// to not require the Space to implement these. + +impl Clone for Vector2 { + fn clone(&self) -> Self { + Self { + x: self.x, + y: self.y, + _panthom: PhantomData, + } + } +} + +impl Copy for Vector2 {} + +impl PartialEq for Vector2 { + fn eq(&self, other: &Self) -> bool { + self.x == other.x && self.y == other.y + } +} + +impl Default for Vector2 { + fn default() -> Self { + Self::new(0.0, 0.0) + } +} + impl Vector2 { pub fn new(x: f64, y: f64) -> Self { - Vector2 { + Self { x, y, _panthom: PhantomData, @@ -41,8 +67,8 @@ impl Vector2 { Point2::new(self.x, self.y) } - pub fn to_world(self) -> Point2 { - Point2::new(self.x, self.y) + pub fn to_world(self) -> Vector2 { + Vector2::new(self.x, self.y) } } @@ -77,6 +103,14 @@ impl Add for Vector2 { } } +impl Neg for Vector2 { + type Output = Vector2; + + fn neg(self) -> Self::Output { + Self::Output::new(-self.x, -self.y) + } +} + impl Sub for Vector2 { type Output = Vector2; fn sub(self, rhs: Vector2) -> Self::Output { diff --git a/pax-runtime/src/properties.rs b/pax-runtime/src/properties.rs index f179e9638..75fe19e41 100644 --- a/pax-runtime/src/properties.rs +++ b/pax-runtime/src/properties.rs @@ -1,4 +1,4 @@ -use crate::api::log; +use crate::math::Point2; use crate::numeric::Numeric; use pax_message::NativeMessage; use std::cell::RefCell; @@ -81,7 +81,7 @@ impl RuntimeContext { /// not register a `hit`, nor will elements that suppress input events. pub fn get_elements_beneath_ray( &self, - ray: (f64, f64), + ray: Point2, limit_one: bool, mut accum: Vec>, ) -> Vec> { @@ -91,7 +91,7 @@ impl RuntimeContext { //Finally: check whether element itself satisfies hit_test(ray) for node in self.z_index_node_cache.iter().rev().skip(1) { - if node.ray_cast_test(&ray) { + if node.ray_cast_test(ray) { //We only care about the topmost node getting hit, and the element //pool is ordered by z-index so we can just resolve the whole //calculation when we find the first matching node @@ -104,7 +104,7 @@ impl RuntimeContext { if let Some(unwrapped_parent) = parent { if let Some(_) = unwrapped_parent.get_clipping_size() { ancestral_clipping_bounds_are_satisfied = - (*unwrapped_parent).ray_cast_test(&ray); + (*unwrapped_parent).ray_cast_test(ray); break; } parent = unwrapped_parent.parent_expanded_node.borrow().upgrade(); @@ -125,7 +125,7 @@ impl RuntimeContext { } /// Alias for `get_elements_beneath_ray` with `limit_one = true` - pub fn get_topmost_element_beneath_ray(&self, ray: (f64, f64)) -> Option> { + pub fn get_topmost_element_beneath_ray(&self, ray: Point2) -> Option> { let res = self.get_elements_beneath_ray(ray, true, vec![]); if res.len() == 0 { None diff --git a/pax-runtime/src/rendering.rs b/pax-runtime/src/rendering.rs index 99d7b6677..98df5d74e 100644 --- a/pax-runtime/src/rendering.rs +++ b/pax-runtime/src/rendering.rs @@ -6,9 +6,7 @@ use std::iter; use std::rc::Rc; use crate::api::{CommonProperties, RenderContext}; -use crate::math::Generic; -pub use kurbo; -use kurbo::Affine; +use crate::math::{Generic, Space, Transform2}; use piet::{Color, StrokeStyle}; use crate::api::{ArgsScroll, Layer, Size}; @@ -35,12 +33,17 @@ pub struct InstantiationArgs { pub component_type_id: String, } +#[derive(Clone, Copy, Debug)] +pub struct EngineSpace; + +impl Space for EngineSpace {} + /// Stores the computed transform and the pre-transform bounding box (where the /// other corner is the origin). Useful for ray-casting, along with #[cfg_attr(debug_assertions, derive(Debug))] #[derive(Clone, PartialEq)] pub struct TransformAndBounds { - pub transform: Affine, + pub transform: Transform2, pub bounds: (f64, f64), // pub clipping_bounds: Option<(f64, f64)>, } diff --git a/pax-std/pax-std-primitives/src/button.rs b/pax-std/pax-std-primitives/src/button.rs index a287afc10..c3a10b570 100644 --- a/pax-std/pax-std-primitives/src/button.rs +++ b/pax-std/pax-std-primitives/src/button.rs @@ -95,7 +95,7 @@ impl InstanceNode for ButtonInstance { patch_if_needed( &mut old_state.transform, &mut patch.transform, - computed_tab.transform.as_coeffs().to_vec(), + computed_tab.transform.coeffs().to_vec(), ), ]; if updates.into_iter().any(|v| v == true) { diff --git a/pax-std/pax-std-primitives/src/checkbox.rs b/pax-std/pax-std-primitives/src/checkbox.rs index 19811ad97..9fa81bb75 100644 --- a/pax-std/pax-std-primitives/src/checkbox.rs +++ b/pax-std/pax-std-primitives/src/checkbox.rs @@ -83,7 +83,7 @@ impl InstanceNode for CheckboxInstance { patch_if_needed( &mut old_state.transform, &mut patch.transform, - computed_tab.transform.as_coeffs().to_vec(), + computed_tab.transform.coeffs().to_vec(), ), ]; if updates.into_iter().any(|v| v == true) { diff --git a/pax-std/pax-std-primitives/src/ellipse.rs b/pax-std/pax-std-primitives/src/ellipse.rs index 900baef53..32ffcc135 100644 --- a/pax-std/pax-std-primitives/src/ellipse.rs +++ b/pax-std/pax-std-primitives/src/ellipse.rs @@ -48,7 +48,7 @@ impl InstanceNode for EllipseInstance { let accuracy = 0.1; let bez_path = ellipse.to_path(accuracy); - let transformed_bez_path = tab.transform * bez_path; + let transformed_bez_path = Into::::into(tab.transform) * bez_path; let duplicate_transformed_bez_path = transformed_bez_path.clone(); let color = if let Fill::Solid(properties_color) = properties.fill.get() { diff --git a/pax-std/pax-std-primitives/src/image.rs b/pax-std/pax-std-primitives/src/image.rs index 63c5abdd6..ab8a343b3 100644 --- a/pax-std/pax-std-primitives/src/image.rs +++ b/pax-std/pax-std-primitives/src/image.rs @@ -1,4 +1,4 @@ -use pax_runtime::api::RenderContext; +use pax_runtime::{api::RenderContext, math::Point2}; use pax_std::primitives::Image; use std::{cell::RefCell, collections::HashMap}; @@ -88,8 +88,8 @@ impl InstanceNode for ImageInstance { let height = bounding_dimens.1; let bounds = kurbo::Rect::new(0.0, 0.0, width, height); - let top_left = transform * kurbo::Point::new(bounds.min_x(), bounds.min_y()); - let bottom_right = transform * kurbo::Point::new(bounds.max_x(), bounds.max_y()); + let top_left = transform * Point2::new(bounds.min_x(), bounds.min_y()); + let bottom_right = transform * Point2::new(bounds.max_x(), bounds.max_y()); let transformed_bounds = kurbo::Rect::new(top_left.x, top_left.y, bottom_right.x, bottom_right.y); diff --git a/pax-std/pax-std-primitives/src/path.rs b/pax-std/pax-std-primitives/src/path.rs index ea37f79f9..ec24325c4 100644 --- a/pax-std/pax-std-primitives/src/path.rs +++ b/pax-std/pax-std-primitives/src/path.rs @@ -75,7 +75,10 @@ impl InstanceNode for PathInstance { } } - let transformed_bez_path = bez_path; + let computed_props = expanded_node.layout_properties.borrow(); + let tab = &computed_props.as_ref().unwrap().computed_tab; + + let transformed_bez_path = Into::::into(tab.transform) * bez_path; let duplicate_transformed_bez_path = transformed_bez_path.clone(); let color = properties.fill.get().to_piet_color(); diff --git a/pax-std/pax-std-primitives/src/rectangle.rs b/pax-std/pax-std-primitives/src/rectangle.rs index ef1125166..df9cf1283 100644 --- a/pax-std/pax-std-primitives/src/rectangle.rs +++ b/pax-std/pax-std-primitives/src/rectangle.rs @@ -80,7 +80,7 @@ impl InstanceNode for RectangleInstance { let rect = RoundedRect::new(0.0, 0.0, width, height, properties.corner_radii.get()); let bez_path = rect.to_path(0.1); - let transformed_bez_path = tab.transform * bez_path; + let transformed_bez_path = Into::::into(tab.transform) * bez_path; let duplicate_transformed_bez_path = transformed_bez_path.clone(); match properties.fill.get() { diff --git a/pax-std/pax-std-primitives/src/text.rs b/pax-std/pax-std-primitives/src/text.rs index 0e819641d..19a6071ad 100644 --- a/pax-std/pax-std-primitives/src/text.rs +++ b/pax-std/pax-std-primitives/src/text.rs @@ -105,7 +105,7 @@ impl InstanceNode for TextInstance { patch_if_needed( &mut old_state.transform, &mut patch.transform, - computed_tab.transform.as_coeffs().to_vec(), + computed_tab.transform.coeffs().to_vec(), ), ]; diff --git a/pax-std/pax-std-primitives/src/textbox.rs b/pax-std/pax-std-primitives/src/textbox.rs index e90f72710..a0eec2c76 100644 --- a/pax-std/pax-std-primitives/src/textbox.rs +++ b/pax-std/pax-std-primitives/src/textbox.rs @@ -81,7 +81,7 @@ impl InstanceNode for TextboxInstance { patch_if_needed( &mut old_state.transform, &mut patch.transform, - computed_tab.transform.as_coeffs().to_vec(), + computed_tab.transform.coeffs().to_vec(), ), ]; if updates.into_iter().any(|v| v == true) { From 6d37ccede257f8edd1a9055892fb198d32ebdd32 Mon Sep 17 00:00:00 2001 From: Samuel Selleck Date: Fri, 16 Feb 2024 10:52:13 -0800 Subject: [PATCH 05/10] cleanup --- pax-runtime/src/engine/expanded_node.rs | 12 +----------- pax-runtime/src/rendering.rs | 9 ++------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/pax-runtime/src/engine/expanded_node.rs b/pax-runtime/src/engine/expanded_node.rs index 0b820b466..6ffe1abcc 100644 --- a/pax-runtime/src/engine/expanded_node.rs +++ b/pax-runtime/src/engine/expanded_node.rs @@ -5,7 +5,7 @@ use crate::constants::{ MOUSE_OVER_HANDLERS, MOUSE_UP_HANDLERS, SCROLL_HANDLERS, TEXTBOX_CHANGE_HANDLERS, TOUCH_END_HANDLERS, TOUCH_MOVE_HANDLERS, TOUCH_START_HANDLERS, WHEEL_HANDLERS, }; -use crate::math::{Point2, Transform2}; +use crate::math::Point2; use crate::Globals; #[cfg(debug_assertions)] use core::fmt; @@ -348,16 +348,6 @@ impl ExpandedNode { self.instance_node.render(&self, context, rcs); } - pub fn local_raycast(&self, context: &RuntimeContext, point: Point2) -> Vec> { - let lp = self.layout_properties.borrow(); - let transform = if let Some(v) = lp.as_ref() { - v.computed_tab.transform - } else { - Transform2::identity() - }; - context.get_elements_beneath_ray(transform * point, false, vec![]) - } - /// Manages unpacking an Rc>, downcasting into /// the parameterized `target_type`, and executing a provided closure `body` in the /// context of that unwrapped variant (including support for mutable operations), diff --git a/pax-runtime/src/rendering.rs b/pax-runtime/src/rendering.rs index 98df5d74e..18ba197de 100644 --- a/pax-runtime/src/rendering.rs +++ b/pax-runtime/src/rendering.rs @@ -6,7 +6,7 @@ use std::iter; use std::rc::Rc; use crate::api::{CommonProperties, RenderContext}; -use crate::math::{Generic, Space, Transform2}; +use crate::math::Transform2; use piet::{Color, StrokeStyle}; use crate::api::{ArgsScroll, Layer, Size}; @@ -33,11 +33,6 @@ pub struct InstantiationArgs { pub component_type_id: String, } -#[derive(Clone, Copy, Debug)] -pub struct EngineSpace; - -impl Space for EngineSpace {} - /// Stores the computed transform and the pre-transform bounding box (where the /// other corner is the origin). Useful for ray-casting, along with #[cfg_attr(debug_assertions, derive(Debug))] @@ -49,7 +44,7 @@ pub struct TransformAndBounds { } impl TransformAndBounds { - pub fn corners(&self) -> [Point2; 4] { + pub fn corners(&self) -> [Point2; 4] { let width = self.bounds.0; let height = self.bounds.1; From 53adbb2afe2809cae59603aacd5c5d17c07542c5 Mon Sep 17 00:00:00 2001 From: Samuel Selleck Date: Fri, 16 Feb 2024 11:54:53 -0800 Subject: [PATCH 06/10] wip node abstraction --- pax-runtime/src/engine/design_utils.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pax-runtime/src/engine/design_utils.rs b/pax-runtime/src/engine/design_utils.rs index f3b0c1bf7..466d27dd1 100644 --- a/pax-runtime/src/engine/design_utils.rs +++ b/pax-runtime/src/engine/design_utils.rs @@ -1,3 +1,15 @@ +use std::rc::Rc; + // For the designer // What should be exposed to the user? -pub use crate::ExpandedNode; +use crate::{math::Transform2, ExpandedNode}; + +pub struct Node { + inner: Rc, +} + +impl Node { + fn screen_transform(&self) -> Transform2 { + todo!() + } +} From 3dc1fbb05a6c271ea3d12ff4ea25dbe44fa5448b Mon Sep 17 00:00:00 2001 From: Samuel Selleck Date: Fri, 16 Feb 2024 13:28:56 -0800 Subject: [PATCH 07/10] NodeInterface wrapper, other refactors --- examples/src/camera/src/lib.rs | 6 +- .../src/component_in_component/src/inner.rs | 4 +- .../src/component_in_component/src/lib.rs | 4 +- examples/src/fireworks/src/lib.rs | 6 +- examples/src/hello-rgb/src/lib.rs | 2 +- examples/src/layer-tests/src/lib.rs | 6 +- examples/src/one-rect/src/lib.rs | 2 +- examples/src/paths/src/lib.rs | 6 +- examples/src/pax-intro/src/lib.rs | 8 +-- examples/src/playground/src/lib.rs | 12 ++-- examples/src/raycast-tests/src/lib.rs | 12 ++-- examples/src/simple-conditional/src/lib.rs | 6 +- examples/src/simple-stacker/src/lib.rs | 10 +-- examples/src/words/src/lib.rs | 38 +++++----- .../new-libdev-project-template/src/lib.rs | 6 +- pax-compiler/new-project-template/src/lib.rs | 6 +- .../cartridge_generation/cartridge.tera | 4 +- .../cartridge_generation/macros.tera | 4 +- pax-runtime/src/api.rs | 40 ++++++++++- pax-runtime/src/engine/design_utils.rs | 72 +++++++++++++++++-- pax-runtime/src/engine/expanded_node.rs | 8 +-- pax-runtime/src/engine/mod.rs | 4 +- pax-runtime/src/math.rs | 3 +- pax-std/src/stacker.rs | 4 +- 24 files changed, 183 insertions(+), 90 deletions(-) diff --git a/examples/src/camera/src/lib.rs b/examples/src/camera/src/lib.rs index f8344ee21..259fe183d 100644 --- a/examples/src/camera/src/lib.rs +++ b/examples/src/camera/src/lib.rs @@ -1,5 +1,5 @@ #![allow(unused_imports)] -use pax_engine::api::{ArgsClick, EasingCurve, NodeContext, Property}; +use pax_engine::api::{ArgsClick, EasingCurve, EngineContext, Property}; use pax_engine::Pax; use pax_std::primitives::{Ellipse, Frame, Group, Rectangle, Text}; @@ -20,13 +20,13 @@ pub struct TypeExample { } impl Camera { - pub fn handle_mount(&mut self, _: NodeContext) { + pub fn handle_mount(&mut self, _: EngineContext) { self.zoom.set(2.0); self.pan_x.set(0.0); self.pan_y.set(0.0); } - pub fn handle_click(&mut self, _: NodeContext, args: ArgsClick) { + pub fn handle_click(&mut self, _: EngineContext, args: ArgsClick) { let delta_pan = ( args.mouse.x - self.pan_x.get(), args.mouse.y - self.pan_y.get(), diff --git a/examples/src/component_in_component/src/inner.rs b/examples/src/component_in_component/src/inner.rs index 4d48ff6f3..97722d16b 100644 --- a/examples/src/component_in_component/src/inner.rs +++ b/examples/src/component_in_component/src/inner.rs @@ -17,9 +17,9 @@ pub struct Inner { } impl Inner { - pub fn handle_mount(&mut self, ctx: &NodeContext) {} + pub fn handle_mount(&mut self, ctx: &EngineContext) {} - pub fn inner_clicked(&mut self, ctx: &NodeContext, args: ArgsClick) { + pub fn inner_clicked(&mut self, ctx: &EngineContext, args: ArgsClick) { self.inner_active.set(!self.inner_active.get()); } } diff --git a/examples/src/component_in_component/src/lib.rs b/examples/src/component_in_component/src/lib.rs index ea96e2dac..d5723ab51 100644 --- a/examples/src/component_in_component/src/lib.rs +++ b/examples/src/component_in_component/src/lib.rs @@ -20,12 +20,12 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &NodeContext) { + pub fn handle_mount(&mut self, ctx: &EngineContext) { self.message_outer.set("testing 12049".to_string()); self.x.set(Size::Percent(30.into())); } - pub fn outer_clicked(&mut self, ctx: &NodeContext, args: ArgsClick) { + pub fn outer_clicked(&mut self, ctx: &EngineContext, args: ArgsClick) { self.outer_active.set(!self.outer_active.get()); } } diff --git a/examples/src/fireworks/src/lib.rs b/examples/src/fireworks/src/lib.rs index 46a3ed4a6..31aef5fd6 100644 --- a/examples/src/fireworks/src/lib.rs +++ b/examples/src/fireworks/src/lib.rs @@ -1,5 +1,5 @@ #![allow(unused_imports)] -use pax_engine::api::{ArgsClick, ArgsWheel, EasingCurve, NodeContext}; +use pax_engine::api::{ArgsClick, ArgsWheel, EasingCurve, EngineContext}; use pax_engine::*; use pax_std::primitives::{Ellipse, Frame, Group, Path, Rectangle, Text}; @@ -14,13 +14,13 @@ pub struct Fireworks { const ROTATION_COEFFICIENT: f64 = 0.00010; impl Fireworks { - pub fn handle_scroll(&mut self, _ctx: &NodeContext, args: ArgsWheel) { + pub fn handle_scroll(&mut self, _ctx: &EngineContext, args: ArgsWheel) { let old_t = self.rotation.get(); let new_t = old_t - args.delta_y * ROTATION_COEFFICIENT; self.rotation.set(f64::max(0.0, new_t)); } - pub fn handle_pre_render(&mut self, _ctx: &NodeContext) { + pub fn handle_pre_render(&mut self, _ctx: &EngineContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } diff --git a/examples/src/hello-rgb/src/lib.rs b/examples/src/hello-rgb/src/lib.rs index 29f9e5156..0b384e8d8 100644 --- a/examples/src/hello-rgb/src/lib.rs +++ b/examples/src/hello-rgb/src/lib.rs @@ -11,7 +11,7 @@ pub struct HelloRGB { const ROTATION_COEFFICIENT: f64 = 0.005; impl HelloRGB { - pub fn handle_scroll(&mut self, ctx: &NodeContext, args: ArgsWheel) { + pub fn handle_scroll(&mut self, ctx: &EngineContext, args: ArgsWheel) { let old_t = self.rotation.get(); let new_t = old_t + args.delta_y * ROTATION_COEFFICIENT; self.rotation.set(new_t); diff --git a/examples/src/layer-tests/src/lib.rs b/examples/src/layer-tests/src/lib.rs index 83358bb1d..c343d4116 100644 --- a/examples/src/layer-tests/src/lib.rs +++ b/examples/src/layer-tests/src/lib.rs @@ -18,16 +18,16 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &NodeContext) { + pub fn handle_mount(&mut self, ctx: &EngineContext) { self.message.set("false".to_string()); } - pub fn handle_pre_render(&mut self, ctx: &NodeContext) { + pub fn handle_pre_render(&mut self, ctx: &EngineContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } - pub fn toggle(&mut self, ctx: &NodeContext, args: ArgsClick) { + pub fn toggle(&mut self, ctx: &EngineContext, args: ArgsClick) { self.activated.set(!self.activated.get()); self.message.set(format!("{}", self.activated.get())); } diff --git a/examples/src/one-rect/src/lib.rs b/examples/src/one-rect/src/lib.rs index 27f23ce4b..353cb020c 100644 --- a/examples/src/one-rect/src/lib.rs +++ b/examples/src/one-rect/src/lib.rs @@ -19,7 +19,7 @@ pub struct OneRect { impl OneRect { - pub fn handle_pre_render(&mut self, ctx: &NodeContext) { + pub fn handle_pre_render(&mut self, ctx: &EngineContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } diff --git a/examples/src/paths/src/lib.rs b/examples/src/paths/src/lib.rs index 52de1c59f..9f57e97c3 100644 --- a/examples/src/paths/src/lib.rs +++ b/examples/src/paths/src/lib.rs @@ -18,15 +18,15 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &NodeContext) { + pub fn handle_mount(&mut self, ctx: &EngineContext) { self.message.set("Click me".to_string()); } - pub fn handle_pre_render(&mut self, ctx: &NodeContext) { + pub fn handle_pre_render(&mut self, ctx: &EngineContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } - pub fn increment(&mut self, ctx: &NodeContext, args: ArgsClick) { + pub fn increment(&mut self, ctx: &EngineContext, args: ArgsClick) { let old_num_clicks = self.num_clicks.get(); self.num_clicks.set(old_num_clicks + 1); self.message diff --git a/examples/src/pax-intro/src/lib.rs b/examples/src/pax-intro/src/lib.rs index 1451205dc..78e9034ca 100644 --- a/examples/src/pax-intro/src/lib.rs +++ b/examples/src/pax-intro/src/lib.rs @@ -32,12 +32,12 @@ const N_Y: f64 = 10.0; const LEN: usize = N_X as usize * N_Y as usize; impl DynamicObject { - pub fn handle_mount(&mut self, _ctx: &NodeContext) { + pub fn handle_mount(&mut self, _ctx: &EngineContext) { self.rects.set(vec![Rect::default(); LEN]); self.rects_bellow.set(vec![Rect::default(); LEN]); } - pub fn handle_pre_render(&mut self, ctx: &NodeContext) { + pub fn handle_pre_render(&mut self, ctx: &EngineContext) { let offsets = [0.1, 0.5, 1.0, 0.2, 0.3, 0.9, 0.3, 0.8, 0.7, 0.6]; let div_line = [-4, -1, -2, 0, 1, -1, 0, 3, 2, 4]; let t = *self.ticks.get(); @@ -93,9 +93,9 @@ impl DynamicObject { } } - pub fn increment(&mut self, _ctx: &NodeContext, _args: ArgsClick) {} + pub fn increment(&mut self, _ctx: &EngineContext, _args: ArgsClick) {} - pub fn mouse_move(&mut self, _ctx: &NodeContext, args: ArgsMouseMove) { + pub fn mouse_move(&mut self, _ctx: &EngineContext, args: ArgsMouseMove) { self.mouse_x.set(args.mouse.x); self.mouse_y.set(args.mouse.y); } diff --git a/examples/src/playground/src/lib.rs b/examples/src/playground/src/lib.rs index af3a455ec..6b641cb30 100644 --- a/examples/src/playground/src/lib.rs +++ b/examples/src/playground/src/lib.rs @@ -23,17 +23,17 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &NodeContext) { + pub fn handle_mount(&mut self, ctx: &EngineContext) { self.message.set("Click me".to_string()); self.color .set(Color::rgba(1.0.into(), 0.3.into(), 0.6.into(), 1.0.into())); } - pub fn handle_pre_render(&mut self, ctx: &NodeContext) { + pub fn handle_pre_render(&mut self, ctx: &EngineContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } - pub fn toggle(&mut self, ctx: &NodeContext, args: ArgsClick) { + pub fn toggle(&mut self, ctx: &EngineContext, args: ArgsClick) { let old_num_clicks = self.num_clicks.get(); self.num_clicks.set(old_num_clicks + 1); self.message @@ -41,7 +41,7 @@ impl Example { self.conditional.set(!self.conditional.get()); } - pub fn checkbox_change(&mut self, ctx: &NodeContext, args: ArgsCheckboxChange) { + pub fn checkbox_change(&mut self, ctx: &EngineContext, args: ArgsCheckboxChange) { self.checked.set(!args.checked); self.align_vertical.set(match self.checked.get() { true => TextAlignVertical::Top, @@ -56,11 +56,11 @@ impl Example { } } - pub fn textbox_change(&mut self, ctx: &NodeContext, args: ArgsTextboxChange) { + pub fn textbox_change(&mut self, ctx: &EngineContext, args: ArgsTextboxChange) { self.textbox_text.set(args.text); } - pub fn button_click(&mut self, ctx: &NodeContext, args: ArgsButtonClick) { + pub fn button_click(&mut self, ctx: &EngineContext, args: ArgsButtonClick) { self.color .set(Color::rgba(1.0.into(), 0.3.into(), 0.6.into(), 1.0.into())); } diff --git a/examples/src/raycast-tests/src/lib.rs b/examples/src/raycast-tests/src/lib.rs index 7eb6d0be7..61802c81a 100644 --- a/examples/src/raycast-tests/src/lib.rs +++ b/examples/src/raycast-tests/src/lib.rs @@ -17,25 +17,25 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &NodeContext) {} + pub fn handle_mount(&mut self, ctx: &EngineContext) {} - pub fn frame1(&mut self, ctx: &NodeContext, args: ArgsMouseMove) { + pub fn frame1(&mut self, ctx: &EngineContext, args: ArgsMouseMove) { self.hit_outer.set(format!("hit outer: frame {}", 1)); } - pub fn frame2(&mut self, ctx: &NodeContext, args: ArgsMouseMove) { + pub fn frame2(&mut self, ctx: &EngineContext, args: ArgsMouseMove) { self.hit_outer.set(format!("hit outer: frame {}", 2)); } - pub fn frame1rect1(&mut self, ctx: &NodeContext, args: ArgsMouseMove) { + pub fn frame1rect1(&mut self, ctx: &EngineContext, args: ArgsMouseMove) { self.hit_inner.set(format!("hit inner: rect {}", 1)); } - pub fn frame1rect2(&mut self, ctx: &NodeContext, args: ArgsMouseMove) { + pub fn frame1rect2(&mut self, ctx: &EngineContext, args: ArgsMouseMove) { self.hit_inner.set(format!("hit inner: rect {}", 2)); } - pub fn frame2rect1(&mut self, ctx: &NodeContext, args: ArgsMouseMove) { + pub fn frame2rect1(&mut self, ctx: &EngineContext, args: ArgsMouseMove) { self.hit_inner.set(format!("hit inner: rect {}", 1)); } } diff --git a/examples/src/simple-conditional/src/lib.rs b/examples/src/simple-conditional/src/lib.rs index 1af0f2410..332ab7f9f 100644 --- a/examples/src/simple-conditional/src/lib.rs +++ b/examples/src/simple-conditional/src/lib.rs @@ -19,17 +19,17 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &NodeContext) { + pub fn handle_mount(&mut self, ctx: &EngineContext) { self.message.set("Click me".to_string()); self.activated.set(false); self.not_activated.set(true); } - pub fn handle_pre_render(&mut self, ctx: &NodeContext) { + pub fn handle_pre_render(&mut self, ctx: &EngineContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } - pub fn increment(&mut self, ctx: &NodeContext, args: ArgsClick) { + pub fn increment(&mut self, ctx: &EngineContext, args: ArgsClick) { self.activated.set(!self.activated.get()); self.not_activated.set(!self.activated.get()); self.message diff --git a/examples/src/simple-stacker/src/lib.rs b/examples/src/simple-stacker/src/lib.rs index 933fc6906..bd649c425 100644 --- a/examples/src/simple-stacker/src/lib.rs +++ b/examples/src/simple-stacker/src/lib.rs @@ -19,20 +19,20 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &NodeContext) { + pub fn handle_mount(&mut self, ctx: &EngineContext) { self.num.set(1); } - pub fn click0(&mut self, ctx: &NodeContext, args: ArgsClick) { + pub fn click0(&mut self, ctx: &EngineContext, args: ArgsClick) { self.num.set(1); } - pub fn click1(&mut self, ctx: &NodeContext, args: ArgsClick) { + pub fn click1(&mut self, ctx: &EngineContext, args: ArgsClick) { self.num.set(3); } - pub fn click2(&mut self, ctx: &NodeContext, args: ArgsClick) { + pub fn click2(&mut self, ctx: &EngineContext, args: ArgsClick) { self.num.set(5); } - pub fn handle_pre_render(&mut self, ctx: &NodeContext) {} + pub fn handle_pre_render(&mut self, ctx: &EngineContext) {} } diff --git a/examples/src/words/src/lib.rs b/examples/src/words/src/lib.rs index ffc806f70..35d26da20 100644 --- a/examples/src/words/src/lib.rs +++ b/examples/src/words/src/lib.rs @@ -2,7 +2,7 @@ use pax_engine::api::{ ArgsClick, ArgsClap, ArgsScroll, ArgsTouchStart, ArgsTouchMove, ArgsTouchEnd, ArgsKeyDown, ArgsKeyUp, ArgsKeyPress, ArgsDoubleClick, ArgsMouseMove, ArgsWheel, ArgsMouseDown, ArgsMouseUp, ArgsMouseOver, ArgsMouseOut, ArgsContextMenu, - NodeContext, Property, PropertyLiteral + EngineContext, Property, PropertyLiteral }; use pax_engine::Pax; use pax_std::primitives::{Ellipse, Frame, Group, Path, Rectangle, Text, Image}; @@ -16,74 +16,74 @@ pub struct Words { } impl Words { - pub fn handle_mount(&mut self, _ctx: &NodeContext) { + pub fn handle_mount(&mut self, _ctx: &EngineContext) { } - pub fn handle_clap(&mut self, _ctx: &NodeContext, _args: ArgsClap) { + pub fn handle_clap(&mut self, _ctx: &EngineContext, _args: ArgsClap) { self.content.set("Clap".to_string()); } - pub fn handle_scroll(&mut self, _ctx: &NodeContext, _args: ArgsScroll) { + pub fn handle_scroll(&mut self, _ctx: &EngineContext, _args: ArgsScroll) { self.content.set("Scroll".to_string()); } - pub fn handle_touch_start(&mut self, _ctx: &NodeContext, _args: ArgsTouchStart) { + pub fn handle_touch_start(&mut self, _ctx: &EngineContext, _args: ArgsTouchStart) { self.content.set("Touch Start".to_string()); } - pub fn handle_touch_move(&mut self, _ctx: &NodeContext, _args: ArgsTouchMove) { + pub fn handle_touch_move(&mut self, _ctx: &EngineContext, _args: ArgsTouchMove) { self.content.set("Touch Move".to_string()); } - pub fn handle_touch_end(&mut self, _ctx: &NodeContext, _args: ArgsTouchEnd) { + pub fn handle_touch_end(&mut self, _ctx: &EngineContext, _args: ArgsTouchEnd) { self.content.set("Touch End".to_string()); } - pub fn handle_key_down(&mut self, _ctx: &NodeContext, _args: ArgsKeyDown) { + pub fn handle_key_down(&mut self, _ctx: &EngineContext, _args: ArgsKeyDown) { self.content.set("Key Down".to_string()); } - pub fn handle_key_up(&mut self, _ctx: &NodeContext, _args: ArgsKeyUp) { + pub fn handle_key_up(&mut self, _ctx: &EngineContext, _args: ArgsKeyUp) { self.content.set("Key Up".to_string()); } - pub fn handle_key_press(&mut self, _ctx: &NodeContext, _args: ArgsKeyPress) { + pub fn handle_key_press(&mut self, _ctx: &EngineContext, _args: ArgsKeyPress) { self.content.set("Key Press".to_string()); } - pub fn handle_click(&mut self, _ctx: &NodeContext, _args: ArgsClick) { + pub fn handle_click(&mut self, _ctx: &EngineContext, _args: ArgsClick) { self.content.set("Click".to_string()); } - pub fn handle_double_click(&mut self, _ctx: &NodeContext, _args: ArgsDoubleClick) { + pub fn handle_double_click(&mut self, _ctx: &EngineContext, _args: ArgsDoubleClick) { self.content.set("Double Click".to_string()); } - pub fn handle_mouse_move(&mut self, _ctx: &NodeContext, _args: ArgsMouseMove) { + pub fn handle_mouse_move(&mut self, _ctx: &EngineContext, _args: ArgsMouseMove) { self.content.set("Mouse Move".to_string()); } - pub fn handle_wheel(&mut self, _ctx: &NodeContext, _args: ArgsWheel) { + pub fn handle_wheel(&mut self, _ctx: &EngineContext, _args: ArgsWheel) { self.content.set("Wheel".to_string()); } - pub fn handle_mouse_down(&mut self, _ctx: &NodeContext, _args: ArgsMouseDown) { + pub fn handle_mouse_down(&mut self, _ctx: &EngineContext, _args: ArgsMouseDown) { self.content.set("Mouse Down".to_string()); } - pub fn handle_mouse_up(&mut self, _ctx: &NodeContext, _args: ArgsMouseUp) { + pub fn handle_mouse_up(&mut self, _ctx: &EngineContext, _args: ArgsMouseUp) { self.content.set("Mouse Up".to_string()); } - pub fn handle_mouse_over(&mut self, _ctx: &NodeContext, _args: ArgsMouseOver) { + pub fn handle_mouse_over(&mut self, _ctx: &EngineContext, _args: ArgsMouseOver) { self.content.set("Mouse Over".to_string()); } - pub fn handle_mouse_out(&mut self, _ctx: &NodeContext, _args: ArgsMouseOut) { + pub fn handle_mouse_out(&mut self, _ctx: &EngineContext, _args: ArgsMouseOut) { self.content.set("Mouse Out".to_string()); } - pub fn handle_context_menu(&mut self, _ctx: &NodeContext, _args: ArgsContextMenu){ + pub fn handle_context_menu(&mut self, _ctx: &EngineContext, _args: ArgsContextMenu){ self.content.set("Context Menu".to_string()); } } \ No newline at end of file diff --git a/pax-compiler/new-libdev-project-template/src/lib.rs b/pax-compiler/new-libdev-project-template/src/lib.rs index 5a002e849..36e1a7af4 100644 --- a/pax-compiler/new-libdev-project-template/src/lib.rs +++ b/pax-compiler/new-libdev-project-template/src/lib.rs @@ -18,15 +18,15 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &NodeContext) { + pub fn handle_mount(&mut self, ctx: &EngineContext) { self.message.set("Click me".to_string()); } - pub fn handle_pre_render(&mut self, ctx: &NodeContext) { + pub fn handle_pre_render(&mut self, ctx: &EngineContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } - pub fn increment(&mut self, ctx: &NodeContext, args: ArgsClick){ + pub fn increment(&mut self, ctx: &EngineContext, args: ArgsClick){ let old_num_clicks = self.num_clicks.get(); self.num_clicks.set(old_num_clicks + 1); self.message.set(format!("{} clicks", self.num_clicks.get())); diff --git a/pax-compiler/new-project-template/src/lib.rs b/pax-compiler/new-project-template/src/lib.rs index 5a002e849..36e1a7af4 100644 --- a/pax-compiler/new-project-template/src/lib.rs +++ b/pax-compiler/new-project-template/src/lib.rs @@ -18,15 +18,15 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &NodeContext) { + pub fn handle_mount(&mut self, ctx: &EngineContext) { self.message.set("Click me".to_string()); } - pub fn handle_pre_render(&mut self, ctx: &NodeContext) { + pub fn handle_pre_render(&mut self, ctx: &EngineContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } - pub fn increment(&mut self, ctx: &NodeContext, args: ArgsClick){ + pub fn increment(&mut self, ctx: &EngineContext, args: ArgsClick){ let old_num_clicks = self.num_clicks.get(); self.num_clicks.set(old_num_clicks + 1); self.message.set(format!("{} clicks", self.num_clicks.get())); diff --git a/pax-compiler/templates/cartridge_generation/cartridge.tera b/pax-compiler/templates/cartridge_generation/cartridge.tera index 45e8b3272..a3218d818 100644 --- a/pax-compiler/templates/cartridge_generation/cartridge.tera +++ b/pax-compiler/templates/cartridge_generation/cartridge.tera @@ -161,7 +161,7 @@ pub trait ComponentFactory { /// Returns the requested closure for the handler registry based on the defined handlers for this component /// The argument type is extrapolated based on how the handler was used in the initial compiled template - fn build_handler(&self, fn_name: &str) -> fn(Rc>, &NodeContext, Option::>); + fn build_handler(&self, fn_name: &str) -> fn(Rc>, &EngineContext, Option::>); /// Returns the handler registry based on the defined handlers for this component fn build_component_handlers(&self, handlers: Vec<(String, Vec)>) -> Rc>; @@ -511,4 +511,4 @@ impl DefinitionToInstanceTraverser { } None } -} \ No newline at end of file +} diff --git a/pax-compiler/templates/cartridge_generation/macros.tera b/pax-compiler/templates/cartridge_generation/macros.tera index 3c4786ea9..a892dc02c 100644 --- a/pax-compiler/templates/cartridge_generation/macros.tera +++ b/pax-compiler/templates/cartridge_generation/macros.tera @@ -33,7 +33,7 @@ impl ComponentFactory for {{component.pascal_identifier}}Factory { }))) } - fn build_handler(&self,fn_name: &str) -> fn(Rc>, &NodeContext, Option::>) { + fn build_handler(&self,fn_name: &str) -> fn(Rc>, &EngineContext, Option::>) { match fn_name { {% for handler in component.handlers %} "{{handler.name}}" => { @@ -179,4 +179,4 @@ impl TypeFactory for {{active_type.type_id_escaped}}TypeFactory { } } -{%- endmacro -%} \ No newline at end of file +{%- endmacro -%} diff --git a/pax-runtime/src/api.rs b/pax-runtime/src/api.rs index 8d5380476..44964424e 100644 --- a/pax-runtime/src/api.rs +++ b/pax-runtime/src/api.rs @@ -11,6 +11,8 @@ use lazy_static::lazy_static; use mut_static::MutStatic; use piet::PaintBrush; +use crate::design_utils::NodeInterface; +use crate::math::{Point2, Space}; pub use crate::numeric::Numeric; use crate::{PropertyExpression, RuntimeContext}; use pax_manifest::constants::COMMON_PROPERTIES_TYPE; @@ -135,7 +137,7 @@ pub type Property = Box>; #[derive(Clone)] #[cfg_attr(debug_assertions, derive(Debug))] -pub struct NodeContext<'a> { +pub struct EngineContext<'a> { /// The current global engine tick count pub frames_elapsed: usize, /// The bounds of this element's immediate container (parent) in px @@ -143,12 +145,46 @@ pub struct NodeContext<'a> { /// The bounds of this element in px pub bounds_self: (f64, f64), /// Borrow of the RuntimeContext, used at least for exposing raycasting to userland - pub runtime_context: &'a RuntimeContext, + pub(crate) runtime_context: &'a RuntimeContext, #[cfg(feature = "designtime")] pub designtime: Rc>, } +pub struct Window; + +impl Space for Window {} + +impl EngineContext<'_> { + pub fn raycast(&self, point: Point2) -> Vec { + let expanded_nodes = + self.runtime_context + .get_elements_beneath_ray(point.to_world(), false, vec![]); + expanded_nodes + .into_iter() + .map(Into::::into) + .collect() + } + + pub fn get_nodes_by_global_id(&self, type_id: &str, template_id: usize) -> Vec { + let expanded_nodes = self + .runtime_context + .get_expanded_nodes_by_global_ids(type_id, template_id); + expanded_nodes + .into_iter() + .map(Into::::into) + .collect() + } + + pub fn get_nodes_by_id(&self, id: &str) -> Vec { + let expanded_nodes = self.runtime_context.get_expanded_nodes_by_id(id); + expanded_nodes + .into_iter() + .map(Into::::into) + .collect() + } +} + // Unified events /// A Clap describes either a "click" (mousedown followed by mouseup), OR a diff --git a/pax-runtime/src/engine/design_utils.rs b/pax-runtime/src/engine/design_utils.rs index 466d27dd1..4cbb5669f 100644 --- a/pax-runtime/src/engine/design_utils.rs +++ b/pax-runtime/src/engine/design_utils.rs @@ -1,15 +1,73 @@ use std::rc::Rc; -// For the designer -// What should be exposed to the user? -use crate::{math::Transform2, ExpandedNode}; +use crate::{ + api::Window, + math::{Point2, Space, Transform2}, + ExpandedNode, +}; -pub struct Node { +pub struct NodeInterface { inner: Rc, } -impl Node { - fn screen_transform(&self) -> Transform2 { - todo!() +impl From> for NodeInterface { + fn from(expanded_node: Rc) -> Self { + Self { + inner: expanded_node, + } + } +} + +pub struct NodeLocal; + +impl Space for NodeLocal {} + +impl NodeInterface { + pub fn global_id(&self) -> (String, usize) { + let base = self.inner.instance_node.base(); + (base.component_type_id.to_owned(), base.template_node_id) + } + + pub fn origin(&self) -> Option> { + let common_props = self.inner.get_common_properties(); + let common_props = common_props.borrow(); + let lp = self.inner.layout_properties.borrow(); + let tab = &lp.as_ref()?.computed_tab; + let p_anchor = Point2::new( + common_props + .anchor_x + .as_ref() + .map(|x| x.get().get_pixels(tab.bounds.0)) + .unwrap_or(0.0), + common_props + .anchor_y + .as_ref() + .map(|y| y.get().get_pixels(tab.bounds.1)) + .unwrap_or(0.0), + ); + let origin_window: Point2 = (tab.transform * p_anchor).to_world(); + Some(origin_window) + } + + pub fn transform(&self) -> Option> { + let up_lp = self.inner.layout_properties.borrow_mut(); + if let Some(lp) = up_lp.as_ref() { + Some(lp.computed_tab.transform.inverse().between_worlds()) + } else { + None + } + } + + pub fn bounding_points(&self) -> Option<[Point2; 4]> { + let lp = self.inner.layout_properties.borrow(); + if let Some(layout) = lp.as_ref() { + Some(layout.computed_tab.corners().map(Point2::to_world)) + } else { + None + } + } + + pub fn is_descendant_of(&self, node: &NodeInterface) -> bool { + self.inner.is_descendant_of(&node.inner.id_chain) } } diff --git a/pax-runtime/src/engine/expanded_node.rs b/pax-runtime/src/engine/expanded_node.rs index 6ffe1abcc..05c5a2614 100644 --- a/pax-runtime/src/engine/expanded_node.rs +++ b/pax-runtime/src/engine/expanded_node.rs @@ -17,7 +17,7 @@ use crate::api::{ ArgsButtonClick, ArgsCheckboxChange, ArgsClap, ArgsClick, ArgsContextMenu, ArgsDoubleClick, ArgsKeyDown, ArgsKeyPress, ArgsKeyUp, ArgsMouseDown, ArgsMouseMove, ArgsMouseOut, ArgsMouseOver, ArgsMouseUp, ArgsScroll, ArgsTextboxChange, ArgsTouchEnd, ArgsTouchMove, - ArgsTouchStart, ArgsWheel, Axis, CommonProperties, NodeContext, RenderContext, Size, + ArgsTouchStart, ArgsWheel, Axis, CommonProperties, EngineContext, RenderContext, Size, }; use crate::{ @@ -109,7 +109,7 @@ macro_rules! dispatch_event_handler { bounds_parent }) .unwrap_or(globals.viewport.bounds); - let context = NodeContext { + let context = EngineContext { bounds_self, bounds_parent, frames_elapsed: globals.frames_elapsed, @@ -380,7 +380,7 @@ impl ExpandedNode { func(self, val); } - pub fn get_node_context<'a>(&'a self, context: &'a RuntimeContext) -> NodeContext { + pub fn get_node_context<'a>(&'a self, context: &'a RuntimeContext) -> EngineContext { let globals = context.globals(); let computed_props = self.layout_properties.borrow(); let bounds_self = computed_props @@ -395,7 +395,7 @@ impl ExpandedNode { props.as_ref().map(|v| v.computed_tab.bounds) }) .unwrap_or(globals.viewport.bounds); - NodeContext { + EngineContext { frames_elapsed: globals.frames_elapsed, bounds_self, bounds_parent, diff --git a/pax-runtime/src/engine/mod.rs b/pax-runtime/src/engine/mod.rs index b667077ee..9ca1afae6 100644 --- a/pax-runtime/src/engine/mod.rs +++ b/pax-runtime/src/engine/mod.rs @@ -8,7 +8,7 @@ use std::rc::Rc; use pax_message::{NativeMessage, OcclusionPatch}; use crate::api::{ - CommonProperties, Interpolatable, Layer, NodeContext, OcclusionLayerGen, RenderContext, + CommonProperties, EngineContext, Interpolatable, Layer, OcclusionLayerGen, RenderContext, TransitionManager, }; use crate::math::Point2; @@ -82,7 +82,7 @@ impl PropertiesComputable for CommonProperties { pub struct HandlerRegistry { pub handlers: - HashMap>, &NodeContext, Option>)>>, + HashMap>, &EngineContext, Option>)>>, } impl Default for HandlerRegistry { diff --git a/pax-runtime/src/math.rs b/pax-runtime/src/math.rs index 9b0047865..6f196eea7 100644 --- a/pax-runtime/src/math.rs +++ b/pax-runtime/src/math.rs @@ -10,9 +10,8 @@ pub use point::Point2; pub use transform::Transform2; pub use vector::Vector2; -pub trait Space: Copy + Clone {} +pub trait Space {} -#[derive(Copy, Clone)] pub struct Generic; impl Space for Generic {} diff --git a/pax-std/src/stacker.rs b/pax-std/src/stacker.rs index 2a4652378..9503fe0aa 100644 --- a/pax-std/src/stacker.rs +++ b/pax-std/src/stacker.rs @@ -3,7 +3,7 @@ use crate::types::{StackerCell, StackerDirection}; use pax_engine::api::Numeric; use pax_engine::api::{Property, Size, Transform2D}; use pax_engine::*; -use pax_runtime::api::{NodeContext, PropertyLiteral}; +use pax_runtime::api::{EngineContext, PropertyLiteral}; /// Stacker lays out a series of nodes either /// vertically or horizontally (i.e. a single row or column) with a specified gutter in between @@ -51,7 +51,7 @@ impl Default for Stacker { } impl Stacker { - pub fn handle_tick(&mut self, ctx: &NodeContext) { + pub fn handle_tick(&mut self, ctx: &EngineContext) { let cells = self.cells.get().get_as_float(); let bounds = ctx.bounds_self; From 8c17908a65be3628059125d0909c1cfe4568b246 Mon Sep 17 00:00:00 2001 From: Samuel Selleck Date: Fri, 16 Feb 2024 13:41:29 -0800 Subject: [PATCH 08/10] moved exports --- pax-engine/src/lib.rs | 2 +- pax-runtime/src/api.rs | 2 +- pax-runtime/src/engine/mod.rs | 2 +- pax-runtime/src/engine/{design_utils.rs => node_interface.rs} | 0 pax-runtime/src/lib.rs | 1 - 5 files changed, 3 insertions(+), 4 deletions(-) rename pax-runtime/src/engine/{design_utils.rs => node_interface.rs} (100%) diff --git a/pax-engine/src/lib.rs b/pax-engine/src/lib.rs index 7c264a5d4..fcd6e273a 100644 --- a/pax-engine/src/lib.rs +++ b/pax-engine/src/lib.rs @@ -2,7 +2,7 @@ pub extern crate pax_macro; pub use pax_macro::*; pub use pax_runtime::api; -pub use pax_runtime::design_utils; +pub use pax_runtime::engine::node_interface::*; pub use pax_runtime::math; pub use pax_runtime::rendering; diff --git a/pax-runtime/src/api.rs b/pax-runtime/src/api.rs index 44964424e..4d9d6879d 100644 --- a/pax-runtime/src/api.rs +++ b/pax-runtime/src/api.rs @@ -11,8 +11,8 @@ use lazy_static::lazy_static; use mut_static::MutStatic; use piet::PaintBrush; -use crate::design_utils::NodeInterface; use crate::math::{Point2, Space}; +use crate::node_interface::NodeInterface; pub use crate::numeric::Numeric; use crate::{PropertyExpression, RuntimeContext}; use pax_manifest::constants::COMMON_PROPERTIES_TYPE; diff --git a/pax-runtime/src/engine/mod.rs b/pax-runtime/src/engine/mod.rs index 9ca1afae6..3476bcdc5 100644 --- a/pax-runtime/src/engine/mod.rs +++ b/pax-runtime/src/engine/mod.rs @@ -20,7 +20,7 @@ use crate::{ RuntimePropertiesStackFrame, TransformAndBounds, }; -pub mod design_utils; +pub mod node_interface; /// The atomic unit of rendering; also the container for each unique tuple of computed properties. /// Represents an expanded node, that is "expanded" in the context of computed properties and repeat expansion. diff --git a/pax-runtime/src/engine/design_utils.rs b/pax-runtime/src/engine/node_interface.rs similarity index 100% rename from pax-runtime/src/engine/design_utils.rs rename to pax-runtime/src/engine/node_interface.rs diff --git a/pax-runtime/src/lib.rs b/pax-runtime/src/lib.rs index 48b1fac0e..6f242ece5 100644 --- a/pax-runtime/src/lib.rs +++ b/pax-runtime/src/lib.rs @@ -25,4 +25,3 @@ pub use crate::properties::*; pub use crate::rendering::*; pub use crate::repeat::*; pub use crate::slot::*; -pub use engine::design_utils; From e651e03a8af23b582dbeb411d1a695a8e0aa7f05 Mon Sep 17 00:00:00 2001 From: Samuel Selleck Date: Fri, 16 Feb 2024 14:51:51 -0800 Subject: [PATCH 09/10] rename back to NodeContext --- examples/src/camera/src/lib.rs | 6 +-- .../src/component_in_component/src/inner.rs | 4 +- .../src/component_in_component/src/lib.rs | 4 +- examples/src/fireworks/src/lib.rs | 6 +-- examples/src/hello-rgb/src/lib.rs | 2 +- examples/src/layer-tests/src/lib.rs | 6 +-- examples/src/one-rect/src/lib.rs | 2 +- examples/src/paths/src/lib.rs | 6 +-- examples/src/pax-intro/src/lib.rs | 8 ++-- examples/src/playground/src/lib.rs | 12 +++--- examples/src/raycast-tests/src/lib.rs | 12 +++--- examples/src/simple-conditional/src/lib.rs | 6 +-- examples/src/simple-stacker/src/lib.rs | 10 ++--- examples/src/words/src/lib.rs | 38 +++++++++---------- .../new-libdev-project-template/src/lib.rs | 6 +-- pax-compiler/new-project-template/src/lib.rs | 6 +-- .../cartridge_generation/cartridge.tera | 2 +- .../cartridge_generation/macros.tera | 2 +- pax-runtime/src/api.rs | 5 ++- pax-runtime/src/engine/expanded_node.rs | 8 ++-- pax-runtime/src/engine/mod.rs | 4 +- pax-std/src/stacker.rs | 4 +- 22 files changed, 80 insertions(+), 79 deletions(-) diff --git a/examples/src/camera/src/lib.rs b/examples/src/camera/src/lib.rs index 259fe183d..f8344ee21 100644 --- a/examples/src/camera/src/lib.rs +++ b/examples/src/camera/src/lib.rs @@ -1,5 +1,5 @@ #![allow(unused_imports)] -use pax_engine::api::{ArgsClick, EasingCurve, EngineContext, Property}; +use pax_engine::api::{ArgsClick, EasingCurve, NodeContext, Property}; use pax_engine::Pax; use pax_std::primitives::{Ellipse, Frame, Group, Rectangle, Text}; @@ -20,13 +20,13 @@ pub struct TypeExample { } impl Camera { - pub fn handle_mount(&mut self, _: EngineContext) { + pub fn handle_mount(&mut self, _: NodeContext) { self.zoom.set(2.0); self.pan_x.set(0.0); self.pan_y.set(0.0); } - pub fn handle_click(&mut self, _: EngineContext, args: ArgsClick) { + 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(), diff --git a/examples/src/component_in_component/src/inner.rs b/examples/src/component_in_component/src/inner.rs index 97722d16b..4d48ff6f3 100644 --- a/examples/src/component_in_component/src/inner.rs +++ b/examples/src/component_in_component/src/inner.rs @@ -17,9 +17,9 @@ pub struct Inner { } impl Inner { - pub fn handle_mount(&mut self, ctx: &EngineContext) {} + pub fn handle_mount(&mut self, ctx: &NodeContext) {} - pub fn inner_clicked(&mut self, ctx: &EngineContext, args: ArgsClick) { + pub fn inner_clicked(&mut self, ctx: &NodeContext, args: ArgsClick) { self.inner_active.set(!self.inner_active.get()); } } diff --git a/examples/src/component_in_component/src/lib.rs b/examples/src/component_in_component/src/lib.rs index d5723ab51..ea96e2dac 100644 --- a/examples/src/component_in_component/src/lib.rs +++ b/examples/src/component_in_component/src/lib.rs @@ -20,12 +20,12 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &EngineContext) { + pub fn handle_mount(&mut self, ctx: &NodeContext) { self.message_outer.set("testing 12049".to_string()); self.x.set(Size::Percent(30.into())); } - pub fn outer_clicked(&mut self, ctx: &EngineContext, args: ArgsClick) { + pub fn outer_clicked(&mut self, ctx: &NodeContext, args: ArgsClick) { self.outer_active.set(!self.outer_active.get()); } } diff --git a/examples/src/fireworks/src/lib.rs b/examples/src/fireworks/src/lib.rs index 31aef5fd6..46a3ed4a6 100644 --- a/examples/src/fireworks/src/lib.rs +++ b/examples/src/fireworks/src/lib.rs @@ -1,5 +1,5 @@ #![allow(unused_imports)] -use pax_engine::api::{ArgsClick, ArgsWheel, EasingCurve, EngineContext}; +use pax_engine::api::{ArgsClick, ArgsWheel, EasingCurve, NodeContext}; use pax_engine::*; use pax_std::primitives::{Ellipse, Frame, Group, Path, Rectangle, Text}; @@ -14,13 +14,13 @@ pub struct Fireworks { const ROTATION_COEFFICIENT: f64 = 0.00010; impl Fireworks { - pub fn handle_scroll(&mut self, _ctx: &EngineContext, args: ArgsWheel) { + pub fn handle_scroll(&mut self, _ctx: &NodeContext, args: ArgsWheel) { let old_t = self.rotation.get(); let new_t = old_t - args.delta_y * ROTATION_COEFFICIENT; self.rotation.set(f64::max(0.0, new_t)); } - pub fn handle_pre_render(&mut self, _ctx: &EngineContext) { + pub fn handle_pre_render(&mut self, _ctx: &NodeContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } diff --git a/examples/src/hello-rgb/src/lib.rs b/examples/src/hello-rgb/src/lib.rs index 0b384e8d8..29f9e5156 100644 --- a/examples/src/hello-rgb/src/lib.rs +++ b/examples/src/hello-rgb/src/lib.rs @@ -11,7 +11,7 @@ pub struct HelloRGB { const ROTATION_COEFFICIENT: f64 = 0.005; impl HelloRGB { - pub fn handle_scroll(&mut self, ctx: &EngineContext, args: ArgsWheel) { + pub fn handle_scroll(&mut self, ctx: &NodeContext, args: ArgsWheel) { let old_t = self.rotation.get(); let new_t = old_t + args.delta_y * ROTATION_COEFFICIENT; self.rotation.set(new_t); diff --git a/examples/src/layer-tests/src/lib.rs b/examples/src/layer-tests/src/lib.rs index c343d4116..83358bb1d 100644 --- a/examples/src/layer-tests/src/lib.rs +++ b/examples/src/layer-tests/src/lib.rs @@ -18,16 +18,16 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &EngineContext) { + pub fn handle_mount(&mut self, ctx: &NodeContext) { self.message.set("false".to_string()); } - pub fn handle_pre_render(&mut self, ctx: &EngineContext) { + pub fn handle_pre_render(&mut self, ctx: &NodeContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } - pub fn toggle(&mut self, ctx: &EngineContext, args: ArgsClick) { + pub fn toggle(&mut self, ctx: &NodeContext, args: ArgsClick) { self.activated.set(!self.activated.get()); self.message.set(format!("{}", self.activated.get())); } diff --git a/examples/src/one-rect/src/lib.rs b/examples/src/one-rect/src/lib.rs index 353cb020c..27f23ce4b 100644 --- a/examples/src/one-rect/src/lib.rs +++ b/examples/src/one-rect/src/lib.rs @@ -19,7 +19,7 @@ pub struct OneRect { impl OneRect { - pub fn handle_pre_render(&mut self, ctx: &EngineContext) { + pub fn handle_pre_render(&mut self, ctx: &NodeContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } diff --git a/examples/src/paths/src/lib.rs b/examples/src/paths/src/lib.rs index 9f57e97c3..52de1c59f 100644 --- a/examples/src/paths/src/lib.rs +++ b/examples/src/paths/src/lib.rs @@ -18,15 +18,15 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &EngineContext) { + pub fn handle_mount(&mut self, ctx: &NodeContext) { self.message.set("Click me".to_string()); } - pub fn handle_pre_render(&mut self, ctx: &EngineContext) { + pub fn handle_pre_render(&mut self, ctx: &NodeContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } - pub fn increment(&mut self, ctx: &EngineContext, args: ArgsClick) { + pub fn increment(&mut self, ctx: &NodeContext, args: ArgsClick) { let old_num_clicks = self.num_clicks.get(); self.num_clicks.set(old_num_clicks + 1); self.message diff --git a/examples/src/pax-intro/src/lib.rs b/examples/src/pax-intro/src/lib.rs index 78e9034ca..1451205dc 100644 --- a/examples/src/pax-intro/src/lib.rs +++ b/examples/src/pax-intro/src/lib.rs @@ -32,12 +32,12 @@ const N_Y: f64 = 10.0; const LEN: usize = N_X as usize * N_Y as usize; impl DynamicObject { - pub fn handle_mount(&mut self, _ctx: &EngineContext) { + pub fn handle_mount(&mut self, _ctx: &NodeContext) { self.rects.set(vec![Rect::default(); LEN]); self.rects_bellow.set(vec![Rect::default(); LEN]); } - pub fn handle_pre_render(&mut self, ctx: &EngineContext) { + pub fn handle_pre_render(&mut self, ctx: &NodeContext) { let offsets = [0.1, 0.5, 1.0, 0.2, 0.3, 0.9, 0.3, 0.8, 0.7, 0.6]; let div_line = [-4, -1, -2, 0, 1, -1, 0, 3, 2, 4]; let t = *self.ticks.get(); @@ -93,9 +93,9 @@ impl DynamicObject { } } - pub fn increment(&mut self, _ctx: &EngineContext, _args: ArgsClick) {} + pub fn increment(&mut self, _ctx: &NodeContext, _args: ArgsClick) {} - pub fn mouse_move(&mut self, _ctx: &EngineContext, args: ArgsMouseMove) { + pub fn mouse_move(&mut self, _ctx: &NodeContext, args: ArgsMouseMove) { self.mouse_x.set(args.mouse.x); self.mouse_y.set(args.mouse.y); } diff --git a/examples/src/playground/src/lib.rs b/examples/src/playground/src/lib.rs index 6b641cb30..af3a455ec 100644 --- a/examples/src/playground/src/lib.rs +++ b/examples/src/playground/src/lib.rs @@ -23,17 +23,17 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &EngineContext) { + pub fn handle_mount(&mut self, ctx: &NodeContext) { self.message.set("Click me".to_string()); self.color .set(Color::rgba(1.0.into(), 0.3.into(), 0.6.into(), 1.0.into())); } - pub fn handle_pre_render(&mut self, ctx: &EngineContext) { + pub fn handle_pre_render(&mut self, ctx: &NodeContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } - pub fn toggle(&mut self, ctx: &EngineContext, args: ArgsClick) { + pub fn toggle(&mut self, ctx: &NodeContext, args: ArgsClick) { let old_num_clicks = self.num_clicks.get(); self.num_clicks.set(old_num_clicks + 1); self.message @@ -41,7 +41,7 @@ impl Example { self.conditional.set(!self.conditional.get()); } - pub fn checkbox_change(&mut self, ctx: &EngineContext, args: ArgsCheckboxChange) { + pub fn checkbox_change(&mut self, ctx: &NodeContext, args: ArgsCheckboxChange) { self.checked.set(!args.checked); self.align_vertical.set(match self.checked.get() { true => TextAlignVertical::Top, @@ -56,11 +56,11 @@ impl Example { } } - pub fn textbox_change(&mut self, ctx: &EngineContext, args: ArgsTextboxChange) { + pub fn textbox_change(&mut self, ctx: &NodeContext, args: ArgsTextboxChange) { self.textbox_text.set(args.text); } - pub fn button_click(&mut self, ctx: &EngineContext, args: ArgsButtonClick) { + pub fn button_click(&mut self, ctx: &NodeContext, args: ArgsButtonClick) { self.color .set(Color::rgba(1.0.into(), 0.3.into(), 0.6.into(), 1.0.into())); } diff --git a/examples/src/raycast-tests/src/lib.rs b/examples/src/raycast-tests/src/lib.rs index 61802c81a..7eb6d0be7 100644 --- a/examples/src/raycast-tests/src/lib.rs +++ b/examples/src/raycast-tests/src/lib.rs @@ -17,25 +17,25 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &EngineContext) {} + pub fn handle_mount(&mut self, ctx: &NodeContext) {} - pub fn frame1(&mut self, ctx: &EngineContext, args: ArgsMouseMove) { + pub fn frame1(&mut self, ctx: &NodeContext, args: ArgsMouseMove) { self.hit_outer.set(format!("hit outer: frame {}", 1)); } - pub fn frame2(&mut self, ctx: &EngineContext, args: ArgsMouseMove) { + pub fn frame2(&mut self, ctx: &NodeContext, args: ArgsMouseMove) { self.hit_outer.set(format!("hit outer: frame {}", 2)); } - pub fn frame1rect1(&mut self, ctx: &EngineContext, args: ArgsMouseMove) { + pub fn frame1rect1(&mut self, ctx: &NodeContext, args: ArgsMouseMove) { self.hit_inner.set(format!("hit inner: rect {}", 1)); } - pub fn frame1rect2(&mut self, ctx: &EngineContext, args: ArgsMouseMove) { + pub fn frame1rect2(&mut self, ctx: &NodeContext, args: ArgsMouseMove) { self.hit_inner.set(format!("hit inner: rect {}", 2)); } - pub fn frame2rect1(&mut self, ctx: &EngineContext, args: ArgsMouseMove) { + pub fn frame2rect1(&mut self, ctx: &NodeContext, args: ArgsMouseMove) { self.hit_inner.set(format!("hit inner: rect {}", 1)); } } diff --git a/examples/src/simple-conditional/src/lib.rs b/examples/src/simple-conditional/src/lib.rs index 332ab7f9f..1af0f2410 100644 --- a/examples/src/simple-conditional/src/lib.rs +++ b/examples/src/simple-conditional/src/lib.rs @@ -19,17 +19,17 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &EngineContext) { + pub fn handle_mount(&mut self, ctx: &NodeContext) { self.message.set("Click me".to_string()); self.activated.set(false); self.not_activated.set(true); } - pub fn handle_pre_render(&mut self, ctx: &EngineContext) { + pub fn handle_pre_render(&mut self, ctx: &NodeContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } - pub fn increment(&mut self, ctx: &EngineContext, args: ArgsClick) { + pub fn increment(&mut self, ctx: &NodeContext, args: ArgsClick) { self.activated.set(!self.activated.get()); self.not_activated.set(!self.activated.get()); self.message diff --git a/examples/src/simple-stacker/src/lib.rs b/examples/src/simple-stacker/src/lib.rs index bd649c425..933fc6906 100644 --- a/examples/src/simple-stacker/src/lib.rs +++ b/examples/src/simple-stacker/src/lib.rs @@ -19,20 +19,20 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &EngineContext) { + pub fn handle_mount(&mut self, ctx: &NodeContext) { self.num.set(1); } - pub fn click0(&mut self, ctx: &EngineContext, args: ArgsClick) { + pub fn click0(&mut self, ctx: &NodeContext, args: ArgsClick) { self.num.set(1); } - pub fn click1(&mut self, ctx: &EngineContext, args: ArgsClick) { + pub fn click1(&mut self, ctx: &NodeContext, args: ArgsClick) { self.num.set(3); } - pub fn click2(&mut self, ctx: &EngineContext, args: ArgsClick) { + pub fn click2(&mut self, ctx: &NodeContext, args: ArgsClick) { self.num.set(5); } - pub fn handle_pre_render(&mut self, ctx: &EngineContext) {} + pub fn handle_pre_render(&mut self, ctx: &NodeContext) {} } diff --git a/examples/src/words/src/lib.rs b/examples/src/words/src/lib.rs index 35d26da20..ffc806f70 100644 --- a/examples/src/words/src/lib.rs +++ b/examples/src/words/src/lib.rs @@ -2,7 +2,7 @@ use pax_engine::api::{ ArgsClick, ArgsClap, ArgsScroll, ArgsTouchStart, ArgsTouchMove, ArgsTouchEnd, ArgsKeyDown, ArgsKeyUp, ArgsKeyPress, ArgsDoubleClick, ArgsMouseMove, ArgsWheel, ArgsMouseDown, ArgsMouseUp, ArgsMouseOver, ArgsMouseOut, ArgsContextMenu, - EngineContext, Property, PropertyLiteral + NodeContext, Property, PropertyLiteral }; use pax_engine::Pax; use pax_std::primitives::{Ellipse, Frame, Group, Path, Rectangle, Text, Image}; @@ -16,74 +16,74 @@ pub struct Words { } impl Words { - pub fn handle_mount(&mut self, _ctx: &EngineContext) { + pub fn handle_mount(&mut self, _ctx: &NodeContext) { } - pub fn handle_clap(&mut self, _ctx: &EngineContext, _args: ArgsClap) { + pub fn handle_clap(&mut self, _ctx: &NodeContext, _args: ArgsClap) { self.content.set("Clap".to_string()); } - pub fn handle_scroll(&mut self, _ctx: &EngineContext, _args: ArgsScroll) { + pub fn handle_scroll(&mut self, _ctx: &NodeContext, _args: ArgsScroll) { self.content.set("Scroll".to_string()); } - pub fn handle_touch_start(&mut self, _ctx: &EngineContext, _args: ArgsTouchStart) { + pub fn handle_touch_start(&mut self, _ctx: &NodeContext, _args: ArgsTouchStart) { self.content.set("Touch Start".to_string()); } - pub fn handle_touch_move(&mut self, _ctx: &EngineContext, _args: ArgsTouchMove) { + pub fn handle_touch_move(&mut self, _ctx: &NodeContext, _args: ArgsTouchMove) { self.content.set("Touch Move".to_string()); } - pub fn handle_touch_end(&mut self, _ctx: &EngineContext, _args: ArgsTouchEnd) { + pub fn handle_touch_end(&mut self, _ctx: &NodeContext, _args: ArgsTouchEnd) { self.content.set("Touch End".to_string()); } - pub fn handle_key_down(&mut self, _ctx: &EngineContext, _args: ArgsKeyDown) { + pub fn handle_key_down(&mut self, _ctx: &NodeContext, _args: ArgsKeyDown) { self.content.set("Key Down".to_string()); } - pub fn handle_key_up(&mut self, _ctx: &EngineContext, _args: ArgsKeyUp) { + pub fn handle_key_up(&mut self, _ctx: &NodeContext, _args: ArgsKeyUp) { self.content.set("Key Up".to_string()); } - pub fn handle_key_press(&mut self, _ctx: &EngineContext, _args: ArgsKeyPress) { + pub fn handle_key_press(&mut self, _ctx: &NodeContext, _args: ArgsKeyPress) { self.content.set("Key Press".to_string()); } - pub fn handle_click(&mut self, _ctx: &EngineContext, _args: ArgsClick) { + pub fn handle_click(&mut self, _ctx: &NodeContext, _args: ArgsClick) { self.content.set("Click".to_string()); } - pub fn handle_double_click(&mut self, _ctx: &EngineContext, _args: ArgsDoubleClick) { + pub fn handle_double_click(&mut self, _ctx: &NodeContext, _args: ArgsDoubleClick) { self.content.set("Double Click".to_string()); } - pub fn handle_mouse_move(&mut self, _ctx: &EngineContext, _args: ArgsMouseMove) { + pub fn handle_mouse_move(&mut self, _ctx: &NodeContext, _args: ArgsMouseMove) { self.content.set("Mouse Move".to_string()); } - pub fn handle_wheel(&mut self, _ctx: &EngineContext, _args: ArgsWheel) { + pub fn handle_wheel(&mut self, _ctx: &NodeContext, _args: ArgsWheel) { self.content.set("Wheel".to_string()); } - pub fn handle_mouse_down(&mut self, _ctx: &EngineContext, _args: ArgsMouseDown) { + pub fn handle_mouse_down(&mut self, _ctx: &NodeContext, _args: ArgsMouseDown) { self.content.set("Mouse Down".to_string()); } - pub fn handle_mouse_up(&mut self, _ctx: &EngineContext, _args: ArgsMouseUp) { + pub fn handle_mouse_up(&mut self, _ctx: &NodeContext, _args: ArgsMouseUp) { self.content.set("Mouse Up".to_string()); } - pub fn handle_mouse_over(&mut self, _ctx: &EngineContext, _args: ArgsMouseOver) { + pub fn handle_mouse_over(&mut self, _ctx: &NodeContext, _args: ArgsMouseOver) { self.content.set("Mouse Over".to_string()); } - pub fn handle_mouse_out(&mut self, _ctx: &EngineContext, _args: ArgsMouseOut) { + pub fn handle_mouse_out(&mut self, _ctx: &NodeContext, _args: ArgsMouseOut) { self.content.set("Mouse Out".to_string()); } - pub fn handle_context_menu(&mut self, _ctx: &EngineContext, _args: ArgsContextMenu){ + pub fn handle_context_menu(&mut self, _ctx: &NodeContext, _args: ArgsContextMenu){ self.content.set("Context Menu".to_string()); } } \ No newline at end of file diff --git a/pax-compiler/new-libdev-project-template/src/lib.rs b/pax-compiler/new-libdev-project-template/src/lib.rs index 36e1a7af4..5a002e849 100644 --- a/pax-compiler/new-libdev-project-template/src/lib.rs +++ b/pax-compiler/new-libdev-project-template/src/lib.rs @@ -18,15 +18,15 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &EngineContext) { + pub fn handle_mount(&mut self, ctx: &NodeContext) { self.message.set("Click me".to_string()); } - pub fn handle_pre_render(&mut self, ctx: &EngineContext) { + pub fn handle_pre_render(&mut self, ctx: &NodeContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } - pub fn increment(&mut self, ctx: &EngineContext, args: ArgsClick){ + pub fn increment(&mut self, ctx: &NodeContext, args: ArgsClick){ let old_num_clicks = self.num_clicks.get(); self.num_clicks.set(old_num_clicks + 1); self.message.set(format!("{} clicks", self.num_clicks.get())); diff --git a/pax-compiler/new-project-template/src/lib.rs b/pax-compiler/new-project-template/src/lib.rs index 36e1a7af4..5a002e849 100644 --- a/pax-compiler/new-project-template/src/lib.rs +++ b/pax-compiler/new-project-template/src/lib.rs @@ -18,15 +18,15 @@ pub struct Example { } impl Example { - pub fn handle_mount(&mut self, ctx: &EngineContext) { + pub fn handle_mount(&mut self, ctx: &NodeContext) { self.message.set("Click me".to_string()); } - pub fn handle_pre_render(&mut self, ctx: &EngineContext) { + pub fn handle_pre_render(&mut self, ctx: &NodeContext) { let old_ticks = self.ticks.get(); self.ticks.set(old_ticks + 1); } - pub fn increment(&mut self, ctx: &EngineContext, args: ArgsClick){ + pub fn increment(&mut self, ctx: &NodeContext, args: ArgsClick){ let old_num_clicks = self.num_clicks.get(); self.num_clicks.set(old_num_clicks + 1); self.message.set(format!("{} clicks", self.num_clicks.get())); diff --git a/pax-compiler/templates/cartridge_generation/cartridge.tera b/pax-compiler/templates/cartridge_generation/cartridge.tera index a3218d818..774c95ac7 100644 --- a/pax-compiler/templates/cartridge_generation/cartridge.tera +++ b/pax-compiler/templates/cartridge_generation/cartridge.tera @@ -161,7 +161,7 @@ pub trait ComponentFactory { /// Returns the requested closure for the handler registry based on the defined handlers for this component /// The argument type is extrapolated based on how the handler was used in the initial compiled template - fn build_handler(&self, fn_name: &str) -> fn(Rc>, &EngineContext, Option::>); + fn build_handler(&self, fn_name: &str) -> fn(Rc>, &NodeContext, Option::>); /// Returns the handler registry based on the defined handlers for this component fn build_component_handlers(&self, handlers: Vec<(String, Vec)>) -> Rc>; diff --git a/pax-compiler/templates/cartridge_generation/macros.tera b/pax-compiler/templates/cartridge_generation/macros.tera index a892dc02c..e3aabbe93 100644 --- a/pax-compiler/templates/cartridge_generation/macros.tera +++ b/pax-compiler/templates/cartridge_generation/macros.tera @@ -33,7 +33,7 @@ impl ComponentFactory for {{component.pascal_identifier}}Factory { }))) } - fn build_handler(&self,fn_name: &str) -> fn(Rc>, &EngineContext, Option::>) { + fn build_handler(&self,fn_name: &str) -> fn(Rc>, &NodeContext, Option::>) { match fn_name { {% for handler in component.handlers %} "{{handler.name}}" => { diff --git a/pax-runtime/src/api.rs b/pax-runtime/src/api.rs index 4d9d6879d..ee39264f9 100644 --- a/pax-runtime/src/api.rs +++ b/pax-runtime/src/api.rs @@ -137,7 +137,7 @@ pub type Property = Box>; #[derive(Clone)] #[cfg_attr(debug_assertions, derive(Debug))] -pub struct EngineContext<'a> { +pub struct NodeContext<'a> { /// The current global engine tick count pub frames_elapsed: usize, /// The bounds of this element's immediate container (parent) in px @@ -155,7 +155,8 @@ pub struct Window; impl Space for Window {} -impl EngineContext<'_> { +#[cfg(feature = "designtime")] +impl NodeContext<'_> { pub fn raycast(&self, point: Point2) -> Vec { let expanded_nodes = self.runtime_context diff --git a/pax-runtime/src/engine/expanded_node.rs b/pax-runtime/src/engine/expanded_node.rs index 05c5a2614..6ffe1abcc 100644 --- a/pax-runtime/src/engine/expanded_node.rs +++ b/pax-runtime/src/engine/expanded_node.rs @@ -17,7 +17,7 @@ use crate::api::{ ArgsButtonClick, ArgsCheckboxChange, ArgsClap, ArgsClick, ArgsContextMenu, ArgsDoubleClick, ArgsKeyDown, ArgsKeyPress, ArgsKeyUp, ArgsMouseDown, ArgsMouseMove, ArgsMouseOut, ArgsMouseOver, ArgsMouseUp, ArgsScroll, ArgsTextboxChange, ArgsTouchEnd, ArgsTouchMove, - ArgsTouchStart, ArgsWheel, Axis, CommonProperties, EngineContext, RenderContext, Size, + ArgsTouchStart, ArgsWheel, Axis, CommonProperties, NodeContext, RenderContext, Size, }; use crate::{ @@ -109,7 +109,7 @@ macro_rules! dispatch_event_handler { bounds_parent }) .unwrap_or(globals.viewport.bounds); - let context = EngineContext { + let context = NodeContext { bounds_self, bounds_parent, frames_elapsed: globals.frames_elapsed, @@ -380,7 +380,7 @@ impl ExpandedNode { func(self, val); } - pub fn get_node_context<'a>(&'a self, context: &'a RuntimeContext) -> EngineContext { + pub fn get_node_context<'a>(&'a self, context: &'a RuntimeContext) -> NodeContext { let globals = context.globals(); let computed_props = self.layout_properties.borrow(); let bounds_self = computed_props @@ -395,7 +395,7 @@ impl ExpandedNode { props.as_ref().map(|v| v.computed_tab.bounds) }) .unwrap_or(globals.viewport.bounds); - EngineContext { + NodeContext { frames_elapsed: globals.frames_elapsed, bounds_self, bounds_parent, diff --git a/pax-runtime/src/engine/mod.rs b/pax-runtime/src/engine/mod.rs index 3476bcdc5..53c54679d 100644 --- a/pax-runtime/src/engine/mod.rs +++ b/pax-runtime/src/engine/mod.rs @@ -8,7 +8,7 @@ use std::rc::Rc; use pax_message::{NativeMessage, OcclusionPatch}; use crate::api::{ - CommonProperties, EngineContext, Interpolatable, Layer, OcclusionLayerGen, RenderContext, + CommonProperties, NodeContext, Interpolatable, Layer, OcclusionLayerGen, RenderContext, TransitionManager, }; use crate::math::Point2; @@ -82,7 +82,7 @@ impl PropertiesComputable for CommonProperties { pub struct HandlerRegistry { pub handlers: - HashMap>, &EngineContext, Option>)>>, + HashMap>, &NodeContext, Option>)>>, } impl Default for HandlerRegistry { diff --git a/pax-std/src/stacker.rs b/pax-std/src/stacker.rs index 9503fe0aa..2a4652378 100644 --- a/pax-std/src/stacker.rs +++ b/pax-std/src/stacker.rs @@ -3,7 +3,7 @@ use crate::types::{StackerCell, StackerDirection}; use pax_engine::api::Numeric; use pax_engine::api::{Property, Size, Transform2D}; use pax_engine::*; -use pax_runtime::api::{EngineContext, PropertyLiteral}; +use pax_runtime::api::{NodeContext, PropertyLiteral}; /// Stacker lays out a series of nodes either /// vertically or horizontally (i.e. a single row or column) with a specified gutter in between @@ -51,7 +51,7 @@ impl Default for Stacker { } impl Stacker { - pub fn handle_tick(&mut self, ctx: &EngineContext) { + pub fn handle_tick(&mut self, ctx: &NodeContext) { let cells = self.cells.get().get_as_float(); let bounds = ctx.bounds_self; From 81f77157c1f273efb0c8b0187d44914e7ced316b Mon Sep 17 00:00:00 2001 From: Samuel Selleck Date: Fri, 16 Feb 2024 15:14:29 -0800 Subject: [PATCH 10/10] fmt --- pax-runtime/src/engine/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pax-runtime/src/engine/mod.rs b/pax-runtime/src/engine/mod.rs index 53c54679d..81625dae5 100644 --- a/pax-runtime/src/engine/mod.rs +++ b/pax-runtime/src/engine/mod.rs @@ -8,7 +8,7 @@ use std::rc::Rc; use pax_message::{NativeMessage, OcclusionPatch}; use crate::api::{ - CommonProperties, NodeContext, Interpolatable, Layer, OcclusionLayerGen, RenderContext, + CommonProperties, Interpolatable, Layer, NodeContext, OcclusionLayerGen, RenderContext, TransitionManager, }; use crate::math::Point2;