mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 14:21:16 +00:00
C++ Make sure that the layout is properly updated when the model of a for
or if
changes
The problem is that the backend is using the `meta_property_listener` to know if the layout must be updated, but the C++ code would not register a dependency NOTE about the test: The test doesn't really test that it works because the test backend don't have a meta_property_listener and apply the layout inconditionally in sixtyfps_send_mouse_click
This commit is contained in:
parent
13a2138022
commit
b34a34cea0
2 changed files with 59 additions and 9 deletions
|
@ -552,6 +552,10 @@ public:
|
||||||
} else {
|
} else {
|
||||||
inner->data.clear();
|
inner->data.clear();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// just do a get() on the model to register dependencies so that, for example, the
|
||||||
|
// layout property tracker becomes dirty.
|
||||||
|
model.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,14 @@ export TestCase := Window {
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
spacing: 0px;
|
spacing: 0px;
|
||||||
|
|
||||||
Rectangle { background: orange; }
|
Rectangle {
|
||||||
|
background: orange;
|
||||||
|
TouchArea {
|
||||||
|
clicked => {
|
||||||
|
root.value = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (true) : Rectangle {
|
if (true) : Rectangle {
|
||||||
background: blue;
|
background: blue;
|
||||||
|
@ -49,14 +56,15 @@ export TestCase := Window {
|
||||||
background: pink;
|
background: pink;
|
||||||
TouchArea {
|
TouchArea {
|
||||||
clicked => {
|
clicked => {
|
||||||
root.value = 2;
|
root.value = 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// There should be 4 rectangle: so 100 devided by 5 is 25.
|
// There should be 4 rectangle: so 100 devided by 4 is 25.
|
||||||
|
// when cond is false, there is 3, so 33.3 pixel per rectangle
|
||||||
|
|
||||||
/*
|
/*
|
||||||
```cpp
|
```cpp
|
||||||
|
@ -64,7 +72,7 @@ auto handle = TestCase::create();
|
||||||
const TestCase &instance = *handle;
|
const TestCase &instance = *handle;
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
||||||
assert_eq(instance.get_value(), -10);
|
assert_eq(instance.get_value(), 0);
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&instance, 5., 52.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 52.);
|
||||||
assert_eq(instance.get_value(), 2);
|
assert_eq(instance.get_value(), 2);
|
||||||
|
@ -73,7 +81,20 @@ sixtyfps::testing::send_mouse_click(&instance, 5., 30.);
|
||||||
assert_eq(instance.get_value(), 1);
|
assert_eq(instance.get_value(), 1);
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&instance, 5., 80.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 80.);
|
||||||
assert_eq(instance.get_value(), 2); // did not change
|
assert_eq(instance.get_value(), 4);
|
||||||
|
|
||||||
|
instance.set_cond(false);
|
||||||
|
sixtyfps::testing::send_mouse_click(&instance, 5., 35.);
|
||||||
|
assert_eq(instance.get_value(), 1);
|
||||||
|
sixtyfps::testing::send_mouse_click(&instance, 5., 30.);
|
||||||
|
assert_eq(instance.get_value(), 0);
|
||||||
|
sixtyfps::testing::send_mouse_click(&instance, 5., 67.);
|
||||||
|
assert_eq(instance.get_value(), 4);
|
||||||
|
|
||||||
|
instance.set_cond(true);
|
||||||
|
sixtyfps::testing::send_mouse_click(&instance, 5., 70.);
|
||||||
|
assert_eq(instance.get_value(), 2);
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,7 +102,7 @@ assert_eq(instance.get_value(), 2); // did not change
|
||||||
let instance = TestCase::new();
|
let instance = TestCase::new();
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 5.);
|
||||||
assert_eq!(instance.get_value(), -10);
|
assert_eq!(instance.get_value(), 0);
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&instance, 5., 52.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 52.);
|
||||||
assert_eq!(instance.get_value(), 2);
|
assert_eq!(instance.get_value(), 2);
|
||||||
|
@ -90,7 +111,20 @@ sixtyfps::testing::send_mouse_click(&instance, 5., 30.);
|
||||||
assert_eq!(instance.get_value(), 1);
|
assert_eq!(instance.get_value(), 1);
|
||||||
|
|
||||||
sixtyfps::testing::send_mouse_click(&instance, 5., 80.);
|
sixtyfps::testing::send_mouse_click(&instance, 5., 80.);
|
||||||
assert_eq!(instance.get_value(), 2); // did not change
|
assert_eq!(instance.get_value(), 4);
|
||||||
|
|
||||||
|
instance.set_cond(false);
|
||||||
|
sixtyfps::testing::send_mouse_click(&instance, 5., 35.);
|
||||||
|
assert_eq!(instance.get_value(), 1);
|
||||||
|
sixtyfps::testing::send_mouse_click(&instance, 5., 30.);
|
||||||
|
assert_eq!(instance.get_value(), 0);
|
||||||
|
sixtyfps::testing::send_mouse_click(&instance, 5., 67.);
|
||||||
|
assert_eq!(instance.get_value(), 4);
|
||||||
|
|
||||||
|
instance.set_cond(true);
|
||||||
|
sixtyfps::testing::send_mouse_click(&instance, 5., 70.);
|
||||||
|
assert_eq!(instance.get_value(), 2);
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -98,7 +132,7 @@ assert_eq!(instance.get_value(), 2); // did not change
|
||||||
var instance = new sixtyfps.TestCase();
|
var instance = new sixtyfps.TestCase();
|
||||||
|
|
||||||
instance.send_mouse_click(5., 5.);
|
instance.send_mouse_click(5., 5.);
|
||||||
assert.equal(instance.value, -10);
|
assert.equal(instance.value, 0);
|
||||||
|
|
||||||
instance.send_mouse_click(5., 52.);
|
instance.send_mouse_click(5., 52.);
|
||||||
assert.equal(instance.value, 2);
|
assert.equal(instance.value, 2);
|
||||||
|
@ -107,7 +141,19 @@ instance.send_mouse_click(5., 30.);
|
||||||
assert.equal(instance.value, 1);
|
assert.equal(instance.value, 1);
|
||||||
|
|
||||||
instance.send_mouse_click(5., 80);
|
instance.send_mouse_click(5., 80);
|
||||||
assert.equal(instance.value, 2); // did not change
|
assert.equal(instance.value, 4);
|
||||||
|
|
||||||
|
instance.cond = false;
|
||||||
|
instance.send_mouse_click(5., 35.);
|
||||||
|
assert.equal(instance.value, 1);
|
||||||
|
instance.send_mouse_click(5., 30.);
|
||||||
|
assert.equal(instance.value, 0);
|
||||||
|
instance.send_mouse_click(5., 67.);
|
||||||
|
assert.equal(instance.value, 4);
|
||||||
|
|
||||||
|
instance.cond = true;
|
||||||
|
instance.send_mouse_click(5., 70.);
|
||||||
|
assert.equal(instance.value, 2);
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue