C++: rename component_type to static_vtable

Then there is no reference to "component" in vtable.h
This commit is contained in:
Olivier Goffart 2021-01-14 09:39:21 +01:00
parent 1bcf446078
commit 090039094f
18 changed files with 26 additions and 23 deletions

View file

@ -112,7 +112,7 @@ public:
void init_items(Component *c, ItemTree items) const
{
cbindgen_private::sixtyfps_component_init_items(
vtable::VRef<ComponentVTable> { &Component::component_type, c }, items, &inner);
vtable::VRef<ComponentVTable> { &Component::static_vtable, c }, items, &inner);
}
template<typename Component>
@ -547,7 +547,7 @@ public:
vtable::VRef<private_api::ComponentVTable> item_at(int i) const
{
const auto &x = inner->data.at(i);
return { &C::component_type, const_cast<C *>(&(**x.ptr)) };
return { &C::static_vtable, const_cast<C *>(&(**x.ptr)) };
}
void compute_layout(cbindgen_private::Rect parent_rect) const
@ -555,7 +555,7 @@ public:
if (!inner)
return;
for (auto &x : inner->data) {
(*x.ptr)->apply_layout({ &C::component_type, const_cast<C *>(&(**x.ptr)) },
(*x.ptr)->apply_layout({ &C::static_vtable, const_cast<C *>(&(**x.ptr)) },
parent_rect);
}
}

View file

@ -66,7 +66,7 @@ struct VRcInner {
template<typename VTable_, typename X_> friend class VWeak;
private:
VRcInner() : layout {} {}
const VTable *vtable = &X::component_type;
const VTable *vtable = &X::static_vtable;
int strong_ref = 1;
int weak_ref = 1;
std::uint16_t data_offset = offsetof(VRcInner, data);
@ -108,6 +108,9 @@ public:
new(this) VRc(other);
return *this;
}
/// Construct a new VRc holding an X.
///
/// The type X must have a static member `static_vtable` of type VTable
template<typename ...Args> static VRc make(Args... args) {
auto mem = ::operator new(sizeof(VRcInner<VTable, X>), static_cast<std::align_val_t>(alignof(VRcInner<VTable, X>)));
auto inner = new (mem) VRcInner<VTable, X>;

View file

@ -837,7 +837,7 @@ fn generate_component(
.to_owned(),
statements: Some(vec![
"float vp_w = viewport_width->get();".to_owned(),
format!("apply_layout({{&component_type, const_cast<void *>(static_cast<const void *>(this))}}, sixtyfps::Rect{{ 0, *offset_y, vp_w, {h} }});", h = "0/*FIXME: should compute the heigth somehow*/"),
format!("apply_layout({{&static_vtable, const_cast<void *>(static_cast<const void *>(this))}}, sixtyfps::Rect{{ 0, *offset_y, vp_w, {h} }});", h = "0/*FIXME: should compute the heigth somehow*/"),
format!("{}.set(*offset_y);", p_y), // FIXME: shouldn't that be handled by apply layout?
format!("*offset_y += {}.get();", p_height),
format!("float w = {}.get();", p_width),
@ -855,7 +855,7 @@ fn generate_component(
name: "box_layout_data".into(),
signature: "() const -> sixtyfps::BoxLayoutCellData".to_owned(),
statements: Some(vec![format!(
"return {{ layouting_info({{&component_type, const_cast<void *>(static_cast<const void *>(this))}}), &{x}, &{y}, &{w}, &{h} }};",
"return {{ layouting_info({{&static_vtable, const_cast<void *>(static_cast<const void *>(this))}}), &{x}, &{y}, &{w}, &{h} }};",
x = p_x,
y = p_y,
w = p_width,
@ -1143,7 +1143,7 @@ fn generate_component(
Access::Public,
Declaration::Var(Var {
ty: "static const sixtyfps::private_api::ComponentVTable".to_owned(),
name: "component_type".to_owned(),
name: "static_vtable".to_owned(),
init: None,
}),
));
@ -1186,7 +1186,7 @@ fn generate_component(
if !component.is_global() {
file.definitions.push(Declaration::Var(Var {
ty: "const sixtyfps::private_api::ComponentVTable".to_owned(),
name: format!("{}::component_type", component_id),
name: format!("{}::static_vtable", component_id),
init: Some(format!(
"{{ visit_children, get_item_ref, layouting_info, apply_layout, sixtyfps::private_api::drop_in_place<{}>, sixtyfps::private_api::dealloc }}",
component_id)

View file

@ -36,7 +36,7 @@ TestCase := Container {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 200});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 200});
assert(instance.get_rect1_pos_ok());
```

View file

@ -44,7 +44,7 @@ TestCase := MegaContainer {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 200});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 200});
assert(instance.get_rect1_pos_ok());
```

View file

@ -75,7 +75,7 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_v1());
assert(instance.get_v2());
assert(instance.get_v3());

View file

@ -28,7 +28,7 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_elem1_ok());
assert(instance.get_elem2_ok());
assert(instance.get_elem3_ok());

View file

@ -42,7 +42,7 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_rect1_pos_ok());
assert(instance.get_rect2_pos_ok());
assert(instance.get_rect3_pos_ok());

View file

@ -60,7 +60,7 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_rect1_pos_ok());
assert(instance.get_rect2_pos_ok());
assert(instance.get_rect3_pos_ok());

View file

@ -54,7 +54,7 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_rect1_pos_ok());
assert(instance.get_rect2_pos_ok());
assert(instance.get_rect3_pos_ok());

View file

@ -58,7 +58,7 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 600, 300});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 600, 300});
assert(instance.get_rect1_pos_ok());
assert(instance.get_rect2_pos_ok());
```

View file

@ -41,7 +41,7 @@ TestCase := Rectangle {
auto handle = TestCase::create();
const TestCase &instance = *handle;
sixtyfps::testing::send_mouse_click(&handle, -1., -1.); // FIXME: Force creation of repeater components before computing the layout
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
sixtyfps::testing::send_mouse_click(&handle, 190., 190.);
assert_eq(instance.get_value(), 1+1);

View file

@ -69,7 +69,7 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_blue_rect_ok());
assert(instance.get_red_rect_ok());
assert(instance.get_green_rect_ok());

View file

@ -130,7 +130,7 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_rect_blue_ok());
assert(instance.get_rect_orange_ok());
assert(instance.get_rect_red_ok());

View file

@ -45,7 +45,7 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_rect1_pos_ok());
assert(instance.get_rect2_pos_ok());
assert(instance.get_rect3_pos_ok());

View file

@ -55,7 +55,7 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_rect1_pos_ok());
assert(instance.get_rect2_pos_ok());
assert(instance.get_rect3_pos_ok());

View file

@ -44,7 +44,7 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_rect1_pos_ok());
assert(instance.get_rect2_pos_ok());
```

View file

@ -85,7 +85,7 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_test1());
assert(instance.get_test2());
assert(instance.get_test3());