mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-30 13:51:13 +00:00
Change the field_offsets() function to a FIELD_OFFSETS associated const
This commit is contained in:
parent
de188e0a54
commit
1bfd708784
10 changed files with 156 additions and 156 deletions
|
@ -12,8 +12,8 @@ use syn::{parse_macro_input, spanned::Spanned, DeriveInput, VisRestricted, Visib
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
The macro FieldOffsets adds a `const fn field_offsets()` associated function to the struct, that
|
The macro FieldOffsets adds a `FIELD_OFFSETS` associated const to the struct, that
|
||||||
returns an object which has fields with the same name as the fields of the original struct,
|
is an object which has fields with the same name as the fields of the original struct,
|
||||||
each field is of type `const_field_offset::FieldOffset`
|
each field is of type `const_field_offset::FieldOffset`
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
@ -25,7 +25,7 @@ struct Foo {
|
||||||
field_2 : u32,
|
field_2 : u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
const FOO : usize = Foo::field_offsets().field_2.get_byte_offset();
|
const FOO : usize = Foo::FIELD_OFFSETS.field_2.get_byte_offset();
|
||||||
assert_eq!(FOO, 4);
|
assert_eq!(FOO, 4);
|
||||||
|
|
||||||
// This would not work on stable rust at the moment (rust 1.43)
|
// This would not work on stable rust at the moment (rust 1.43)
|
||||||
|
@ -71,7 +71,7 @@ struct Foo {
|
||||||
field_2 : u32,
|
field_2 : u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
const FIELD_2 : FieldOffset<Foo, u32, PinnedFlag> = Foo::field_offsets().field_2;
|
const FIELD_2 : FieldOffset<Foo, u32, PinnedFlag> = Foo::FIELD_OFFSETS.field_2;
|
||||||
let pin_box = Box::pin(Foo{field_1: 1, field_2: 2});
|
let pin_box = Box::pin(Foo{field_1: 1, field_2: 2});
|
||||||
assert_eq!(*FIELD_2.apply_pin(pin_box.as_ref()), 2);
|
assert_eq!(*FIELD_2.apply_pin(pin_box.as_ref()), 2);
|
||||||
```
|
```
|
||||||
|
@ -208,7 +208,7 @@ pub fn const_field_offset(input: TokenStream) -> TokenStream {
|
||||||
|
|
||||||
impl #struct_name {
|
impl #struct_name {
|
||||||
/// Return a struct containing the offset of for the fields of this struct
|
/// Return a struct containing the offset of for the fields of this struct
|
||||||
pub const fn field_offsets() -> #field_struct_name {
|
pub const FIELD_OFFSETS : #field_struct_name = {
|
||||||
#ensure_pin_safe;
|
#ensure_pin_safe;
|
||||||
let mut len = 0usize;
|
let mut len = 0usize;
|
||||||
#field_struct_name {
|
#field_struct_name {
|
||||||
|
@ -221,7 +221,7 @@ pub fn const_field_offset(input: TokenStream) -> TokenStream {
|
||||||
unsafe { #crate_::FieldOffset::<#struct_name, #types, _>::#new_from_offset(len_rounded_up) }
|
unsafe { #crate_::FieldOffset::<#struct_name, #types, _>::#new_from_offset(len_rounded_up) }
|
||||||
}, )*
|
}, )*
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
|
@ -239,11 +239,11 @@ pub fn const_field_offset(input: TokenStream) -> TokenStream {
|
||||||
type Field = #types;
|
type Field = #types;
|
||||||
type PinFlag = #pin_flag;
|
type PinFlag = #pin_flag;
|
||||||
const OFFSET : #crate_::FieldOffset<#struct_name, #types, Self::PinFlag>
|
const OFFSET : #crate_::FieldOffset<#struct_name, #types, Self::PinFlag>
|
||||||
= #struct_name::field_offsets().#fields;
|
= #struct_name::FIELD_OFFSETS.#fields;
|
||||||
}
|
}
|
||||||
impl ::core::convert::Into<#crate_::FieldOffset<#struct_name, #types, #pin_flag>> for #module_name::#fields {
|
impl ::core::convert::Into<#crate_::FieldOffset<#struct_name, #types, #pin_flag>> for #module_name::#fields {
|
||||||
fn into(self) -> #crate_::FieldOffset<#struct_name, #types, #pin_flag> {
|
fn into(self) -> #crate_::FieldOffset<#struct_name, #types, #pin_flag> {
|
||||||
#struct_name::field_offsets().#fields
|
#struct_name::FIELD_OFFSETS.#fields
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<Other> ::core::ops::Add<Other> for #module_name::#fields
|
impl<Other> ::core::ops::Add<Other> for #module_name::#fields
|
||||||
|
|
|
@ -359,7 +359,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_simple() {
|
fn test_simple() {
|
||||||
// Get a pointer to `b` within `Foo`
|
// Get a pointer to `b` within `Foo`
|
||||||
let foo_b = Foo::field_offsets().b;
|
let foo_b = Foo::FIELD_OFFSETS.b;
|
||||||
|
|
||||||
// Construct an example `Foo`
|
// Construct an example `Foo`
|
||||||
let mut x = Foo { a: 1, b: 2.0, c: false };
|
let mut x = Foo { a: 1, b: 2.0, c: false };
|
||||||
|
@ -384,7 +384,7 @@ mod tests {
|
||||||
let mut x = Bar { x: 0, y: Foo { a: 1, b: 2.0, c: false } };
|
let mut x = Bar { x: 0, y: Foo { a: 1, b: 2.0, c: false } };
|
||||||
|
|
||||||
// Combine the pointer-to-members
|
// Combine the pointer-to-members
|
||||||
let bar_y_b = Bar::field_offsets().y + Foo::field_offsets().b;
|
let bar_y_b = Bar::FIELD_OFFSETS.y + Foo::FIELD_OFFSETS.b;
|
||||||
|
|
||||||
// Apply the pointer to get at `b` and mutate it
|
// Apply the pointer to get at `b` and mutate it
|
||||||
{
|
{
|
||||||
|
@ -398,17 +398,17 @@ mod tests {
|
||||||
fn test_pin() {
|
fn test_pin() {
|
||||||
use ::alloc::boxed::Box;
|
use ::alloc::boxed::Box;
|
||||||
// Get a pointer to `b` within `Foo`
|
// Get a pointer to `b` within `Foo`
|
||||||
let foo_b = Foo::field_offsets().b;
|
let foo_b = Foo::FIELD_OFFSETS.b;
|
||||||
let foo_b_pin = unsafe { foo_b.as_pinned_projection() };
|
let foo_b_pin = unsafe { foo_b.as_pinned_projection() };
|
||||||
let foo = Box::pin(Foo { a: 21, b: 22.0, c: true });
|
let foo = Box::pin(Foo { a: 21, b: 22.0, c: true });
|
||||||
let pb: Pin<&f64> = foo_b_pin.apply_pin(foo.as_ref());
|
let pb: Pin<&f64> = foo_b_pin.apply_pin(foo.as_ref());
|
||||||
assert!(*pb == 22.0);
|
assert!(*pb == 22.0);
|
||||||
|
|
||||||
let mut x = Box::pin(Bar { x: 0, y: Foo { a: 1, b: 52.0, c: false } });
|
let mut x = Box::pin(Bar { x: 0, y: Foo { a: 1, b: 52.0, c: false } });
|
||||||
let bar_y_b = Bar::field_offsets().y + foo_b_pin;
|
let bar_y_b = Bar::FIELD_OFFSETS.y + foo_b_pin;
|
||||||
assert!(*bar_y_b.apply(&*x) == 52.0);
|
assert!(*bar_y_b.apply(&*x) == 52.0);
|
||||||
|
|
||||||
let bar_y_pin = unsafe { Bar::field_offsets().y.as_pinned_projection() };
|
let bar_y_pin = unsafe { Bar::FIELD_OFFSETS.y.as_pinned_projection() };
|
||||||
*(bar_y_pin + foo_b_pin).apply_pin_mut(x.as_mut()) = 12.;
|
*(bar_y_pin + foo_b_pin).apply_pin_mut(x.as_mut()) = 12.;
|
||||||
assert!(x.y.b == 12.0);
|
assert!(x.y.b == 12.0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,18 +24,18 @@ struct MyStruct3 {
|
||||||
ms2: MyStruct2,
|
ms2: MyStruct2,
|
||||||
}
|
}
|
||||||
|
|
||||||
const XX_CONST: usize = MyStruct2::field_offsets().xx.get_byte_offset();
|
const XX_CONST: usize = MyStruct2::FIELD_OFFSETS.xx.get_byte_offset();
|
||||||
static D_STATIC: usize = MyStruct::field_offsets().d.get_byte_offset();
|
static D_STATIC: usize = MyStruct::FIELD_OFFSETS.d.get_byte_offset();
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test() {
|
fn test() {
|
||||||
assert_eq!(offset_of!(MyStruct, a), MyStruct::field_offsets().a.get_byte_offset());
|
assert_eq!(offset_of!(MyStruct, a), MyStruct::FIELD_OFFSETS.a.get_byte_offset());
|
||||||
assert_eq!(offset_of!(MyStruct, b), MyStruct::field_offsets().b.get_byte_offset());
|
assert_eq!(offset_of!(MyStruct, b), MyStruct::FIELD_OFFSETS.b.get_byte_offset());
|
||||||
assert_eq!(offset_of!(MyStruct, c), MyStruct::field_offsets().c.get_byte_offset());
|
assert_eq!(offset_of!(MyStruct, c), MyStruct::FIELD_OFFSETS.c.get_byte_offset());
|
||||||
assert_eq!(offset_of!(MyStruct, d), MyStruct::field_offsets().d.get_byte_offset());
|
assert_eq!(offset_of!(MyStruct, d), MyStruct::FIELD_OFFSETS.d.get_byte_offset());
|
||||||
assert_eq!(offset_of!(MyStruct2, xx), MyStruct2::field_offsets().xx.get_byte_offset());
|
assert_eq!(offset_of!(MyStruct2, xx), MyStruct2::FIELD_OFFSETS.xx.get_byte_offset());
|
||||||
assert_eq!(offset_of!(MyStruct2, v), MyStruct2::field_offsets().v.get_byte_offset());
|
assert_eq!(offset_of!(MyStruct2, v), MyStruct2::FIELD_OFFSETS.v.get_byte_offset());
|
||||||
assert_eq!(offset_of!(MyStruct2, k), MyStruct2::field_offsets().k.get_byte_offset());
|
assert_eq!(offset_of!(MyStruct2, k), MyStruct2::FIELD_OFFSETS.k.get_byte_offset());
|
||||||
|
|
||||||
assert_eq!(XX_CONST, offset_of!(MyStruct2, xx));
|
assert_eq!(XX_CONST, offset_of!(MyStruct2, xx));
|
||||||
assert_eq!(D_STATIC, offset_of!(MyStruct, d));
|
assert_eq!(D_STATIC, offset_of!(MyStruct, d));
|
||||||
|
@ -80,18 +80,18 @@ struct MyStruct2Pin {
|
||||||
v: u32,
|
v: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
const XX_CONST_PIN: usize = MyStruct2Pin::field_offsets().xx.get_byte_offset();
|
const XX_CONST_PIN: usize = MyStruct2Pin::FIELD_OFFSETS.xx.get_byte_offset();
|
||||||
static D_STATIC_PIN: usize = MyStructPin::field_offsets().d.get_byte_offset();
|
static D_STATIC_PIN: usize = MyStructPin::FIELD_OFFSETS.d.get_byte_offset();
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pin() {
|
fn test_pin() {
|
||||||
assert_eq!(offset_of!(MyStructPin, a), MyStructPin::field_offsets().a.get_byte_offset());
|
assert_eq!(offset_of!(MyStructPin, a), MyStructPin::FIELD_OFFSETS.a.get_byte_offset());
|
||||||
assert_eq!(offset_of!(MyStructPin, b), MyStructPin::field_offsets().b.get_byte_offset());
|
assert_eq!(offset_of!(MyStructPin, b), MyStructPin::FIELD_OFFSETS.b.get_byte_offset());
|
||||||
assert_eq!(offset_of!(MyStructPin, c), MyStructPin::field_offsets().c.get_byte_offset());
|
assert_eq!(offset_of!(MyStructPin, c), MyStructPin::FIELD_OFFSETS.c.get_byte_offset());
|
||||||
assert_eq!(offset_of!(MyStructPin, d), MyStructPin::field_offsets().d.get_byte_offset());
|
assert_eq!(offset_of!(MyStructPin, d), MyStructPin::FIELD_OFFSETS.d.get_byte_offset());
|
||||||
assert_eq!(offset_of!(MyStruct2Pin, xx), MyStruct2Pin::field_offsets().xx.get_byte_offset());
|
assert_eq!(offset_of!(MyStruct2Pin, xx), MyStruct2Pin::FIELD_OFFSETS.xx.get_byte_offset());
|
||||||
assert_eq!(offset_of!(MyStruct2Pin, v), MyStruct2Pin::field_offsets().v.get_byte_offset());
|
assert_eq!(offset_of!(MyStruct2Pin, v), MyStruct2Pin::FIELD_OFFSETS.v.get_byte_offset());
|
||||||
assert_eq!(offset_of!(MyStruct2Pin, k), MyStruct2Pin::field_offsets().k.get_byte_offset());
|
assert_eq!(offset_of!(MyStruct2Pin, k), MyStruct2Pin::FIELD_OFFSETS.k.get_byte_offset());
|
||||||
|
|
||||||
assert_eq!(XX_CONST_PIN, offset_of!(MyStruct2Pin, xx));
|
assert_eq!(XX_CONST_PIN, offset_of!(MyStruct2Pin, xx));
|
||||||
assert_eq!(D_STATIC_PIN, offset_of!(MyStructPin, d));
|
assert_eq!(D_STATIC_PIN, offset_of!(MyStructPin, d));
|
||||||
|
|
|
@ -43,7 +43,7 @@ impl Hello for SomeStruct {
|
||||||
impl HelloConsts for SomeStruct {
|
impl HelloConsts for SomeStruct {
|
||||||
const CONSTANT: usize = 88;
|
const CONSTANT: usize = 88;
|
||||||
const SOME_OFFSET: const_field_offset::FieldOffset<SomeStruct, u32> =
|
const SOME_OFFSET: const_field_offset::FieldOffset<SomeStruct, u32> =
|
||||||
SomeStruct::field_offsets().x;
|
SomeStruct::FIELD_OFFSETS.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
HelloVTable_static!(static SOME_STRUCT_TYPE for SomeStruct);
|
HelloVTable_static!(static SOME_STRUCT_TYPE for SomeStruct);
|
||||||
|
@ -81,7 +81,7 @@ impl Hello for AnotherStruct {
|
||||||
impl HelloConsts for AnotherStruct {
|
impl HelloConsts for AnotherStruct {
|
||||||
const CONSTANT: usize = 99;
|
const CONSTANT: usize = 99;
|
||||||
const SOME_OFFSET: const_field_offset::FieldOffset<AnotherStruct, u32> =
|
const SOME_OFFSET: const_field_offset::FieldOffset<AnotherStruct, u32> =
|
||||||
AnotherStruct::field_offsets().foo;
|
AnotherStruct::FIELD_OFFSETS.foo;
|
||||||
}
|
}
|
||||||
|
|
||||||
HelloVTable_static!(static ANOTHERSTRUCT_VTABLE for AnotherStruct);
|
HelloVTable_static!(static ANOTHERSTRUCT_VTABLE for AnotherStruct);
|
||||||
|
@ -117,7 +117,7 @@ fn test() {
|
||||||
}
|
}
|
||||||
|
|
||||||
let vo =
|
let vo =
|
||||||
VOffset::<SomeStructContainer, HelloVTable>::new(SomeStructContainer::field_offsets().s);
|
VOffset::<SomeStructContainer, HelloVTable>::new(SomeStructContainer::FIELD_OFFSETS.s);
|
||||||
let mut ssc = SomeStructContainer { e: 4, s: SomeStruct { e: 5, x: 32 } };
|
let mut ssc = SomeStructContainer { e: 4, s: SomeStruct { e: 5, x: 32 } };
|
||||||
assert_eq!(vo.apply(&ssc).foo(4), 32 + 4);
|
assert_eq!(vo.apply(&ssc).foo(4), 32 + 4);
|
||||||
assert_eq!(vo.apply_mut(&mut ssc).foo_mut(4), 32 + 4);
|
assert_eq!(vo.apply_mut(&mut ssc).foo_mut(4), 32 + 4);
|
||||||
|
|
|
@ -73,7 +73,7 @@ fn generate_component(
|
||||||
quote!(
|
quote!(
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn #emitter_ident(self: ::core::pin::Pin<&Self>) {
|
pub fn #emitter_ident(self: ::core::pin::Pin<&Self>) {
|
||||||
Self::field_offsets().#prop_ident.apply_pin(self).emit(())
|
Self::FIELD_OFFSETS.#prop_ident.apply_pin(self).emit(())
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
|
@ -83,7 +83,7 @@ fn generate_component(
|
||||||
quote!(
|
quote!(
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn #on_ident(self: ::core::pin::Pin<&Self>, f: impl Fn() + 'static) {
|
pub fn #on_ident(self: ::core::pin::Pin<&Self>, f: impl Fn() + 'static) {
|
||||||
Self::field_offsets().#prop_ident.apply_pin(self).set_handler(move |()|f())
|
Self::FIELD_OFFSETS.#prop_ident.apply_pin(self).set_handler(move |()|f())
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
|
@ -107,7 +107,7 @@ fn generate_component(
|
||||||
quote!(
|
quote!(
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn #getter_ident(self: ::core::pin::Pin<&Self>) -> #rust_property_type {
|
pub fn #getter_ident(self: ::core::pin::Pin<&Self>) -> #rust_property_type {
|
||||||
Self::field_offsets().#prop_ident.apply_pin(self).get()
|
Self::FIELD_OFFSETS.#prop_ident.apply_pin(self).get()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
|
@ -123,7 +123,7 @@ fn generate_component(
|
||||||
quote!(
|
quote!(
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn #setter_ident(&self, value: #rust_property_type) {
|
pub fn #setter_ident(&self, value: #rust_property_type) {
|
||||||
Self::field_offsets().#prop_ident.apply(self).#set_value
|
Self::FIELD_OFFSETS.#prop_ident.apply(self).#set_value
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.into(),
|
.into(),
|
||||||
|
@ -155,7 +155,7 @@ fn generate_component(
|
||||||
|
|
||||||
item_tree_array.push(quote!(
|
item_tree_array.push(quote!(
|
||||||
sixtyfps::re_exports::ItemTreeNode::Item{
|
sixtyfps::re_exports::ItemTreeNode::Item{
|
||||||
item: VOffset::new(#component_id::field_offsets().#field_name + sixtyfps::re_exports::Flickable::field_offsets().viewport),
|
item: VOffset::new(#component_id::FIELD_OFFSETS.#field_name + sixtyfps::re_exports::Flickable::FIELD_OFFSETS.viewport),
|
||||||
chilren_count: #children_count,
|
chilren_count: #children_count,
|
||||||
children_index: #children_index,
|
children_index: #children_index,
|
||||||
}
|
}
|
||||||
|
@ -219,7 +219,7 @@ fn generate_component(
|
||||||
repeated_visit_branch.push(quote!(
|
repeated_visit_branch.push(quote!(
|
||||||
#repeater_index => {
|
#repeater_index => {
|
||||||
if self_pinned.#model_name.is_dirty() {
|
if self_pinned.#model_name.is_dirty() {
|
||||||
#component_id::field_offsets().#model_name.apply_pin(self_pinned).evaluate(|| {
|
#component_id::FIELD_OFFSETS.#model_name.apply_pin(self_pinned).evaluate(|| {
|
||||||
let _self = self_pinned.clone();
|
let _self = self_pinned.clone();
|
||||||
self_pinned.#repeater_id.update_model(#model, || {
|
self_pinned.#repeater_id.update_model(#model, || {
|
||||||
#rep_component_id::new(self_pinned.self_weak.get().unwrap().clone())
|
#rep_component_id::new(self_pinned.self_weak.get().unwrap().clone())
|
||||||
|
@ -247,7 +247,7 @@ fn generate_component(
|
||||||
|
|
||||||
item_tree_array.push(quote!(
|
item_tree_array.push(quote!(
|
||||||
sixtyfps::re_exports::ItemTreeNode::Item{
|
sixtyfps::re_exports::ItemTreeNode::Item{
|
||||||
item: VOffset::new(#component_id::field_offsets().#field_name),
|
item: VOffset::new(#component_id::FIELD_OFFSETS.#field_name),
|
||||||
chilren_count: #children_count,
|
chilren_count: #children_count,
|
||||||
children_index: #children_index,
|
children_index: #children_index,
|
||||||
}
|
}
|
||||||
|
@ -536,12 +536,12 @@ fn access_member(
|
||||||
let component_id = component_id(&enclosing_component);
|
let component_id = component_id(&enclosing_component);
|
||||||
let name_ident = quote::format_ident!("{}", name);
|
let name_ident = quote::format_ident!("{}", name);
|
||||||
if e.property_declarations.contains_key(name) {
|
if e.property_declarations.contains_key(name) {
|
||||||
quote!(#component_id::field_offsets().#name_ident.apply_pin(#component_rust))
|
quote!(#component_id::FIELD_OFFSETS.#name_ident.apply_pin(#component_rust))
|
||||||
} else {
|
} else {
|
||||||
let elem_ident = quote::format_ident!("{}", e.id);
|
let elem_ident = quote::format_ident!("{}", e.id);
|
||||||
let elem_ty = quote::format_ident!("{}", e.base_type.as_native().class_name);
|
let elem_ty = quote::format_ident!("{}", e.base_type.as_native().class_name);
|
||||||
|
|
||||||
quote!((#component_id::field_offsets().#elem_ident + #elem_ty::field_offsets().#name_ident)
|
quote!((#component_id::FIELD_OFFSETS.#elem_ident + #elem_ty::FIELD_OFFSETS.#name_ident)
|
||||||
.apply_pin(#component_rust)
|
.apply_pin(#component_rust)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -571,7 +571,7 @@ fn dpi_expression(component: &Rc<Component>) -> TokenStream {
|
||||||
component_rust = quote!(#component_rust.parent.upgrade().unwrap().as_ref());
|
component_rust = quote!(#component_rust.parent.upgrade().unwrap().as_ref());
|
||||||
}
|
}
|
||||||
let component_id = component_id(&root_component);
|
let component_id = component_id(&root_component);
|
||||||
quote!(#component_id::field_offsets().dpi.apply_pin(#component_rust).get())
|
quote!(#component_id::FIELD_OFFSETS.dpi.apply_pin(#component_rust).get())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_expression(e: &Expression, component: &Rc<Component>) -> TokenStream {
|
fn compile_expression(e: &Expression, component: &Rc<Component>) -> TokenStream {
|
||||||
|
@ -612,7 +612,7 @@ fn compile_expression(e: &Expression, component: &Rc<Component>) -> TokenStream
|
||||||
Expression::RepeaterIndexReference { element } => {
|
Expression::RepeaterIndexReference { element } => {
|
||||||
if element.upgrade().unwrap().borrow().base_type == Type::Component(component.clone()) {
|
if element.upgrade().unwrap().borrow().base_type == Type::Component(component.clone()) {
|
||||||
let component_id = component_id(&component);
|
let component_id = component_id(&component);
|
||||||
quote!({ #component_id::field_offsets().index.apply_pin(_self).get() })
|
quote!({ #component_id::FIELD_OFFSETS.index.apply_pin(_self).get() })
|
||||||
} else {
|
} else {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
@ -620,7 +620,7 @@ fn compile_expression(e: &Expression, component: &Rc<Component>) -> TokenStream
|
||||||
Expression::RepeaterModelReference { element } => {
|
Expression::RepeaterModelReference { element } => {
|
||||||
if element.upgrade().unwrap().borrow().base_type == Type::Component(component.clone()) {
|
if element.upgrade().unwrap().borrow().base_type == Type::Component(component.clone()) {
|
||||||
let component_id = component_id(&component);
|
let component_id = component_id(&component);
|
||||||
quote!({ #component_id::field_offsets().model_data.apply_pin(_self).get() })
|
quote!({ #component_id::FIELD_OFFSETS.model_data.apply_pin(_self).get() })
|
||||||
} else {
|
} else {
|
||||||
todo!();
|
todo!();
|
||||||
}
|
}
|
||||||
|
@ -858,7 +858,7 @@ impl LayoutItemCodeGen for ElementRc {
|
||||||
_layout_tree: &'b mut Vec<LayoutTreeItem<'a>>,
|
_layout_tree: &'b mut Vec<LayoutTreeItem<'a>>,
|
||||||
) -> TokenStream {
|
) -> TokenStream {
|
||||||
let e = quote::format_ident!("{}", self.borrow().id);
|
let e = quote::format_ident!("{}", self.borrow().id);
|
||||||
quote!(Self::field_offsets().#e.apply_pin(self).layouting_info())
|
quote!(Self::FIELD_OFFSETS.#e.apply_pin(self).layouting_info())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,10 +29,10 @@ impl FlickableData {
|
||||||
inner.pressed_pos = event.pos;
|
inner.pressed_pos = event.pos;
|
||||||
inner.pressed_time = Some(crate::animations::current_tick());
|
inner.pressed_time = Some(crate::animations::current_tick());
|
||||||
inner.pressed_viewport_pos = Point::new(
|
inner.pressed_viewport_pos = Point::new(
|
||||||
(Flickable::field_offsets().viewport + Rectangle::field_offsets().x)
|
(Flickable::FIELD_OFFSETS.viewport + Rectangle::FIELD_OFFSETS.x)
|
||||||
.apply_pin(flick)
|
.apply_pin(flick)
|
||||||
.get(),
|
.get(),
|
||||||
(Flickable::field_offsets().viewport + Rectangle::field_offsets().y)
|
(Flickable::FIELD_OFFSETS.viewport + Rectangle::FIELD_OFFSETS.y)
|
||||||
.apply_pin(flick)
|
.apply_pin(flick)
|
||||||
.get(),
|
.get(),
|
||||||
)
|
)
|
||||||
|
@ -53,10 +53,10 @@ impl FlickableData {
|
||||||
easing: EasingCurve::CubicBezier([0.0, 0.0, 0.58, 1.0]),
|
easing: EasingCurve::CubicBezier([0.0, 0.0, 0.58, 1.0]),
|
||||||
..PropertyAnimation::default()
|
..PropertyAnimation::default()
|
||||||
};
|
};
|
||||||
(Flickable::field_offsets().viewport + Rectangle::field_offsets().x)
|
(Flickable::FIELD_OFFSETS.viewport + Rectangle::FIELD_OFFSETS.x)
|
||||||
.apply_pin(flick)
|
.apply_pin(flick)
|
||||||
.set_animated_value(final_pos.x, &anim);
|
.set_animated_value(final_pos.x, &anim);
|
||||||
(Flickable::field_offsets().viewport + Rectangle::field_offsets().y)
|
(Flickable::FIELD_OFFSETS.viewport + Rectangle::FIELD_OFFSETS.y)
|
||||||
.apply_pin(flick)
|
.apply_pin(flick)
|
||||||
.set_animated_value(final_pos.y, &anim);
|
.set_animated_value(final_pos.y, &anim);
|
||||||
}
|
}
|
||||||
|
@ -68,10 +68,10 @@ impl FlickableData {
|
||||||
flick,
|
flick,
|
||||||
inner.pressed_viewport_pos + (event.pos - inner.pressed_pos),
|
inner.pressed_viewport_pos + (event.pos - inner.pressed_pos),
|
||||||
);
|
);
|
||||||
(Flickable::field_offsets().viewport + Rectangle::field_offsets().x)
|
(Flickable::FIELD_OFFSETS.viewport + Rectangle::FIELD_OFFSETS.x)
|
||||||
.apply_pin(flick)
|
.apply_pin(flick)
|
||||||
.set(new_pos.x);
|
.set(new_pos.x);
|
||||||
(Flickable::field_offsets().viewport + Rectangle::field_offsets().y)
|
(Flickable::FIELD_OFFSETS.viewport + Rectangle::FIELD_OFFSETS.y)
|
||||||
.apply_pin(flick)
|
.apply_pin(flick)
|
||||||
.set(new_pos.y);
|
.set(new_pos.y);
|
||||||
}
|
}
|
||||||
|
@ -82,12 +82,12 @@ impl FlickableData {
|
||||||
|
|
||||||
/// Make sure that the point is within the bounds
|
/// Make sure that the point is within the bounds
|
||||||
fn ensure_in_bound(flick: Pin<&Flickable>, p: Point) -> Point {
|
fn ensure_in_bound(flick: Pin<&Flickable>, p: Point) -> Point {
|
||||||
let w = (Flickable::field_offsets().width).apply_pin(flick).get();
|
let w = (Flickable::FIELD_OFFSETS.width).apply_pin(flick).get();
|
||||||
let h = (Flickable::field_offsets().height).apply_pin(flick).get();
|
let h = (Flickable::FIELD_OFFSETS.height).apply_pin(flick).get();
|
||||||
/*let vw = (Flickable::field_offsets().viewport + Rectangle::field_offsets().width)
|
/*let vw = (Flickable::FIELD_OFFSETS.viewport + Rectangle::FIELD_OFFSETS.width)
|
||||||
.apply_pin(flick)
|
.apply_pin(flick)
|
||||||
.get();
|
.get();
|
||||||
let vh = (Flickable::field_offsets().viewport + Rectangle::field_offsets().height)
|
let vh = (Flickable::FIELD_OFFSETS.viewport + Rectangle::FIELD_OFFSETS.height)
|
||||||
.apply_pin(flick)
|
.apply_pin(flick)
|
||||||
.get();*/
|
.get();*/
|
||||||
let (vw, vh) = (1000., 1000.); // FIXME: should be the actual viewport
|
let (vw, vh) = (1000., 1000.); // FIXME: should be the actual viewport
|
||||||
|
|
|
@ -44,22 +44,22 @@ pub struct Rectangle {
|
||||||
impl Item for Rectangle {
|
impl Item for Rectangle {
|
||||||
fn geometry(self: Pin<&Self>) -> Rect {
|
fn geometry(self: Pin<&Self>) -> Rect {
|
||||||
euclid::rect(
|
euclid::rect(
|
||||||
Self::field_offsets().x.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
Self::field_offsets().y.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
Self::field_offsets().width.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.width.apply_pin(self).get(),
|
||||||
Self::field_offsets().height.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.height.apply_pin(self).get(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
||||||
let width = Self::field_offsets().width.apply_pin(self).get();
|
let width = Self::FIELD_OFFSETS.width.apply_pin(self).get();
|
||||||
let height = Self::field_offsets().height.apply_pin(self).get();
|
let height = Self::FIELD_OFFSETS.height.apply_pin(self).get();
|
||||||
if width > 0. && height > 0. {
|
if width > 0. && height > 0. {
|
||||||
HighLevelRenderingPrimitive::Rectangle {
|
HighLevelRenderingPrimitive::Rectangle {
|
||||||
x: Self::field_offsets().x.apply_pin(self).get(),
|
x: Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
y: Self::field_offsets().y.apply_pin(self).get(),
|
y: Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
color: Self::field_offsets().color.apply_pin(self).get(),
|
color: Self::FIELD_OFFSETS.color.apply_pin(self).get(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
HighLevelRenderingPrimitive::NoContents
|
HighLevelRenderingPrimitive::NoContents
|
||||||
|
@ -77,7 +77,7 @@ impl ItemConsts for Rectangle {
|
||||||
const cached_rendering_data_offset: const_field_offset::FieldOffset<
|
const cached_rendering_data_offset: const_field_offset::FieldOffset<
|
||||||
Rectangle,
|
Rectangle,
|
||||||
CachedRenderingData,
|
CachedRenderingData,
|
||||||
> = Rectangle::field_offsets().cached_rendering_data.as_unpinned_projection();
|
> = Rectangle::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use crate::abi::datastructures::RectangleVTable;
|
pub use crate::abi::datastructures::RectangleVTable;
|
||||||
|
@ -101,25 +101,25 @@ pub struct BorderRectangle {
|
||||||
impl Item for BorderRectangle {
|
impl Item for BorderRectangle {
|
||||||
fn geometry(self: Pin<&Self>) -> Rect {
|
fn geometry(self: Pin<&Self>) -> Rect {
|
||||||
euclid::rect(
|
euclid::rect(
|
||||||
Self::field_offsets().x.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
Self::field_offsets().y.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
Self::field_offsets().width.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.width.apply_pin(self).get(),
|
||||||
Self::field_offsets().height.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.height.apply_pin(self).get(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
||||||
let width = Self::field_offsets().width.apply_pin(self).get();
|
let width = Self::FIELD_OFFSETS.width.apply_pin(self).get();
|
||||||
let height = Self::field_offsets().height.apply_pin(self).get();
|
let height = Self::FIELD_OFFSETS.height.apply_pin(self).get();
|
||||||
if width > 0. && height > 0. {
|
if width > 0. && height > 0. {
|
||||||
HighLevelRenderingPrimitive::BorderRectangle {
|
HighLevelRenderingPrimitive::BorderRectangle {
|
||||||
x: Self::field_offsets().x.apply_pin(self).get(),
|
x: Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
y: Self::field_offsets().y.apply_pin(self).get(),
|
y: Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
width,
|
width,
|
||||||
height,
|
height,
|
||||||
color: Self::field_offsets().color.apply_pin(self).get(),
|
color: Self::FIELD_OFFSETS.color.apply_pin(self).get(),
|
||||||
border_width: Self::field_offsets().border_width.apply_pin(self).get(),
|
border_width: Self::FIELD_OFFSETS.border_width.apply_pin(self).get(),
|
||||||
border_radius: Self::field_offsets().border_radius.apply_pin(self).get(),
|
border_radius: Self::FIELD_OFFSETS.border_radius.apply_pin(self).get(),
|
||||||
border_color: Self::field_offsets().border_color.apply_pin(self).get(),
|
border_color: Self::FIELD_OFFSETS.border_color.apply_pin(self).get(),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
HighLevelRenderingPrimitive::NoContents
|
HighLevelRenderingPrimitive::NoContents
|
||||||
|
@ -137,7 +137,7 @@ impl ItemConsts for BorderRectangle {
|
||||||
const cached_rendering_data_offset: const_field_offset::FieldOffset<
|
const cached_rendering_data_offset: const_field_offset::FieldOffset<
|
||||||
BorderRectangle,
|
BorderRectangle,
|
||||||
CachedRenderingData,
|
CachedRenderingData,
|
||||||
> = BorderRectangle::field_offsets().cached_rendering_data.as_unpinned_projection();
|
> = BorderRectangle::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use crate::abi::datastructures::BorderRectangleVTable;
|
pub use crate::abi::datastructures::BorderRectangleVTable;
|
||||||
|
@ -158,17 +158,17 @@ pub struct Image {
|
||||||
impl Item for Image {
|
impl Item for Image {
|
||||||
fn geometry(self: Pin<&Self>) -> Rect {
|
fn geometry(self: Pin<&Self>) -> Rect {
|
||||||
euclid::rect(
|
euclid::rect(
|
||||||
Self::field_offsets().x.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
Self::field_offsets().y.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
Self::field_offsets().width.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.width.apply_pin(self).get(),
|
||||||
Self::field_offsets().height.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.height.apply_pin(self).get(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
||||||
HighLevelRenderingPrimitive::Image {
|
HighLevelRenderingPrimitive::Image {
|
||||||
x: Self::field_offsets().x.apply_pin(self).get(),
|
x: Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
y: Self::field_offsets().y.apply_pin(self).get(),
|
y: Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
source: Self::field_offsets().source.apply_pin(self).get(),
|
source: Self::FIELD_OFFSETS.source.apply_pin(self).get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,7 +184,7 @@ impl ItemConsts for Image {
|
||||||
const cached_rendering_data_offset: const_field_offset::FieldOffset<
|
const cached_rendering_data_offset: const_field_offset::FieldOffset<
|
||||||
Image,
|
Image,
|
||||||
CachedRenderingData,
|
CachedRenderingData,
|
||||||
> = Image::field_offsets().cached_rendering_data.as_unpinned_projection();
|
> = Image::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use crate::abi::datastructures::ImageVTable;
|
pub use crate::abi::datastructures::ImageVTable;
|
||||||
|
@ -207,27 +207,27 @@ impl Item for Text {
|
||||||
// FIXME: width / height. or maybe it doesn't matter? (
|
// FIXME: width / height. or maybe it doesn't matter? (
|
||||||
fn geometry(self: Pin<&Self>) -> Rect {
|
fn geometry(self: Pin<&Self>) -> Rect {
|
||||||
euclid::rect(
|
euclid::rect(
|
||||||
Self::field_offsets().x.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
Self::field_offsets().y.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
0.,
|
0.,
|
||||||
0.,
|
0.,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
||||||
HighLevelRenderingPrimitive::Text {
|
HighLevelRenderingPrimitive::Text {
|
||||||
x: Self::field_offsets().x.apply_pin(self).get(),
|
x: Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
y: Self::field_offsets().y.apply_pin(self).get(),
|
y: Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
text: Self::field_offsets().text.apply_pin(self).get(),
|
text: Self::FIELD_OFFSETS.text.apply_pin(self).get(),
|
||||||
font_family: Self::field_offsets().font_family.apply_pin(self).get(),
|
font_family: Self::FIELD_OFFSETS.font_family.apply_pin(self).get(),
|
||||||
font_pixel_size: Self::field_offsets().font_pixel_size.apply_pin(self).get(),
|
font_pixel_size: Self::FIELD_OFFSETS.font_pixel_size.apply_pin(self).get(),
|
||||||
color: Self::field_offsets().color.apply_pin(self).get(),
|
color: Self::FIELD_OFFSETS.color.apply_pin(self).get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn layouting_info(self: Pin<&Self>) -> LayoutInfo {
|
fn layouting_info(self: Pin<&Self>) -> LayoutInfo {
|
||||||
let font_family = Self::field_offsets().font_family.apply_pin(self).get();
|
let font_family = Self::FIELD_OFFSETS.font_family.apply_pin(self).get();
|
||||||
let font_pixel_size = Self::field_offsets().font_pixel_size.apply_pin(self).get();
|
let font_pixel_size = Self::FIELD_OFFSETS.font_pixel_size.apply_pin(self).get();
|
||||||
let text = Self::field_offsets().text.apply_pin(self).get();
|
let text = Self::FIELD_OFFSETS.text.apply_pin(self).get();
|
||||||
|
|
||||||
crate::font::FONT_CACHE.with(|fc| {
|
crate::font::FONT_CACHE.with(|fc| {
|
||||||
let font = fc.find_font(&font_family, font_pixel_size);
|
let font = fc.find_font(&font_family, font_pixel_size);
|
||||||
|
@ -247,7 +247,7 @@ impl Item for Text {
|
||||||
|
|
||||||
impl ItemConsts for Text {
|
impl ItemConsts for Text {
|
||||||
const cached_rendering_data_offset: const_field_offset::FieldOffset<Text, CachedRenderingData> =
|
const cached_rendering_data_offset: const_field_offset::FieldOffset<Text, CachedRenderingData> =
|
||||||
Text::field_offsets().cached_rendering_data.as_unpinned_projection();
|
Text::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use crate::abi::datastructures::TextVTable;
|
pub use crate::abi::datastructures::TextVTable;
|
||||||
|
@ -271,10 +271,10 @@ pub struct TouchArea {
|
||||||
impl Item for TouchArea {
|
impl Item for TouchArea {
|
||||||
fn geometry(self: Pin<&Self>) -> Rect {
|
fn geometry(self: Pin<&Self>) -> Rect {
|
||||||
euclid::rect(
|
euclid::rect(
|
||||||
Self::field_offsets().x.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
Self::field_offsets().y.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
Self::field_offsets().width.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.width.apply_pin(self).get(),
|
||||||
Self::field_offsets().height.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.height.apply_pin(self).get(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
||||||
|
@ -287,13 +287,13 @@ impl Item for TouchArea {
|
||||||
|
|
||||||
fn input_event(self: Pin<&Self>, event: MouseEvent) {
|
fn input_event(self: Pin<&Self>, event: MouseEvent) {
|
||||||
println!("Touch Area Event {:?}", event);
|
println!("Touch Area Event {:?}", event);
|
||||||
Self::field_offsets().pressed.apply_pin(self).set(match event.what {
|
Self::FIELD_OFFSETS.pressed.apply_pin(self).set(match event.what {
|
||||||
MouseEventType::MousePressed => true,
|
MouseEventType::MousePressed => true,
|
||||||
MouseEventType::MouseReleased => false,
|
MouseEventType::MouseReleased => false,
|
||||||
MouseEventType::MouseMoved => return,
|
MouseEventType::MouseMoved => return,
|
||||||
});
|
});
|
||||||
if matches!(event.what, MouseEventType::MouseReleased) {
|
if matches!(event.what, MouseEventType::MouseReleased) {
|
||||||
Self::field_offsets().clicked.apply_pin(self).emit(())
|
Self::FIELD_OFFSETS.clicked.apply_pin(self).emit(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,7 +302,7 @@ impl ItemConsts for TouchArea {
|
||||||
const cached_rendering_data_offset: const_field_offset::FieldOffset<
|
const cached_rendering_data_offset: const_field_offset::FieldOffset<
|
||||||
TouchArea,
|
TouchArea,
|
||||||
CachedRenderingData,
|
CachedRenderingData,
|
||||||
> = TouchArea::field_offsets().cached_rendering_data.as_unpinned_projection();
|
> = TouchArea::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||||
}
|
}
|
||||||
pub use crate::abi::datastructures::TouchAreaVTable;
|
pub use crate::abi::datastructures::TouchAreaVTable;
|
||||||
|
|
||||||
|
@ -325,22 +325,22 @@ pub struct Path {
|
||||||
impl Item for Path {
|
impl Item for Path {
|
||||||
fn geometry(self: Pin<&Self>) -> Rect {
|
fn geometry(self: Pin<&Self>) -> Rect {
|
||||||
euclid::rect(
|
euclid::rect(
|
||||||
Self::field_offsets().x.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
Self::field_offsets().y.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
0.,
|
0.,
|
||||||
0.,
|
0.,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
||||||
HighLevelRenderingPrimitive::Path {
|
HighLevelRenderingPrimitive::Path {
|
||||||
x: Self::field_offsets().x.apply_pin(self).get(),
|
x: Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
y: Self::field_offsets().y.apply_pin(self).get(),
|
y: Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
width: Self::field_offsets().width.apply_pin(self).get(),
|
width: Self::FIELD_OFFSETS.width.apply_pin(self).get(),
|
||||||
height: Self::field_offsets().height.apply_pin(self).get(),
|
height: Self::FIELD_OFFSETS.height.apply_pin(self).get(),
|
||||||
elements: Self::field_offsets().elements.apply_pin(self).get(),
|
elements: Self::FIELD_OFFSETS.elements.apply_pin(self).get(),
|
||||||
fill_color: Self::field_offsets().fill_color.apply_pin(self).get(),
|
fill_color: Self::FIELD_OFFSETS.fill_color.apply_pin(self).get(),
|
||||||
stroke_color: Self::field_offsets().stroke_color.apply_pin(self).get(),
|
stroke_color: Self::FIELD_OFFSETS.stroke_color.apply_pin(self).get(),
|
||||||
stroke_width: Self::field_offsets().stroke_width.apply_pin(self).get(),
|
stroke_width: Self::FIELD_OFFSETS.stroke_width.apply_pin(self).get(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ impl Item for Path {
|
||||||
|
|
||||||
impl ItemConsts for Path {
|
impl ItemConsts for Path {
|
||||||
const cached_rendering_data_offset: const_field_offset::FieldOffset<Path, CachedRenderingData> =
|
const cached_rendering_data_offset: const_field_offset::FieldOffset<Path, CachedRenderingData> =
|
||||||
Path::field_offsets().cached_rendering_data.as_unpinned_projection();
|
Path::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub use crate::abi::datastructures::PathVTable;
|
pub use crate::abi::datastructures::PathVTable;
|
||||||
|
@ -377,10 +377,10 @@ pub struct Flickable {
|
||||||
impl Item for Flickable {
|
impl Item for Flickable {
|
||||||
fn geometry(self: Pin<&Self>) -> Rect {
|
fn geometry(self: Pin<&Self>) -> Rect {
|
||||||
euclid::rect(
|
euclid::rect(
|
||||||
Self::field_offsets().x.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
Self::field_offsets().y.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
Self::field_offsets().width.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.width.apply_pin(self).get(),
|
||||||
Self::field_offsets().height.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.height.apply_pin(self).get(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
||||||
|
@ -398,7 +398,7 @@ impl Item for Flickable {
|
||||||
|
|
||||||
impl ItemConsts for Flickable {
|
impl ItemConsts for Flickable {
|
||||||
const cached_rendering_data_offset: const_field_offset::FieldOffset<Self, CachedRenderingData> =
|
const cached_rendering_data_offset: const_field_offset::FieldOffset<Self, CachedRenderingData> =
|
||||||
Self::field_offsets().cached_rendering_data.as_unpinned_projection();
|
Self::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||||
}
|
}
|
||||||
pub use crate::abi::datastructures::FlickableVTable;
|
pub use crate::abi::datastructures::FlickableVTable;
|
||||||
|
|
||||||
|
|
|
@ -65,20 +65,20 @@ pub fn builtin_item(input: TokenStream) -> TokenStream {
|
||||||
fn properties<Value: ValueType>() -> Vec<(&'static str, &'static dyn PropertyInfo<Self, Value>)> {
|
fn properties<Value: ValueType>() -> Vec<(&'static str, &'static dyn PropertyInfo<Self, Value>)> {
|
||||||
vec![#( {
|
vec![#( {
|
||||||
const O : MaybeAnimatedPropertyInfoWrapper<#item_name, #prop_field_types> =
|
const O : MaybeAnimatedPropertyInfoWrapper<#item_name, #prop_field_types> =
|
||||||
MaybeAnimatedPropertyInfoWrapper(#item_name::field_offsets().#prop_field_names);
|
MaybeAnimatedPropertyInfoWrapper(#item_name::FIELD_OFFSETS.#prop_field_names);
|
||||||
(stringify!(#prop_field_names), (&O).as_property_info())
|
(stringify!(#prop_field_names), (&O).as_property_info())
|
||||||
} ),*]
|
} ),*]
|
||||||
}
|
}
|
||||||
fn fields<Value: ValueType>() -> Vec<(&'static str, &'static dyn FieldInfo<Self, Value>)> {
|
fn fields<Value: ValueType>() -> Vec<(&'static str, &'static dyn FieldInfo<Self, Value>)> {
|
||||||
vec![#( {
|
vec![#( {
|
||||||
const O : FieldOffset<#item_name, #plain_field_types> =
|
const O : FieldOffset<#item_name, #plain_field_types> =
|
||||||
#item_name::field_offsets().#plain_field_names;
|
#item_name::FIELD_OFFSETS.#plain_field_names;
|
||||||
(stringify!(#plain_field_names), &O as &'static dyn FieldInfo<Self, Value> )
|
(stringify!(#plain_field_names), &O as &'static dyn FieldInfo<Self, Value> )
|
||||||
} ),*]
|
} ),*]
|
||||||
}
|
}
|
||||||
fn signals() -> Vec<(&'static str, FieldOffset<Self, crate::Signal<()>>)> {
|
fn signals() -> Vec<(&'static str, FieldOffset<Self, crate::Signal<()>>)> {
|
||||||
vec![#(
|
vec![#(
|
||||||
(stringify!(#signal_field_names),#item_name::field_offsets().#signal_field_names)
|
(stringify!(#signal_field_names),#item_name::FIELD_OFFSETS.#signal_field_names)
|
||||||
),*]
|
),*]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,7 +269,7 @@ fn generate_component(root_component: &Rc<object_tree::Component>) -> Rc<Compone
|
||||||
if is_flickable_rect {
|
if is_flickable_rect {
|
||||||
use vtable::HasStaticVTable;
|
use vtable::HasStaticVTable;
|
||||||
let offset = items_types[&item.id].offset
|
let offset = items_types[&item.id].offset
|
||||||
+ Flickable::field_offsets().viewport.get_byte_offset();
|
+ Flickable::FIELD_OFFSETS.viewport.get_byte_offset();
|
||||||
tree_array.push(ItemTreeNode::Item {
|
tree_array.push(ItemTreeNode::Item {
|
||||||
item: unsafe { vtable::VOffset::from_raw(Rectangle::static_vtable(), offset) },
|
item: unsafe { vtable::VOffset::from_raw(Rectangle::static_vtable(), offset) },
|
||||||
children_index: tree_array.len() as u32 + 1,
|
children_index: tree_array.len() as u32 + 1,
|
||||||
|
|
|
@ -61,21 +61,21 @@ pub struct QtStyleButton {
|
||||||
impl Item for QtStyleButton {
|
impl Item for QtStyleButton {
|
||||||
fn geometry(self: Pin<&Self>) -> Rect {
|
fn geometry(self: Pin<&Self>) -> Rect {
|
||||||
euclid::rect(
|
euclid::rect(
|
||||||
Self::field_offsets().x.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
Self::field_offsets().y.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
Self::field_offsets().width.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.width.apply_pin(self).get(),
|
||||||
Self::field_offsets().height.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.height.apply_pin(self).get(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
||||||
#[cfg(have_qt)]
|
#[cfg(have_qt)]
|
||||||
{
|
{
|
||||||
let down: bool = Self::field_offsets().pressed.apply_pin(self).get();
|
let down: bool = Self::FIELD_OFFSETS.pressed.apply_pin(self).get();
|
||||||
let text: qttypes::QString =
|
let text: qttypes::QString =
|
||||||
Self::field_offsets().text.apply_pin(self).get().as_str().into();
|
Self::FIELD_OFFSETS.text.apply_pin(self).get().as_str().into();
|
||||||
let size: qttypes::QSize = qttypes::QSize {
|
let size: qttypes::QSize = qttypes::QSize {
|
||||||
width: Self::field_offsets().width.apply_pin(self).get() as _,
|
width: Self::FIELD_OFFSETS.width.apply_pin(self).get() as _,
|
||||||
height: Self::field_offsets().height.apply_pin(self).get() as _,
|
height: Self::FIELD_OFFSETS.height.apply_pin(self).get() as _,
|
||||||
};
|
};
|
||||||
|
|
||||||
let img = cpp!(unsafe [
|
let img = cpp!(unsafe [
|
||||||
|
@ -96,8 +96,8 @@ impl Item for QtStyleButton {
|
||||||
return img;
|
return img;
|
||||||
});
|
});
|
||||||
return HighLevelRenderingPrimitive::Image {
|
return HighLevelRenderingPrimitive::Image {
|
||||||
x: Self::field_offsets().x.apply_pin(self).get(),
|
x: Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
y: Self::field_offsets().y.apply_pin(self).get(),
|
y: Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
source: to_resource(img),
|
source: to_resource(img),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ impl Item for QtStyleButton {
|
||||||
#[cfg(have_qt)]
|
#[cfg(have_qt)]
|
||||||
{
|
{
|
||||||
let text: qttypes::QString =
|
let text: qttypes::QString =
|
||||||
Self::field_offsets().text.apply_pin(self).get().as_str().into();
|
Self::FIELD_OFFSETS.text.apply_pin(self).get().as_str().into();
|
||||||
let size = cpp!(unsafe [
|
let size = cpp!(unsafe [
|
||||||
text as "QString"
|
text as "QString"
|
||||||
] -> qttypes::QSize as "QSize" {
|
] -> qttypes::QSize as "QSize" {
|
||||||
|
@ -130,20 +130,20 @@ impl Item for QtStyleButton {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn input_event(self: Pin<&Self>, event: MouseEvent) {
|
fn input_event(self: Pin<&Self>, event: MouseEvent) {
|
||||||
Self::field_offsets().pressed.apply_pin(self).set(match event.what {
|
Self::FIELD_OFFSETS.pressed.apply_pin(self).set(match event.what {
|
||||||
MouseEventType::MousePressed => true,
|
MouseEventType::MousePressed => true,
|
||||||
MouseEventType::MouseReleased => false,
|
MouseEventType::MouseReleased => false,
|
||||||
MouseEventType::MouseMoved => return,
|
MouseEventType::MouseMoved => return,
|
||||||
});
|
});
|
||||||
if matches!(event.what, MouseEventType::MouseReleased) {
|
if matches!(event.what, MouseEventType::MouseReleased) {
|
||||||
Self::field_offsets().clicked.apply_pin(self).emit(())
|
Self::FIELD_OFFSETS.clicked.apply_pin(self).emit(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ItemConsts for QtStyleButton {
|
impl ItemConsts for QtStyleButton {
|
||||||
const cached_rendering_data_offset: const_field_offset::FieldOffset<Self, CachedRenderingData> =
|
const cached_rendering_data_offset: const_field_offset::FieldOffset<Self, CachedRenderingData> =
|
||||||
Self::field_offsets().cached_rendering_data.as_unpinned_projection();
|
Self::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemVTable_static! { #[no_mangle] pub static QtStyleButtonVTable for QtStyleButton }
|
ItemVTable_static! { #[no_mangle] pub static QtStyleButtonVTable for QtStyleButton }
|
||||||
|
@ -165,21 +165,21 @@ pub struct QtStyleCheckBox {
|
||||||
impl Item for QtStyleCheckBox {
|
impl Item for QtStyleCheckBox {
|
||||||
fn geometry(self: Pin<&Self>) -> Rect {
|
fn geometry(self: Pin<&Self>) -> Rect {
|
||||||
euclid::rect(
|
euclid::rect(
|
||||||
Self::field_offsets().x.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
Self::field_offsets().y.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
Self::field_offsets().width.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.width.apply_pin(self).get(),
|
||||||
Self::field_offsets().height.apply_pin(self).get(),
|
Self::FIELD_OFFSETS.height.apply_pin(self).get(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
|
||||||
#[cfg(have_qt)]
|
#[cfg(have_qt)]
|
||||||
{
|
{
|
||||||
let checked: bool = Self::field_offsets().checked.apply_pin(self).get();
|
let checked: bool = Self::FIELD_OFFSETS.checked.apply_pin(self).get();
|
||||||
let text: qttypes::QString =
|
let text: qttypes::QString =
|
||||||
Self::field_offsets().text.apply_pin(self).get().as_str().into();
|
Self::FIELD_OFFSETS.text.apply_pin(self).get().as_str().into();
|
||||||
let size: qttypes::QSize = qttypes::QSize {
|
let size: qttypes::QSize = qttypes::QSize {
|
||||||
width: Self::field_offsets().width.apply_pin(self).get() as _,
|
width: Self::FIELD_OFFSETS.width.apply_pin(self).get() as _,
|
||||||
height: Self::field_offsets().height.apply_pin(self).get() as _,
|
height: Self::FIELD_OFFSETS.height.apply_pin(self).get() as _,
|
||||||
};
|
};
|
||||||
|
|
||||||
let img = cpp!(unsafe [
|
let img = cpp!(unsafe [
|
||||||
|
@ -199,8 +199,8 @@ impl Item for QtStyleCheckBox {
|
||||||
return img;
|
return img;
|
||||||
});
|
});
|
||||||
return HighLevelRenderingPrimitive::Image {
|
return HighLevelRenderingPrimitive::Image {
|
||||||
x: Self::field_offsets().x.apply_pin(self).get(),
|
x: Self::FIELD_OFFSETS.x.apply_pin(self).get(),
|
||||||
y: Self::field_offsets().y.apply_pin(self).get(),
|
y: Self::FIELD_OFFSETS.y.apply_pin(self).get(),
|
||||||
source: to_resource(img),
|
source: to_resource(img),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ impl Item for QtStyleCheckBox {
|
||||||
#[cfg(have_qt)]
|
#[cfg(have_qt)]
|
||||||
{
|
{
|
||||||
let text: qttypes::QString =
|
let text: qttypes::QString =
|
||||||
Self::field_offsets().text.apply_pin(self).get().as_str().into();
|
Self::FIELD_OFFSETS.text.apply_pin(self).get().as_str().into();
|
||||||
let size = cpp!(unsafe [
|
let size = cpp!(unsafe [
|
||||||
text as "QString"
|
text as "QString"
|
||||||
] -> qttypes::QSize as "QSize" {
|
] -> qttypes::QSize as "QSize" {
|
||||||
|
@ -234,18 +234,18 @@ impl Item for QtStyleCheckBox {
|
||||||
|
|
||||||
fn input_event(self: Pin<&Self>, event: MouseEvent) {
|
fn input_event(self: Pin<&Self>, event: MouseEvent) {
|
||||||
if matches!(event.what, MouseEventType::MouseReleased) {
|
if matches!(event.what, MouseEventType::MouseReleased) {
|
||||||
Self::field_offsets()
|
Self::FIELD_OFFSETS
|
||||||
.checked
|
.checked
|
||||||
.apply_pin(self)
|
.apply_pin(self)
|
||||||
.set(!Self::field_offsets().checked.apply_pin(self).get());
|
.set(!Self::FIELD_OFFSETS.checked.apply_pin(self).get());
|
||||||
Self::field_offsets().toggled.apply_pin(self).emit(())
|
Self::FIELD_OFFSETS.toggled.apply_pin(self).emit(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ItemConsts for QtStyleCheckBox {
|
impl ItemConsts for QtStyleCheckBox {
|
||||||
const cached_rendering_data_offset: const_field_offset::FieldOffset<Self, CachedRenderingData> =
|
const cached_rendering_data_offset: const_field_offset::FieldOffset<Self, CachedRenderingData> =
|
||||||
Self::field_offsets().cached_rendering_data.as_unpinned_projection();
|
Self::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection();
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemVTable_static! { #[no_mangle] pub static QtStyleCheckBoxVTable for QtStyleCheckBox }
|
ItemVTable_static! { #[no_mangle] pub static QtStyleCheckBoxVTable for QtStyleCheckBox }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue