diff --git a/api/sixtyfps-cpp/include/sixtyfps_properties.h b/api/sixtyfps-cpp/include/sixtyfps_properties.h index 6302abe5a..a38925ff6 100644 --- a/api/sixtyfps-cpp/include/sixtyfps_properties.h +++ b/api/sixtyfps-cpp/include/sixtyfps_properties.h @@ -11,20 +11,16 @@ LICENSE END */ #include #include -namespace sixtyfps { -namespace cbindgen_private { +namespace sixtyfps::cbindgen_private { struct PropertyAnimation; } -} #include "sixtyfps_properties_internal.h" -namespace sixtyfps { +namespace sixtyfps::private_api { using cbindgen_private::StateInfo; -namespace private_api { - inline void sixtyfps_property_set_animated_binding_helper( const cbindgen_private::PropertyHandleOpaque *handle, void (*binding)(void *, int32_t *), void *user_data, void (*drop_user_data)(void *), @@ -301,6 +297,4 @@ private: cbindgen_private::PropertyTrackerOpaque inner; }; -} // namespace private_api - -} // namespace sixtyfps +} // namespace sixtyfps::private_api diff --git a/api/sixtyfps-rs/lib.rs b/api/sixtyfps-rs/lib.rs index 3a791720d..312e83ad2 100644 --- a/api/sixtyfps-rs/lib.rs +++ b/api/sixtyfps-rs/lib.rs @@ -208,11 +208,6 @@ pub fn register_font_from_path>( sixtyfps_rendering_backend_default::backend().register_font_from_path(path.as_ref()) } -// FIXME: this should not be in this namespace -// but the name is `sixtyfps::StateInfo` in builtin.60 -#[doc(hidden)] -pub use sixtyfps_corelib::properties::StateInfo; - /// internal re_exports used by the macro generated #[doc(hidden)] pub mod re_exports { @@ -241,7 +236,9 @@ pub mod re_exports { pub use sixtyfps_corelib::items::*; pub use sixtyfps_corelib::layout::*; pub use sixtyfps_corelib::model::*; - pub use sixtyfps_corelib::properties::{set_state_binding, Property, PropertyTracker}; + pub use sixtyfps_corelib::properties::{ + set_state_binding, Property, PropertyTracker, StateInfo, + }; pub use sixtyfps_corelib::slice::Slice; pub use sixtyfps_corelib::window::ComponentWindow; pub use sixtyfps_corelib::Color; diff --git a/sixtyfps_compiler/builtins.60 b/sixtyfps_compiler/builtins.60 index dacd5471d..a0b49562d 100644 --- a/sixtyfps_compiler/builtins.60 +++ b/sixtyfps_compiler/builtins.60 @@ -378,7 +378,7 @@ export struct StandardListViewItem := { } export struct StateInfo := { - //-name:sixtyfps::StateInfo + //-name:sixtyfps::private_api::StateInfo current_state: int, previous_state: int, //change_time: duration, diff --git a/sixtyfps_compiler/generator/rust.rs b/sixtyfps_compiler/generator/rust.rs index ac417867a..535370de1 100644 --- a/sixtyfps_compiler/generator/rust.rs +++ b/sixtyfps_compiler/generator/rust.rs @@ -55,7 +55,7 @@ fn rust_type(ty: &Type) -> Option { // This will produce a tuple Some(quote!((#(#elem,)*))) } - Type::Struct { name: Some(name), .. } => Some(name.parse().unwrap()), + Type::Struct { name: Some(name), .. } => Some(struct_name_to_tokens(&name)), Type::Array(o) => { let inner = rust_type(&o)?; Some(quote!(sixtyfps::re_exports::ModelHandle<#inner>)) @@ -1078,7 +1078,7 @@ fn compile_expression(expr: &Expression, component: &Rc) -> TokenStre let name = format_ident!("{}", name); quote!(#name: obj.#index as _) }); - let id : TokenStream = n.parse().unwrap(); + let id = struct_name_to_tokens(n); quote!({ let obj = #f; #id { #(#fields),*} }) } _ => f, @@ -1399,7 +1399,7 @@ fn compile_expression(expr: &Expression, component: &Rc) -> TokenStre }) }); if let Some(name) = name { - let name : TokenStream = name.parse().unwrap(); + let name : TokenStream = struct_name_to_tokens(name.as_str()); let keys = fields.keys().map(|k| k.parse::().unwrap()); quote!(#name { #(#keys: #elem,)* }) } else { @@ -1537,6 +1537,12 @@ fn compile_expression(expr: &Expression, component: &Rc) -> TokenStre } } +/// Return a TokenStream for a name (as in [`Type::Struct::name`]) +fn struct_name_to_tokens(name: &str) -> TokenStream { + // the name match the C++ signature so we need to change that to the rust namespace + name.replace("::private_api::", "::re_exports::").parse().unwrap() +} + fn compile_assignment( lhs: &Expression, op: char,