diff --git a/api/sixtyfps-cpp/include/sixtyfps_pathelements.h b/api/sixtyfps-cpp/include/sixtyfps_pathelements.h index e7446cd87..20cebfc15 100644 --- a/api/sixtyfps-cpp/include/sixtyfps_pathelements.h +++ b/api/sixtyfps-cpp/include/sixtyfps_pathelements.h @@ -6,6 +6,7 @@ namespace sixtyfps { using internal::types::PathElement; +using internal::types::PathLineTo; struct PathElements { diff --git a/api/sixtyfps-node/native/lib.rs b/api/sixtyfps-node/native/lib.rs index c99426cba..1480e1239 100644 --- a/api/sixtyfps-node/native/lib.rs +++ b/api/sixtyfps-node/native/lib.rs @@ -1,7 +1,7 @@ use core::cell::RefCell; use neon::prelude::*; use sixtyfps_compilerlib::typeregister::Type; -use sixtyfps_corelib::abi::datastructures::{PathElement, Resource}; +use sixtyfps_corelib::abi::datastructures::{PathElement, PathLineTo, Resource}; use sixtyfps_corelib::{ComponentRefPin, EvaluationContext}; use std::rc::Rc; @@ -161,7 +161,7 @@ fn to_js_value<'cx>( let element_object = JsObject::new(cx); match element { - PathElement::LineTo { x, y } => { + PathElement::LineTo(PathLineTo { x, y }) => { let x = JsNumber::new(cx, *x); let x = x.as_value(cx); element_object.set(cx, "x", x)?; diff --git a/examples/graphicstest/src/main.rs b/examples/graphicstest/src/main.rs index 82d23f89a..4209b1733 100644 --- a/examples/graphicstest/src/main.rs +++ b/examples/graphicstest/src/main.rs @@ -1,6 +1,6 @@ use cgmath::{Matrix4, SquareMatrix, Vector3}; use sixtyfps_corelib::abi::datastructures::{ - Color, PathElement, PathElements, RenderingPrimitive, Resource, + Color, PathElement, PathElements, PathLineTo, RenderingPrimitive, Resource, }; use sixtyfps_corelib::graphics::{ Frame, GraphicsBackend, RenderingCache, RenderingPrimitivesBuilder, @@ -65,8 +65,10 @@ fn main() { render_cache.allocate_entry(image_primitive) }; - const TRIANGLE_PATH: &'static [PathElement] = - &[PathElement::LineTo { x: 100., y: 50. }, PathElement::LineTo { x: 0., y: 100. }]; + const TRIANGLE_PATH: &'static [PathElement] = &[ + PathElement::LineTo(PathLineTo { x: 100., y: 50. }), + PathElement::LineTo(PathLineTo { x: 0., y: 100. }), + ]; let path_node = { let path_primitive = rendering_primitives_builder.create(RenderingPrimitive::Path { x: 50., diff --git a/sixtyfps_compiler/generator/cpp.rs b/sixtyfps_compiler/generator/cpp.rs index 23bbe87ab..cdff27df7 100644 --- a/sixtyfps_compiler/generator/cpp.rs +++ b/sixtyfps_compiler/generator/cpp.rs @@ -823,7 +823,7 @@ fn compile_expression(e: &crate::expression_tree::Expression, component: &Rc format!( - "sixtyfps::PathElement::LineTo({}, {})", + "sixtyfps::PathElement::LineTo(sixtyfps::PathLineTo{{{}, {}}})", compile_expression(x, component), compile_expression(y, component) ), diff --git a/sixtyfps_compiler/generator/rust.rs b/sixtyfps_compiler/generator/rust.rs index 9ce925923..ae9931d90 100644 --- a/sixtyfps_compiler/generator/rust.rs +++ b/sixtyfps_compiler/generator/rust.rs @@ -684,7 +684,7 @@ fn compile_expression(e: &Expression, component: &Rc) -> TokenStream crate::expression_tree::PathElement::LineTo { x, y } => { let x = compile_expression(x, component); let y = compile_expression(y, component); - quote!(PathElement::LineTo { x: #x as _, y: #y as _}) + quote!(PathElement::LineTo(PathLineTo { x: #x as _, y: #y as _} )) } }) .collect(); diff --git a/sixtyfps_runtime/corelib/abi/datastructures.rs b/sixtyfps_runtime/corelib/abi/datastructures.rs index b54a4ae44..459251564 100644 --- a/sixtyfps_runtime/corelib/abi/datastructures.rs +++ b/sixtyfps_runtime/corelib/abi/datastructures.rs @@ -6,6 +6,11 @@ use core::pin::Pin; use std::cell::Cell; use vtable::*; +#[cfg(feature = "rtti")] +use crate::rtti::{BuiltinItem, FieldInfo, FieldOffset, PropertyInfo, ValueType}; +use const_field_offset::FieldOffsets; +use corelib_macro::*; + /// 2D Rectangle pub type Rect = euclid::default::Rect; /// 2D Point @@ -247,18 +252,26 @@ impl Default for Resource { } } +#[repr(C)] +#[derive(FieldOffsets, Default, BuiltinItem, Clone, Debug, PartialEq)] +#[pin] +/// PathLineTo describes the event of moving the cursor on the path to the specified location +/// along a straight line. +pub struct PathLineTo { + #[rtti_field] + /// The x coordinate where the line should go to. + pub x: f32, + #[rtti_field] + /// The y coordinate where the line should go to. + pub y: f32, +} + #[repr(C)] #[derive(Clone, Debug, PartialEq)] /// PathElement describes a single element on a path, such as move-to, line-to, etc. pub enum PathElement { - /// Line to describes the event of moving the cursor on the path to the specified location - /// along a straight line. - LineTo { - /// The x coordinate where the line should go to. - x: f32, - /// The y coordinate where the line should go to. - y: f32, - }, + /// The LineTo variant describes a line. + LineTo(PathLineTo), } #[repr(C)] diff --git a/sixtyfps_runtime/interpreter/eval.rs b/sixtyfps_runtime/interpreter/eval.rs index 680b34f5c..9ba1c9974 100644 --- a/sixtyfps_runtime/interpreter/eval.rs +++ b/sixtyfps_runtime/interpreter/eval.rs @@ -4,8 +4,9 @@ use sixtyfps_compilerlib::expression_tree::{Expression, NamedReference, PathElem use sixtyfps_compilerlib::{object_tree::ElementRc, typeregister::Type}; use sixtyfps_corelib as corelib; use sixtyfps_corelib::{ - abi::datastructures::ItemRef, abi::primitives::PropertyAnimation, Color, EvaluationContext, - PathElements, Resource, SharedString, + abi::datastructures::ItemRef, abi::datastructures::PathLineTo, + abi::primitives::PropertyAnimation, Color, EvaluationContext, PathElements, Resource, + SharedString, }; use std::{collections::HashMap, rc::Rc}; @@ -325,14 +326,14 @@ pub fn eval_expression( >::from_iter( elements.iter().map(|element| match element { PathElement::LineTo { x, y } => { - sixtyfps_corelib::abi::datastructures::PathElement::LineTo { + sixtyfps_corelib::abi::datastructures::PathElement::LineTo(PathLineTo { x: eval_expression(&x, component_type, eval_context) .try_into() .unwrap(), y: eval_expression(&y, component_type, eval_context) .try_into() .unwrap(), - } + }) } }), ))) diff --git a/sixtyfps_runtime/rendering_backends/gl/lib.rs b/sixtyfps_runtime/rendering_backends/gl/lib.rs index 320e0d045..e86432555 100644 --- a/sixtyfps_runtime/rendering_backends/gl/lib.rs +++ b/sixtyfps_runtime/rendering_backends/gl/lib.rs @@ -5,8 +5,8 @@ use itertools::Itertools; use lyon::tessellation::geometry_builder::{BuffersBuilder, VertexBuffers}; use lyon::tessellation::{FillAttributes, FillOptions, FillTessellator}; use sixtyfps_corelib::abi::datastructures::{ - Color, ComponentWindow, ComponentWindowOpaque, PathElement, Point, Rect, RenderingPrimitive, - Resource, Size, + Color, ComponentWindow, ComponentWindowOpaque, PathElement, PathLineTo, Point, Rect, + RenderingPrimitive, Resource, Size, }; use sixtyfps_corelib::graphics::{ FillStyle, Frame as GraphicsFrame, GraphicsBackend, GraphicsWindow, HasRenderingPrimitive, @@ -342,7 +342,7 @@ impl RenderingPrimitivesBuilder for GLRenderingPrimitivesBuilder { let mut path_builder = lyon::path::Path::builder().with_svg(); for element in elements.iter() { match element { - PathElement::LineTo { x, y } => { + PathElement::LineTo(PathLineTo { x, y }) => { path_builder.line_to(Point::new(*x, *y)) } }