Remove the solve_layout from the component vtable

no longer required
This commit is contained in:
Olivier Goffart 2021-05-05 11:18:15 +02:00 committed by Olivier Goffart
parent f6b71b36a7
commit 720001a223
27 changed files with 5 additions and 103 deletions

View file

@ -587,15 +587,6 @@ public:
return { &C::static_vtable, const_cast<C *>(&(**x.ptr)) };
}
void compute_layout(cbindgen_private::Rect parent_rect) const
{
if (!inner)
return;
for (auto &x : inner->data) {
(*x.ptr)->apply_layout({ &C::static_vtable, const_cast<C *>(&(**x.ptr)) }, parent_rect);
}
}
float compute_layout_listview(const Property<float> *viewport_width, float listview_width) const
{
float offset = 0;

View file

@ -372,18 +372,6 @@ pub mod testing {
)
}
/// Applies the specified rectangular constraints to the component's layout.
pub fn apply_layout<
X: vtable::HasStaticVTable<sixtyfps_corelib::component::ComponentVTable>,
Component: Into<vtable::VRc<sixtyfps_corelib::component::ComponentVTable, X>> + ComponentHandle,
>(
component: &Component,
rect: sixtyfps_corelib::graphics::Rect,
) {
let rc = component.clone_strong().into();
vtable::VRc::borrow_pin(&rc).as_ref().apply_layout(rect);
}
/// Applies the specified scale factor to the window that's associated with the given component.
/// This overrides the value provided by the windowing system.
pub fn set_window_scale_factor<

View file

@ -11,7 +11,6 @@ LICENSE END */
//! This module contains the basic datastructures that are exposed to the C API
use crate::graphics::Rect;
use crate::item_tree::{ItemVisitorVTable, TraversalOrder, VisitChildrenResult};
use crate::items::{ItemVTable, ItemWeak};
use crate::layout::LayoutInfo;
@ -47,9 +46,6 @@ pub struct ComponentVTable {
/// Returns the layout info for this component
pub layout_info: extern "C" fn(core::pin::Pin<VRef<ComponentVTable>>) -> LayoutInfo,
/// Apply the layout to all the items in the component, and set the geometry of the root to the given rect
pub apply_layout: extern "C" fn(core::pin::Pin<VRef<ComponentVTable>>, Rect),
/// in-place destructor (for VRc)
pub drop_in_place: unsafe fn(VRefMut<ComponentVTable>) -> vtable::Layout,
/// dealloc function (for VRc)

View file

@ -503,7 +503,6 @@ impl<C: RepeatedComponent + 'static> Repeater<C> {
};
for c in self.inner.borrow().borrow().components.iter() {
c.1.as_ref().map(|x| {
x.as_pin_ref().apply_layout(Default::default());
get_height_visitor(x.as_pin_ref().get_item_ref(0));
});
}
@ -522,7 +521,6 @@ impl<C: RepeatedComponent + 'static> Repeater<C> {
self.ensure_updated_impl(&init, &model, 1);
if let Some(c) = self.inner.borrow().borrow().components.get(0) {
c.1.as_ref().map(|x| {
x.as_pin_ref().apply_layout(Default::default());
get_height_visitor(x.as_pin_ref().get_item_ref(0));
});
} else {
@ -632,13 +630,6 @@ impl<C: RepeatedComponent> Repeater<C> {
self.inner.borrow().borrow().components.iter().flat_map(|x| x.1.clone()).collect()
}
/// Recompute the layout of each child elements
pub fn compute_layout(&self) {
for c in self.inner.borrow().borrow().components.iter() {
c.1.as_ref().map(|x| x.as_pin_ref().apply_layout(Default::default()));
}
}
/// Same as compule_layout, but only for the ListView
pub fn compute_layout_listview(
&self,

View file

@ -37,8 +37,6 @@ pub extern "C" fn sixtyfps_send_mouse_click(
window: &ComponentWindow,
) {
let mut state = crate::input::MouseInputState::default();
vtable::VRc::borrow_pin(component).as_ref().apply_layout(Default::default());
let pos = euclid::point2(x, y);
state = crate::input::process_mouse_input(

View file

@ -19,7 +19,7 @@ use sixtyfps_compilerlib::*;
use sixtyfps_compilerlib::{diagnostics::BuildDiagnostics, object_tree::PropertyDeclaration};
use sixtyfps_compilerlib::{expression_tree::Expression, langtype::PropertyLookupResult};
use sixtyfps_corelib::component::{Component, ComponentRef, ComponentRefPin, ComponentVTable};
use sixtyfps_corelib::graphics::{ImageReference, Rect};
use sixtyfps_corelib::graphics::ImageReference;
use sixtyfps_corelib::item_tree::{
ItemTreeNode, ItemVisitorRefMut, ItemVisitorVTable, TraversalOrder, VisitChildrenResult,
};
@ -139,7 +139,6 @@ impl RepeatedComponent for ErasedComponentBox {
generativity::make_guard!(guard);
let s = self.unerase(guard);
self.borrow().as_ref().apply_layout(Default::default());
s.component_type
.set_property(s.borrow(), "y", Value::Number(*offset_y as f64))
.expect("cannot set y");
@ -180,9 +179,6 @@ impl Component for ErasedComponentBox {
fn layout_info(self: Pin<&Self>) -> sixtyfps_corelib::layout::LayoutInfo {
self.borrow().as_ref().layout_info()
}
fn apply_layout(self: Pin<&Self>, r: sixtyfps_corelib::graphics::Rect) {
self.borrow().as_ref().apply_layout(r)
}
fn get_item_ref<'a>(self: Pin<&'a Self>, index: usize) -> Pin<ItemRef<'a>> {
// We're having difficulties transferring the lifetime to a pinned reference
// to the other ComponentVTable with the same life time. So skip the vtable
@ -789,7 +785,6 @@ fn generate_component<'id>(
let t = ComponentVTable {
visit_children_item,
layout_info,
apply_layout,
get_item_ref,
parent_item,
drop_in_place,
@ -1225,19 +1220,6 @@ extern "C" fn layout_info(component: ComponentRefPin) -> LayoutInfo {
}
}
extern "C" fn apply_layout(component: ComponentRefPin, _r: sixtyfps_corelib::graphics::Rect) {
generativity::make_guard!(guard);
// This is fine since we can only be called with a component that with our vtable which is a ComponentDescription
let instance_ref = unsafe { InstanceRef::from_pin_ref(component, guard) };
for rep_in_comp in &instance_ref.component_type.repeater {
generativity::make_guard!(g);
let rep_in_comp = rep_in_comp.unerase(g);
ensure_repeater_updated(instance_ref, rep_in_comp);
rep_in_comp.offset.apply_pin(instance_ref.instance).compute_layout();
}
}
unsafe extern "C" fn get_item_ref(component: ComponentRefPin, index: usize) -> Pin<ItemRef> {
generativity::make_guard!(guard);
let instance_ref = InstanceRef::from_pin_ref(component, guard);

View file

@ -233,12 +233,11 @@ impl GraphicsWindow {
runtime_window.meta_properties_tracker.as_ref().evaluate_if_dirty(|| {
self.apply_geometry_constraint(component.as_ref().layout_info());
component.as_ref().apply_layout(Default::default());
if let Some((popup, pos)) = &*self.active_popup.borrow() {
if let Some((popup, _)) = &*self.active_popup.borrow() {
let popup = ComponentRc::borrow_pin(popup);
let popup_root = popup.as_ref().get_item_ref(0);
let size = if let Some(window_item) = ItemRef::downcast_pin(popup_root) {
if let Some(window_item) = ItemRef::downcast_pin(popup_root) {
let layout_info = popup.as_ref().layout_info();
let width =
@ -256,11 +255,7 @@ impl GraphicsWindow {
h = layout_info.min_height;
height.set(h);
}
Size::new(h, w) * self.scale_factor()
} else {
Size::default()
};
popup.as_ref().apply_layout(Rect::new(pos.clone(), size));
}
});

View file

@ -845,7 +845,6 @@ impl QtWindow {
if runtime_window.meta_properties_tracker.as_ref().is_dirty() {
runtime_window.meta_properties_tracker.as_ref().evaluate(|| {
self.apply_geometry_constraint(component.as_ref().layout_info());
component.as_ref().apply_layout(Default::default());
});
}
@ -953,7 +952,6 @@ impl PlatformWindow for QtWindow {
fn show(self: Rc<Self>) {
let component_rc = self.self_weak.upgrade().unwrap().component();
let component = ComponentRc::borrow_pin(&component_rc);
component.as_ref().apply_layout(Default::default());
let root_item = component.as_ref().get_item_ref(0);
if let Some(window_item) = ItemRef::downcast_pin(root_item) {
self.apply_window_properties(window_item);

View file

@ -36,14 +36,12 @@ TestCase := Container {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 200});
assert(instance.get_rect1_pos_ok());
```
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 200.)));
assert!(instance.get_rect1_pos_ok());
```
*/

View file

@ -44,14 +44,12 @@ TestCase := MegaContainer {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 200});
assert(instance.get_rect1_pos_ok());
```
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 200.)));
assert!(instance.get_rect1_pos_ok());
```
*/

View file

@ -54,7 +54,6 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_fixed_image_default_image_fit_ok());
assert(instance.get_fixed_image_image_fit_override_ok());
assert(instance.get_image_in_layout_fit_ok());
@ -66,7 +65,6 @@ assert(instance.get_image_with_missing_width_ok());
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_fixed_image_default_image_fit_ok());
assert!(instance.get_fixed_image_image_fit_override_ok());
assert!(instance.get_image_in_layout_fit_ok());
@ -77,7 +75,6 @@ assert!(instance.get_image_with_missing_width_ok());
```js
var instance = new sixtyfps.TestCase();
instance.send_mouse_click(5., 5.);
assert(instance.fixed_image_default_image_fit_ok);
assert(instance.fixed_image_image_fit_override_ok);
assert(instance.image_in_layout_fit_ok);

View file

@ -77,7 +77,6 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
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());
@ -90,7 +89,6 @@ assert(instance.get_c1());
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_v1());
assert!(instance.get_v2());
assert!(instance.get_v3());

View file

@ -37,7 +37,6 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_fake_image_width_ok());
assert(instance.get_fake_image_height_ok());
```
@ -45,7 +44,6 @@ assert(instance.get_fake_image_height_ok());
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_fake_image_width_ok());
assert!(instance.get_fake_image_height_ok());
```

View file

@ -28,7 +28,6 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
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());
@ -37,7 +36,6 @@ assert(instance.get_elem3_ok());
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_elem1_ok());
assert!(instance.get_elem2_ok());
assert!(instance.get_elem3_ok());

View file

@ -42,7 +42,6 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
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());
@ -52,7 +51,6 @@ assert_eq(instance.get_layout_width(), 300);
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_rect1_pos_ok());
assert!(instance.get_rect2_pos_ok());
assert!(instance.get_rect3_pos_ok());

View file

@ -65,7 +65,6 @@ TestCase := Window {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_size_ok());
assert(instance.get_x_ok());
assert(instance.get_y_ok());
@ -74,7 +73,6 @@ assert(instance.get_y_ok());
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_size_ok());
assert!(instance.get_x_ok());
assert!(instance.get_y_ok());

View file

@ -54,7 +54,6 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
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());
@ -63,7 +62,6 @@ assert(instance.get_rect3_pos_ok());
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(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,6 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
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());
```
@ -66,7 +65,6 @@ assert(instance.get_rect2_pos_ok());
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_rect1_pos_ok());
assert!(instance.get_rect2_pos_ok());
```

View file

@ -42,7 +42,6 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
TestCase::apply_layout({&TestCase::static_vtable, const_cast<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
assert(instance.get_fake_image_width_ok());
assert(instance.get_fake_image_height_ok());
```
@ -50,7 +49,6 @@ assert(instance.get_fake_image_height_ok());
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_fake_image_width_ok());
assert!(instance.get_fake_image_height_ok());
```

View file

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

View file

@ -69,7 +69,6 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
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());
@ -81,7 +80,6 @@ assert(instance.get_pink_rect_ok());
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_blue_rect_ok());
assert!(instance.get_red_rect_ok());
assert!(instance.get_green_rect_ok());

View file

@ -24,13 +24,13 @@ HelloWorld := Window {
```cpp
auto handle = HelloWorld::create();
const HelloWorld &instance = *handle;
HelloWorld::apply_layout({&HelloWorld::static_vtable, const_cast<HelloWorld*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300});
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
```
```rust
let instance = HelloWorld::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
```
*/

View file

@ -132,7 +132,6 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
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());
@ -145,7 +144,6 @@ assert(instance.get_rect_black2_ok());
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(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,6 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
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());
@ -57,7 +56,6 @@ assert(instance.get_rect6_pos_ok());
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(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,6 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
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());
@ -65,7 +64,6 @@ assert(instance.get_rect4_pos_ok());
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(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,6 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
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());
```
@ -52,7 +51,6 @@ assert(instance.get_rect2_pos_ok());
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_rect1_pos_ok());
assert!(instance.get_rect2_pos_ok());
```

View file

@ -85,7 +85,6 @@ TestCase := Rectangle {
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
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());
@ -96,7 +95,6 @@ assert(instance.get_test5());
```rust
let instance = TestCase::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_test1());
assert!(instance.get_test2());
assert!(instance.get_test3());