Avoid self-references in the created layout properties

Fixes #140
This commit is contained in:
Olivier Goffart 2021-01-28 15:06:19 +01:00
parent 52d750999b
commit 8e8c6ab690
2 changed files with 40 additions and 0 deletions

View file

@ -247,6 +247,10 @@ fn init_fake_property(
&& !grid_layout_element.borrow().bindings.contains_key(name) && !grid_layout_element.borrow().bindings.contains_key(name)
{ {
if let Some(e) = lazy_default() { if let Some(e) = lazy_default() {
if e.name == name && Rc::ptr_eq(&e.element.upgrade().unwrap(), grid_layout_element) {
// Don't reference self
return;
}
grid_layout_element grid_layout_element
.borrow_mut() .borrow_mut()
.bindings .bindings

View file

@ -0,0 +1,36 @@
/* LICENSE BEGIN
This file is part of the SixtyFPS Project -- https://sixtyfps.io
Copyright (c) 2020 Olivier Goffart <olivier.goffart@sixtyfps.io>
Copyright (c) 2020 Simon Hausmann <simon.hausmann@sixtyfps.io>
SPDX-License-Identifier: GPL-3.0-only
This file is also available under commercial licensing terms.
Please contact info@sixtyfps.io for more information.
LICENSE END */
HelloWorld := Window {
HorizontalLayout {
VerticalLayout {
HorizontalLayout {
height: 50%;
Rectangle {}
}
}
}
}
/*
```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});
```
```rust
let instance = HelloWorld::new();
sixtyfps::testing::apply_layout(&instance, sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
```
*/