Change the field_offsets() function to a FIELD_OFFSETS associated const

This commit is contained in:
Olivier Goffart 2020-08-03 16:04:55 +02:00
parent de188e0a54
commit 1bfd708784
10 changed files with 156 additions and 156 deletions

View file

@ -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
returns an object which has fields with the same name as the fields of the original struct,
The macro FieldOffsets adds a `FIELD_OFFSETS` associated const to the struct, that
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`
```rust
@ -25,7 +25,7 @@ struct Foo {
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);
// This would not work on stable rust at the moment (rust 1.43)
@ -71,7 +71,7 @@ struct Foo {
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});
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 {
/// 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;
let mut len = 0usize;
#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) }
}, )*
}
}
};
}
#[allow(non_camel_case_types)]
@ -239,11 +239,11 @@ pub fn const_field_offset(input: TokenStream) -> TokenStream {
type Field = #types;
type PinFlag = #pin_flag;
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 {
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

View file

@ -359,7 +359,7 @@ mod tests {
#[test]
fn test_simple() {
// 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`
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 } };
// 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
{
@ -398,17 +398,17 @@ mod tests {
fn test_pin() {
use ::alloc::boxed::Box;
// 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 = Box::pin(Foo { a: 21, b: 22.0, c: true });
let pb: Pin<&f64> = foo_b_pin.apply_pin(foo.as_ref());
assert!(*pb == 22.0);
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);
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.;
assert!(x.y.b == 12.0);
}

View file

@ -24,18 +24,18 @@ struct MyStruct3 {
ms2: MyStruct2,
}
const XX_CONST: usize = MyStruct2::field_offsets().xx.get_byte_offset();
static D_STATIC: usize = MyStruct::field_offsets().d.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();
#[test]
fn test() {
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, 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!(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, k), MyStruct2::field_offsets().k.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, 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!(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, k), MyStruct2::FIELD_OFFSETS.k.get_byte_offset());
assert_eq!(XX_CONST, offset_of!(MyStruct2, xx));
assert_eq!(D_STATIC, offset_of!(MyStruct, d));
@ -80,18 +80,18 @@ struct MyStruct2Pin {
v: u32,
}
const XX_CONST_PIN: usize = MyStruct2Pin::field_offsets().xx.get_byte_offset();
static D_STATIC_PIN: usize = MyStructPin::field_offsets().d.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();
#[test]
fn test_pin() {
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, 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!(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, k), MyStruct2Pin::field_offsets().k.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, 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!(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, k), MyStruct2Pin::FIELD_OFFSETS.k.get_byte_offset());
assert_eq!(XX_CONST_PIN, offset_of!(MyStruct2Pin, xx));
assert_eq!(D_STATIC_PIN, offset_of!(MyStructPin, d));

View file

@ -43,7 +43,7 @@ impl Hello for SomeStruct {
impl HelloConsts for SomeStruct {
const CONSTANT: usize = 88;
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);
@ -81,7 +81,7 @@ impl Hello for AnotherStruct {
impl HelloConsts for AnotherStruct {
const CONSTANT: usize = 99;
const SOME_OFFSET: const_field_offset::FieldOffset<AnotherStruct, u32> =
AnotherStruct::field_offsets().foo;
AnotherStruct::FIELD_OFFSETS.foo;
}
HelloVTable_static!(static ANOTHERSTRUCT_VTABLE for AnotherStruct);
@ -117,7 +117,7 @@ fn test() {
}
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 } };
assert_eq!(vo.apply(&ssc).foo(4), 32 + 4);
assert_eq!(vo.apply_mut(&mut ssc).foo_mut(4), 32 + 4);

View file

@ -73,7 +73,7 @@ fn generate_component(
quote!(
#[allow(dead_code)]
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(),
@ -83,7 +83,7 @@ fn generate_component(
quote!(
#[allow(dead_code)]
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(),
@ -107,7 +107,7 @@ fn generate_component(
quote!(
#[allow(dead_code)]
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(),
@ -123,7 +123,7 @@ fn generate_component(
quote!(
#[allow(dead_code)]
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(),
@ -155,7 +155,7 @@ fn generate_component(
item_tree_array.push(quote!(
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,
children_index: #children_index,
}
@ -219,7 +219,7 @@ fn generate_component(
repeated_visit_branch.push(quote!(
#repeater_index => {
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();
self_pinned.#repeater_id.update_model(#model, || {
#rep_component_id::new(self_pinned.self_weak.get().unwrap().clone())
@ -247,7 +247,7 @@ fn generate_component(
item_tree_array.push(quote!(
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,
children_index: #children_index,
}
@ -536,12 +536,12 @@ fn access_member(
let component_id = component_id(&enclosing_component);
let name_ident = quote::format_ident!("{}", 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 {
let elem_ident = quote::format_ident!("{}", e.id);
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)
)
}
@ -571,7 +571,7 @@ fn dpi_expression(component: &Rc<Component>) -> TokenStream {
component_rust = quote!(#component_rust.parent.upgrade().unwrap().as_ref());
}
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 {
@ -612,7 +612,7 @@ fn compile_expression(e: &Expression, component: &Rc<Component>) -> TokenStream
Expression::RepeaterIndexReference { element } => {
if element.upgrade().unwrap().borrow().base_type == Type::Component(component.clone()) {
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 {
todo!();
}
@ -620,7 +620,7 @@ fn compile_expression(e: &Expression, component: &Rc<Component>) -> TokenStream
Expression::RepeaterModelReference { element } => {
if element.upgrade().unwrap().borrow().base_type == Type::Component(component.clone()) {
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 {
todo!();
}
@ -858,7 +858,7 @@ impl LayoutItemCodeGen for ElementRc {
_layout_tree: &'b mut Vec<LayoutTreeItem<'a>>,
) -> TokenStream {
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())
}
}

View file

@ -29,10 +29,10 @@ impl FlickableData {
inner.pressed_pos = event.pos;
inner.pressed_time = Some(crate::animations::current_tick());
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)
.get(),
(Flickable::field_offsets().viewport + Rectangle::field_offsets().y)
(Flickable::FIELD_OFFSETS.viewport + Rectangle::FIELD_OFFSETS.y)
.apply_pin(flick)
.get(),
)
@ -53,10 +53,10 @@ impl FlickableData {
easing: EasingCurve::CubicBezier([0.0, 0.0, 0.58, 1.0]),
..PropertyAnimation::default()
};
(Flickable::field_offsets().viewport + Rectangle::field_offsets().x)
(Flickable::FIELD_OFFSETS.viewport + Rectangle::FIELD_OFFSETS.x)
.apply_pin(flick)
.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)
.set_animated_value(final_pos.y, &anim);
}
@ -68,10 +68,10 @@ impl FlickableData {
flick,
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)
.set(new_pos.x);
(Flickable::field_offsets().viewport + Rectangle::field_offsets().y)
(Flickable::FIELD_OFFSETS.viewport + Rectangle::FIELD_OFFSETS.y)
.apply_pin(flick)
.set(new_pos.y);
}
@ -82,12 +82,12 @@ impl FlickableData {
/// Make sure that the point is within the bounds
fn ensure_in_bound(flick: Pin<&Flickable>, p: Point) -> Point {
let w = (Flickable::field_offsets().width).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 w = (Flickable::FIELD_OFFSETS.width).apply_pin(flick).get();
let h = (Flickable::FIELD_OFFSETS.height).apply_pin(flick).get();
/*let vw = (Flickable::FIELD_OFFSETS.viewport + Rectangle::FIELD_OFFSETS.width)
.apply_pin(flick)
.get();
let vh = (Flickable::field_offsets().viewport + Rectangle::field_offsets().height)
let vh = (Flickable::FIELD_OFFSETS.viewport + Rectangle::FIELD_OFFSETS.height)
.apply_pin(flick)
.get();*/
let (vw, vh) = (1000., 1000.); // FIXME: should be the actual viewport

View file

@ -44,22 +44,22 @@ pub struct Rectangle {
impl Item for Rectangle {
fn geometry(self: Pin<&Self>) -> Rect {
euclid::rect(
Self::field_offsets().x.apply_pin(self).get(),
Self::field_offsets().y.apply_pin(self).get(),
Self::field_offsets().width.apply_pin(self).get(),
Self::field_offsets().height.apply_pin(self).get(),
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
Self::FIELD_OFFSETS.width.apply_pin(self).get(),
Self::FIELD_OFFSETS.height.apply_pin(self).get(),
)
}
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
let width = Self::field_offsets().width.apply_pin(self).get();
let height = Self::field_offsets().height.apply_pin(self).get();
let width = Self::FIELD_OFFSETS.width.apply_pin(self).get();
let height = Self::FIELD_OFFSETS.height.apply_pin(self).get();
if width > 0. && height > 0. {
HighLevelRenderingPrimitive::Rectangle {
x: Self::field_offsets().x.apply_pin(self).get(),
y: Self::field_offsets().y.apply_pin(self).get(),
x: Self::FIELD_OFFSETS.x.apply_pin(self).get(),
y: Self::FIELD_OFFSETS.y.apply_pin(self).get(),
width,
height,
color: Self::field_offsets().color.apply_pin(self).get(),
color: Self::FIELD_OFFSETS.color.apply_pin(self).get(),
}
} else {
HighLevelRenderingPrimitive::NoContents
@ -77,7 +77,7 @@ impl ItemConsts for Rectangle {
const cached_rendering_data_offset: const_field_offset::FieldOffset<
Rectangle,
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;
@ -101,25 +101,25 @@ pub struct BorderRectangle {
impl Item for BorderRectangle {
fn geometry(self: Pin<&Self>) -> Rect {
euclid::rect(
Self::field_offsets().x.apply_pin(self).get(),
Self::field_offsets().y.apply_pin(self).get(),
Self::field_offsets().width.apply_pin(self).get(),
Self::field_offsets().height.apply_pin(self).get(),
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
Self::FIELD_OFFSETS.width.apply_pin(self).get(),
Self::FIELD_OFFSETS.height.apply_pin(self).get(),
)
}
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
let width = Self::field_offsets().width.apply_pin(self).get();
let height = Self::field_offsets().height.apply_pin(self).get();
let width = Self::FIELD_OFFSETS.width.apply_pin(self).get();
let height = Self::FIELD_OFFSETS.height.apply_pin(self).get();
if width > 0. && height > 0. {
HighLevelRenderingPrimitive::BorderRectangle {
x: Self::field_offsets().x.apply_pin(self).get(),
y: Self::field_offsets().y.apply_pin(self).get(),
x: Self::FIELD_OFFSETS.x.apply_pin(self).get(),
y: Self::FIELD_OFFSETS.y.apply_pin(self).get(),
width,
height,
color: Self::field_offsets().color.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_color: Self::field_offsets().border_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_radius: Self::FIELD_OFFSETS.border_radius.apply_pin(self).get(),
border_color: Self::FIELD_OFFSETS.border_color.apply_pin(self).get(),
}
} else {
HighLevelRenderingPrimitive::NoContents
@ -137,7 +137,7 @@ impl ItemConsts for BorderRectangle {
const cached_rendering_data_offset: const_field_offset::FieldOffset<
BorderRectangle,
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;
@ -158,17 +158,17 @@ pub struct Image {
impl Item for Image {
fn geometry(self: Pin<&Self>) -> Rect {
euclid::rect(
Self::field_offsets().x.apply_pin(self).get(),
Self::field_offsets().y.apply_pin(self).get(),
Self::field_offsets().width.apply_pin(self).get(),
Self::field_offsets().height.apply_pin(self).get(),
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
Self::FIELD_OFFSETS.width.apply_pin(self).get(),
Self::FIELD_OFFSETS.height.apply_pin(self).get(),
)
}
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
HighLevelRenderingPrimitive::Image {
x: Self::field_offsets().x.apply_pin(self).get(),
y: Self::field_offsets().y.apply_pin(self).get(),
source: Self::field_offsets().source.apply_pin(self).get(),
x: Self::FIELD_OFFSETS.x.apply_pin(self).get(),
y: Self::FIELD_OFFSETS.y.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<
Image,
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;
@ -207,27 +207,27 @@ impl Item for Text {
// FIXME: width / height. or maybe it doesn't matter? (
fn geometry(self: Pin<&Self>) -> Rect {
euclid::rect(
Self::field_offsets().x.apply_pin(self).get(),
Self::field_offsets().y.apply_pin(self).get(),
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
0.,
0.,
)
}
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
HighLevelRenderingPrimitive::Text {
x: Self::field_offsets().x.apply_pin(self).get(),
y: Self::field_offsets().y.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_pixel_size: Self::field_offsets().font_pixel_size.apply_pin(self).get(),
color: Self::field_offsets().color.apply_pin(self).get(),
x: Self::FIELD_OFFSETS.x.apply_pin(self).get(),
y: Self::FIELD_OFFSETS.y.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_pixel_size: Self::FIELD_OFFSETS.font_pixel_size.apply_pin(self).get(),
color: Self::FIELD_OFFSETS.color.apply_pin(self).get(),
}
}
fn layouting_info(self: Pin<&Self>) -> LayoutInfo {
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 text = Self::field_offsets().text.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 text = Self::FIELD_OFFSETS.text.apply_pin(self).get();
crate::font::FONT_CACHE.with(|fc| {
let font = fc.find_font(&font_family, font_pixel_size);
@ -247,7 +247,7 @@ impl Item for Text {
impl ItemConsts for Text {
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;
@ -271,10 +271,10 @@ pub struct TouchArea {
impl Item for TouchArea {
fn geometry(self: Pin<&Self>) -> Rect {
euclid::rect(
Self::field_offsets().x.apply_pin(self).get(),
Self::field_offsets().y.apply_pin(self).get(),
Self::field_offsets().width.apply_pin(self).get(),
Self::field_offsets().height.apply_pin(self).get(),
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
Self::FIELD_OFFSETS.width.apply_pin(self).get(),
Self::FIELD_OFFSETS.height.apply_pin(self).get(),
)
}
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
@ -287,13 +287,13 @@ impl Item for TouchArea {
fn input_event(self: Pin<&Self>, event: MouseEvent) {
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::MouseReleased => false,
MouseEventType::MouseMoved => return,
});
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<
TouchArea,
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;
@ -325,22 +325,22 @@ pub struct Path {
impl Item for Path {
fn geometry(self: Pin<&Self>) -> Rect {
euclid::rect(
Self::field_offsets().x.apply_pin(self).get(),
Self::field_offsets().y.apply_pin(self).get(),
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
0.,
0.,
)
}
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
HighLevelRenderingPrimitive::Path {
x: Self::field_offsets().x.apply_pin(self).get(),
y: Self::field_offsets().y.apply_pin(self).get(),
width: Self::field_offsets().width.apply_pin(self).get(),
height: Self::field_offsets().height.apply_pin(self).get(),
elements: Self::field_offsets().elements.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_width: Self::field_offsets().stroke_width.apply_pin(self).get(),
x: Self::FIELD_OFFSETS.x.apply_pin(self).get(),
y: Self::FIELD_OFFSETS.y.apply_pin(self).get(),
width: Self::FIELD_OFFSETS.width.apply_pin(self).get(),
height: Self::FIELD_OFFSETS.height.apply_pin(self).get(),
elements: Self::FIELD_OFFSETS.elements.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_width: Self::FIELD_OFFSETS.stroke_width.apply_pin(self).get(),
}
}
@ -353,7 +353,7 @@ impl Item for Path {
impl ItemConsts for Path {
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;
@ -377,10 +377,10 @@ pub struct Flickable {
impl Item for Flickable {
fn geometry(self: Pin<&Self>) -> Rect {
euclid::rect(
Self::field_offsets().x.apply_pin(self).get(),
Self::field_offsets().y.apply_pin(self).get(),
Self::field_offsets().width.apply_pin(self).get(),
Self::field_offsets().height.apply_pin(self).get(),
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
Self::FIELD_OFFSETS.width.apply_pin(self).get(),
Self::FIELD_OFFSETS.height.apply_pin(self).get(),
)
}
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
@ -398,7 +398,7 @@ impl Item for Flickable {
impl ItemConsts for Flickable {
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;

View file

@ -65,20 +65,20 @@ pub fn builtin_item(input: TokenStream) -> TokenStream {
fn properties<Value: ValueType>() -> Vec<(&'static str, &'static dyn PropertyInfo<Self, Value>)> {
vec![#( {
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())
} ),*]
}
fn fields<Value: ValueType>() -> Vec<(&'static str, &'static dyn FieldInfo<Self, Value>)> {
vec![#( {
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> )
} ),*]
}
fn signals() -> Vec<(&'static str, FieldOffset<Self, crate::Signal<()>>)> {
vec![#(
(stringify!(#signal_field_names),#item_name::field_offsets().#signal_field_names)
(stringify!(#signal_field_names),#item_name::FIELD_OFFSETS.#signal_field_names)
),*]
}
}

View file

@ -269,7 +269,7 @@ fn generate_component(root_component: &Rc<object_tree::Component>) -> Rc<Compone
if is_flickable_rect {
use vtable::HasStaticVTable;
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 {
item: unsafe { vtable::VOffset::from_raw(Rectangle::static_vtable(), offset) },
children_index: tree_array.len() as u32 + 1,

View file

@ -61,21 +61,21 @@ pub struct QtStyleButton {
impl Item for QtStyleButton {
fn geometry(self: Pin<&Self>) -> Rect {
euclid::rect(
Self::field_offsets().x.apply_pin(self).get(),
Self::field_offsets().y.apply_pin(self).get(),
Self::field_offsets().width.apply_pin(self).get(),
Self::field_offsets().height.apply_pin(self).get(),
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
Self::FIELD_OFFSETS.width.apply_pin(self).get(),
Self::FIELD_OFFSETS.height.apply_pin(self).get(),
)
}
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
#[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 =
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 {
width: Self::field_offsets().width.apply_pin(self).get() as _,
height: Self::field_offsets().height.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 _,
};
let img = cpp!(unsafe [
@ -96,8 +96,8 @@ impl Item for QtStyleButton {
return img;
});
return HighLevelRenderingPrimitive::Image {
x: Self::field_offsets().x.apply_pin(self).get(),
y: Self::field_offsets().y.apply_pin(self).get(),
x: Self::FIELD_OFFSETS.x.apply_pin(self).get(),
y: Self::FIELD_OFFSETS.y.apply_pin(self).get(),
source: to_resource(img),
};
}
@ -109,7 +109,7 @@ impl Item for QtStyleButton {
#[cfg(have_qt)]
{
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 [
text as "QString"
] -> qttypes::QSize as "QSize" {
@ -130,20 +130,20 @@ impl Item for QtStyleButton {
}
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::MouseReleased => false,
MouseEventType::MouseMoved => return,
});
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 {
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 }
@ -165,21 +165,21 @@ pub struct QtStyleCheckBox {
impl Item for QtStyleCheckBox {
fn geometry(self: Pin<&Self>) -> Rect {
euclid::rect(
Self::field_offsets().x.apply_pin(self).get(),
Self::field_offsets().y.apply_pin(self).get(),
Self::field_offsets().width.apply_pin(self).get(),
Self::field_offsets().height.apply_pin(self).get(),
Self::FIELD_OFFSETS.x.apply_pin(self).get(),
Self::FIELD_OFFSETS.y.apply_pin(self).get(),
Self::FIELD_OFFSETS.width.apply_pin(self).get(),
Self::FIELD_OFFSETS.height.apply_pin(self).get(),
)
}
fn rendering_primitive(self: Pin<&Self>) -> HighLevelRenderingPrimitive {
#[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 =
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 {
width: Self::field_offsets().width.apply_pin(self).get() as _,
height: Self::field_offsets().height.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 _,
};
let img = cpp!(unsafe [
@ -199,8 +199,8 @@ impl Item for QtStyleCheckBox {
return img;
});
return HighLevelRenderingPrimitive::Image {
x: Self::field_offsets().x.apply_pin(self).get(),
y: Self::field_offsets().y.apply_pin(self).get(),
x: Self::FIELD_OFFSETS.x.apply_pin(self).get(),
y: Self::FIELD_OFFSETS.y.apply_pin(self).get(),
source: to_resource(img),
};
}
@ -212,7 +212,7 @@ impl Item for QtStyleCheckBox {
#[cfg(have_qt)]
{
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 [
text as "QString"
] -> qttypes::QSize as "QSize" {
@ -234,18 +234,18 @@ impl Item for QtStyleCheckBox {
fn input_event(self: Pin<&Self>, event: MouseEvent) {
if matches!(event.what, MouseEventType::MouseReleased) {
Self::field_offsets()
Self::FIELD_OFFSETS
.checked
.apply_pin(self)
.set(!Self::field_offsets().checked.apply_pin(self).get());
Self::field_offsets().toggled.apply_pin(self).emit(())
.set(!Self::FIELD_OFFSETS.checked.apply_pin(self).get());
Self::FIELD_OFFSETS.toggled.apply_pin(self).emit(())
}
}
}
impl ItemConsts for QtStyleCheckBox {
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 }