mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
C++: rename component_type to static_vtable
Then there is no reference to "component" in vtable.h
This commit is contained in:
parent
1bcf446078
commit
090039094f
18 changed files with 26 additions and 23 deletions
|
@ -112,7 +112,7 @@ public:
|
||||||
void init_items(Component *c, ItemTree items) const
|
void init_items(Component *c, ItemTree items) const
|
||||||
{
|
{
|
||||||
cbindgen_private::sixtyfps_component_init_items(
|
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>
|
template<typename Component>
|
||||||
|
@ -547,7 +547,7 @@ public:
|
||||||
vtable::VRef<private_api::ComponentVTable> item_at(int i) const
|
vtable::VRef<private_api::ComponentVTable> item_at(int i) const
|
||||||
{
|
{
|
||||||
const auto &x = inner->data.at(i);
|
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
|
void compute_layout(cbindgen_private::Rect parent_rect) const
|
||||||
|
@ -555,7 +555,7 @@ public:
|
||||||
if (!inner)
|
if (!inner)
|
||||||
return;
|
return;
|
||||||
for (auto &x : inner->data) {
|
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);
|
parent_rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ struct VRcInner {
|
||||||
template<typename VTable_, typename X_> friend class VWeak;
|
template<typename VTable_, typename X_> friend class VWeak;
|
||||||
private:
|
private:
|
||||||
VRcInner() : layout {} {}
|
VRcInner() : layout {} {}
|
||||||
const VTable *vtable = &X::component_type;
|
const VTable *vtable = &X::static_vtable;
|
||||||
int strong_ref = 1;
|
int strong_ref = 1;
|
||||||
int weak_ref = 1;
|
int weak_ref = 1;
|
||||||
std::uint16_t data_offset = offsetof(VRcInner, data);
|
std::uint16_t data_offset = offsetof(VRcInner, data);
|
||||||
|
@ -108,6 +108,9 @@ public:
|
||||||
new(this) VRc(other);
|
new(this) VRc(other);
|
||||||
return *this;
|
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) {
|
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 mem = ::operator new(sizeof(VRcInner<VTable, X>), static_cast<std::align_val_t>(alignof(VRcInner<VTable, X>)));
|
||||||
auto inner = new (mem) VRcInner<VTable, X>;
|
auto inner = new (mem) VRcInner<VTable, X>;
|
||||||
|
|
|
@ -837,7 +837,7 @@ fn generate_component(
|
||||||
.to_owned(),
|
.to_owned(),
|
||||||
statements: Some(vec![
|
statements: Some(vec![
|
||||||
"float vp_w = viewport_width->get();".to_owned(),
|
"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!("{}.set(*offset_y);", p_y), // FIXME: shouldn't that be handled by apply layout?
|
||||||
format!("*offset_y += {}.get();", p_height),
|
format!("*offset_y += {}.get();", p_height),
|
||||||
format!("float w = {}.get();", p_width),
|
format!("float w = {}.get();", p_width),
|
||||||
|
@ -855,7 +855,7 @@ fn generate_component(
|
||||||
name: "box_layout_data".into(),
|
name: "box_layout_data".into(),
|
||||||
signature: "() const -> sixtyfps::BoxLayoutCellData".to_owned(),
|
signature: "() const -> sixtyfps::BoxLayoutCellData".to_owned(),
|
||||||
statements: Some(vec![format!(
|
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,
|
x = p_x,
|
||||||
y = p_y,
|
y = p_y,
|
||||||
w = p_width,
|
w = p_width,
|
||||||
|
@ -1143,7 +1143,7 @@ fn generate_component(
|
||||||
Access::Public,
|
Access::Public,
|
||||||
Declaration::Var(Var {
|
Declaration::Var(Var {
|
||||||
ty: "static const sixtyfps::private_api::ComponentVTable".to_owned(),
|
ty: "static const sixtyfps::private_api::ComponentVTable".to_owned(),
|
||||||
name: "component_type".to_owned(),
|
name: "static_vtable".to_owned(),
|
||||||
init: None,
|
init: None,
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
|
@ -1186,7 +1186,7 @@ fn generate_component(
|
||||||
if !component.is_global() {
|
if !component.is_global() {
|
||||||
file.definitions.push(Declaration::Var(Var {
|
file.definitions.push(Declaration::Var(Var {
|
||||||
ty: "const sixtyfps::private_api::ComponentVTable".to_owned(),
|
ty: "const sixtyfps::private_api::ComponentVTable".to_owned(),
|
||||||
name: format!("{}::component_type", component_id),
|
name: format!("{}::static_vtable", component_id),
|
||||||
init: Some(format!(
|
init: Some(format!(
|
||||||
"{{ visit_children, get_item_ref, layouting_info, apply_layout, sixtyfps::private_api::drop_in_place<{}>, sixtyfps::private_api::dealloc }}",
|
"{{ visit_children, get_item_ref, layouting_info, apply_layout, sixtyfps::private_api::drop_in_place<{}>, sixtyfps::private_api::dealloc }}",
|
||||||
component_id)
|
component_id)
|
||||||
|
|
|
@ -36,7 +36,7 @@ TestCase := Container {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
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());
|
assert(instance.get_rect1_pos_ok());
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ TestCase := MegaContainer {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
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());
|
assert(instance.get_rect1_pos_ok());
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ TestCase := Rectangle {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
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_v1());
|
||||||
assert(instance.get_v2());
|
assert(instance.get_v2());
|
||||||
assert(instance.get_v3());
|
assert(instance.get_v3());
|
||||||
|
|
|
@ -28,7 +28,7 @@ TestCase := Rectangle {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
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_elem1_ok());
|
||||||
assert(instance.get_elem2_ok());
|
assert(instance.get_elem2_ok());
|
||||||
assert(instance.get_elem3_ok());
|
assert(instance.get_elem3_ok());
|
||||||
|
|
|
@ -42,7 +42,7 @@ TestCase := Rectangle {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
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_rect1_pos_ok());
|
||||||
assert(instance.get_rect2_pos_ok());
|
assert(instance.get_rect2_pos_ok());
|
||||||
assert(instance.get_rect3_pos_ok());
|
assert(instance.get_rect3_pos_ok());
|
||||||
|
|
|
@ -60,7 +60,7 @@ TestCase := Rectangle {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
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_rect1_pos_ok());
|
||||||
assert(instance.get_rect2_pos_ok());
|
assert(instance.get_rect2_pos_ok());
|
||||||
assert(instance.get_rect3_pos_ok());
|
assert(instance.get_rect3_pos_ok());
|
||||||
|
|
|
@ -54,7 +54,7 @@ TestCase := Rectangle {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
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_rect1_pos_ok());
|
||||||
assert(instance.get_rect2_pos_ok());
|
assert(instance.get_rect2_pos_ok());
|
||||||
assert(instance.get_rect3_pos_ok());
|
assert(instance.get_rect3_pos_ok());
|
||||||
|
|
|
@ -58,7 +58,7 @@ TestCase := Rectangle {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
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_rect1_pos_ok());
|
||||||
assert(instance.get_rect2_pos_ok());
|
assert(instance.get_rect2_pos_ok());
|
||||||
```
|
```
|
||||||
|
|
|
@ -41,7 +41,7 @@ TestCase := Rectangle {
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
const TestCase &instance = *handle;
|
||||||
sixtyfps::testing::send_mouse_click(&handle, -1., -1.); // FIXME: Force creation of repeater components before computing the layout
|
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.);
|
sixtyfps::testing::send_mouse_click(&handle, 190., 190.);
|
||||||
assert_eq(instance.get_value(), 1+1);
|
assert_eq(instance.get_value(), 1+1);
|
||||||
|
|
|
@ -69,7 +69,7 @@ TestCase := Rectangle {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
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_blue_rect_ok());
|
||||||
assert(instance.get_red_rect_ok());
|
assert(instance.get_red_rect_ok());
|
||||||
assert(instance.get_green_rect_ok());
|
assert(instance.get_green_rect_ok());
|
||||||
|
|
|
@ -130,7 +130,7 @@ TestCase := Rectangle {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
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_blue_ok());
|
||||||
assert(instance.get_rect_orange_ok());
|
assert(instance.get_rect_orange_ok());
|
||||||
assert(instance.get_rect_red_ok());
|
assert(instance.get_rect_red_ok());
|
||||||
|
|
|
@ -45,7 +45,7 @@ TestCase := Rectangle {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
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_rect1_pos_ok());
|
||||||
assert(instance.get_rect2_pos_ok());
|
assert(instance.get_rect2_pos_ok());
|
||||||
assert(instance.get_rect3_pos_ok());
|
assert(instance.get_rect3_pos_ok());
|
||||||
|
|
|
@ -55,7 +55,7 @@ TestCase := Rectangle {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
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_rect1_pos_ok());
|
||||||
assert(instance.get_rect2_pos_ok());
|
assert(instance.get_rect2_pos_ok());
|
||||||
assert(instance.get_rect3_pos_ok());
|
assert(instance.get_rect3_pos_ok());
|
||||||
|
|
|
@ -44,7 +44,7 @@ TestCase := Rectangle {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
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_rect1_pos_ok());
|
||||||
assert(instance.get_rect2_pos_ok());
|
assert(instance.get_rect2_pos_ok());
|
||||||
```
|
```
|
||||||
|
|
|
@ -85,7 +85,7 @@ TestCase := Rectangle {
|
||||||
```cpp
|
```cpp
|
||||||
auto handle = TestCase::create();
|
auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
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_test1());
|
||||||
assert(instance.get_test2());
|
assert(instance.get_test2());
|
||||||
assert(instance.get_test3());
|
assert(instance.get_test3());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue