From b34a34cea06240da55fea853794e06a8098d231e Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 18 Feb 2021 09:40:12 +0100 Subject: [PATCH] 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 --- api/sixtyfps-cpp/include/sixtyfps.h | 4 ++ tests/cases/layout/vertical_if.60 | 64 +++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 9 deletions(-) diff --git a/api/sixtyfps-cpp/include/sixtyfps.h b/api/sixtyfps-cpp/include/sixtyfps.h index fd9aeab2e..090423dc8 100644 --- a/api/sixtyfps-cpp/include/sixtyfps.h +++ b/api/sixtyfps-cpp/include/sixtyfps.h @@ -552,6 +552,10 @@ public: } else { 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(); } } diff --git a/tests/cases/layout/vertical_if.60 b/tests/cases/layout/vertical_if.60 index 8703775a0..8658df792 100644 --- a/tests/cases/layout/vertical_if.60 +++ b/tests/cases/layout/vertical_if.60 @@ -18,7 +18,14 @@ export TestCase := Window { padding: 0px; spacing: 0px; - Rectangle { background: orange; } + Rectangle { + background: orange; + TouchArea { + clicked => { + root.value = 0; + } + } + } if (true) : Rectangle { background: blue; @@ -49,14 +56,15 @@ export TestCase := Window { background: pink; TouchArea { 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 @@ -64,7 +72,7 @@ auto handle = TestCase::create(); const TestCase &instance = *handle; 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.); assert_eq(instance.get_value(), 2); @@ -73,7 +81,20 @@ sixtyfps::testing::send_mouse_click(&instance, 5., 30.); assert_eq(instance.get_value(), 1); 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(); 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.); assert_eq!(instance.get_value(), 2); @@ -90,7 +111,20 @@ sixtyfps::testing::send_mouse_click(&instance, 5., 30.); assert_eq!(instance.get_value(), 1); 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(); instance.send_mouse_click(5., 5.); -assert.equal(instance.value, -10); +assert.equal(instance.value, 0); instance.send_mouse_click(5., 52.); assert.equal(instance.value, 2); @@ -107,7 +141,19 @@ instance.send_mouse_click(5., 30.); assert.equal(instance.value, 1); 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); ``` */