Repository: slint-ui/slint (Rust)

Issue:
Internal error: compute_dirty_regions panicking!
### Bug Description

Some builds of windows are failing after the latest update to slint `1.13.1`. This is caused by uses of a custom implementation of `SkiaRenderer`'s `render` method.

Here is the log 
```
thread 'main' panicked at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/partial_renderer.rs:655:21:
internal error: entered unreachable code: compute_dirty_regions should have already computed the geometry
stack backtrace:
   0: __rustc::rust_begin_unwind
             at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library/std/src/panicking.rs:697:5
   1: core::panicking::panic_fmt
             at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library/core/src/panicking.rs:75:14
   2: <i_slint_core::partial_renderer::PartialRenderer<T> as i_slint_core::item_rendering::ItemRenderer>::filter_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/partial_renderer.rs:655:21
   3: i_slint_core::item_rendering::render_item_children::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:155:53
   4: i_slint_core::item_tree::<impl i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitor for T>::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1100:9
   5: i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorVTable::new::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1070:1
   6: i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorTO::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1070:1
   7: i_slint_core::item_tree::visit_item_tree::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1170:25
   8: i_slint_core::item_tree::visit_item_tree
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1193:45
   9: <young_shell::slint_generatedWorkspaces::InnerTopBar as i_slint_core::item_tree::ItemTree_vtable_mod::ItemTree>::visit_children_item
             at ./target/debug/build/young-shell-202e858554dd2278/out/app-window.rs:58354:21
  10: young_shell::slint_generatedWorkspaces::_::VT::visit_children_item
             at ./target/debug/build/young-shell-202e858554dd2278/out/app-window.rs:58341:10
  11: i_slint_core::item_tree::ItemTree_vtable_mod::ItemTreeTO::visit_children_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:45:1
  12: i_slint_core::item_rendering::render_item_children
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:183:41
  13: i_slint_core::item_rendering::render_item_children::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:177:17
  14: i_slint_core::item_tree::<impl i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitor for T>::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1100:9
  15: i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorVTable::new::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1070:1
  16: i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorTO::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1070:1
  17: i_slint_core::item_tree::visit_item_tree::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1170:25
  18: i_slint_core::item_tree::visit_item_tree
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1193:45
  19: <young_shell::slint_generatedWorkspaces::InnerTopBar as i_slint_core::item_tree::ItemTree_vtable_mod::ItemTree>::visit_children_item
             at ./target/debug/build/young-shell-202e858554dd2278/out/app-window.rs:58354:21
  20: young_shell::slint_generatedWorkspaces::_::VT::visit_children_item
             at ./target/debug/build/young-shell-202e858554dd2278/out/app-window.rs:58341:10
  21: i_slint_core::item_tree::ItemTree_vtable_mod::ItemTreeTO::visit_children_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:45:1
  22: i_slint_core::item_rendering::render_item_children
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:183:41
  23: i_slint_core::item_rendering::render_item_children::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:177:17
  24: i_slint_core::item_tree::<impl i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitor for T>::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1100:9
  25: i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorVTable::new::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1070:1
  26: i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorTO::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1070:1
  27: i_slint_core::item_tree::visit_item_tree::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1170:25
  28: i_slint_core::item_tree::visit_item_tree
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1193:45
  29: <young_shell::slint_generatedWorkspaces::InnerTopBar as i_slint_core::item_tree::ItemTree_vtable_mod::ItemTree>::visit_children_item
             at ./target/debug/build/young-shell-202e858554dd2278/out/app-window.rs:58354:21
  30: young_shell::slint_generatedWorkspaces::_::VT::visit_children_item
             at ./target/debug/build/young-shell-202e858554dd2278/out/app-window.rs:58341:10
  31: i_slint_core::item_tree::ItemTree_vtable_mod::ItemTreeTO::visit_children_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:45:1
  32: i_slint_core::item_rendering::render_item_children
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:183:41
  33: i_slint_core::item_rendering::render_item_children::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:177:17
  34: i_slint_core::item_tree::<impl i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitor for T>::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1100:9
  35: i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorVTable::new::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1070:1
  36: i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorTO::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1070:1
  37: i_slint_core::item_tree::visit_item_tree::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1170:25
  38: i_slint_core::item_tree::visit_item_tree
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1193:45
  39: <young_shell::slint_generatedWorkspaces::InnerTopBar as i_slint_core::item_tree::ItemTree_vtable_mod::ItemTree>::visit_children_item
             at ./target/debug/build/young-shell-202e858554dd2278/out/app-window.rs:58354:21
  40: young_shell::slint_generatedWorkspaces::_::VT::visit_children_item
             at ./target/debug/build/young-shell-202e858554dd2278/out/app-window.rs:58341:10
  41: i_slint_core::item_tree::ItemTree_vtable_mod::ItemTreeTO::visit_children_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:45:1
  42: i_slint_core::item_rendering::render_item_children
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:183:41
  43: i_slint_core::item_rendering::render_item_children::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:177:17
  44: i_slint_core::item_tree::<impl i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitor for T>::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1100:9
  45: i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorVTable::new::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1070:1
  46: i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorTO::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1070:1
  47: i_slint_core::item_tree::visit_item_tree::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1170:25
  48: i_slint_core::item_tree::visit_item_tree
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1193:45
  49: <young_shell::slint_generatedWorkspaces::InnerTopBar as i_slint_core::item_tree::ItemTree_vtable_mod::ItemTree>::visit_children_item
             at ./target/debug/build/young-shell-202e858554dd2278/out/app-window.rs:58354:21
  50: young_shell::slint_generatedWorkspaces::_::VT::visit_children_item
             at ./target/debug/build/young-shell-202e858554dd2278/out/app-window.rs:58341:10
  51: i_slint_core::item_tree::ItemTree_vtable_mod::ItemTreeTO::visit_children_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:45:1
  52: i_slint_core::item_rendering::render_item_children
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:183:41
  53: i_slint_core::item_rendering::render_item_children::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:177:17
  54: i_slint_core::item_tree::<impl i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitor for T>::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1100:9
  55: i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorVTable::new::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1070:1
  56: i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorTO::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1070:1
  57: i_slint_core::item_tree::visit_item_tree::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1170:25
  58: i_slint_core::item_tree::visit_item_tree
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1193:45
  59: <young_shell::slint_generatedWorkspaces::InnerTopBar as i_slint_core::item_tree::ItemTree_vtable_mod::ItemTree>::visit_children_item
             at ./target/debug/build/young-shell-202e858554dd2278/out/app-window.rs:58354:21
  60: young_shell::slint_generatedWorkspaces::_::VT::visit_children_item
             at ./target/debug/build/young-shell-202e858554dd2278/out/app-window.rs:58341:10
  61: i_slint_core::item_tree::ItemTree_vtable_mod::ItemTreeTO::visit_children_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:45:1
  62: i_slint_core::item_rendering::render_item_children
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:183:41
  63: i_slint_core::item_rendering::render_item_children::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:177:17
  64: i_slint_core::item_tree::<impl i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitor for T>::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1100:9
  65: i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorVTable::new::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1070:1
  66: i_slint_core::item_tree::ItemVisitor_vtable_mod::ItemVisitorTO::visit_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1070:1
  67: i_slint_core::item_tree::visit_item_tree::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1170:25
  68: i_slint_core::item_tree::visit_item_tree
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:1184:9
  69: <young_shell::slint_generatedWorkspaces::InnerTopBar as i_slint_core::item_tree::ItemTree_vtable_mod::ItemTree>::visit_children_item
             at ./target/debug/build/young-shell-202e858554dd2278/out/app-window.rs:58354:21
  70: young_shell::slint_generatedWorkspaces::_::VT::visit_children_item
             at ./target/debug/build/young-shell-202e858554dd2278/out/app-window.rs:58341:10
  71: i_slint_core::item_tree::ItemTree_vtable_mod::ItemTreeTO::visit_children_item
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_tree.rs:45:1
  72: i_slint_core::item_rendering::render_item_children
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:183:41
  73: i_slint_core::item_rendering::render_component_items
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/item_rendering.rs:201:5
  74: i_slint_renderer_skia::SkiaRenderer::render_components_to_canvas
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/renderers/skia/lib.rs:758:17
  75: i_slint_renderer_skia::SkiaRenderer::render_to_canvas::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/renderers/skia/lib.rs:603:22
  76: i_slint_core::window::WindowInner::draw_contents::{{closure}}
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/window.rs:1107:21
  77: i_slint_core::properties::_::<impl i_slint_core::properties::CURRENT_BINDING>::set
             at /home/ramayen/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/scoped-tls-hkt-0.1.5/src/lib.rs:258:21
  78: i_slint_core::properties::PropertyTracker<DirtyHandler>::evaluate_as_dependency_root
             at /home/ramayen/.cargo/git/checkouts/slint-774a37e469fae6bf/03059bb/internal/core/properties.rs:1483:33
```

### Reproducible Code (if applicable)

```slint

```

### Environment Details

- Slint Version: 13.1.1
- Platform/OS: 6.16.10-artix1-1 
- Programming Language: Rust
- Backend/Renderer: Skia


### Product Impact

I am building a backend for slint to create desktop widgets with it, by providing a `Platform` implementation for wayland's `wlr_layer_shell` protocols and related protocols.
This breakage just came up when I was about to publish first stable release for my crate, so it would be great to get fixed, because almost all the tests and builds are failing as a result of it


Discussion:

Patch:
diff --git a/internal/core/partial_renderer.rs b/internal/core/partial_renderer.rs
index 1d1e345f9ef..14adf30812a 100644
--- a/internal/core/partial_renderer.rs
+++ b/internal/core/partial_renderer.rs
@@ -581,7 +581,6 @@ impl<'a, T: ItemRenderer + ItemRendererFeatures> PartialRenderer<'a, T> {
         cache: &RefCell<PartialRendererCache>,
         rendering_data: &CachedRenderingData,
         item_rc: &ItemRc,
-        window_adapter: &Rc<dyn WindowAdapter>,
         render_fn: impl FnOnce(),
     ) {
         let mut cache = cache.borrow_mut();
@@ -592,18 +591,10 @@ impl<'a, T: ItemRenderer + ItemRendererFeatures> PartialRenderer<'a, T> {
                 .as_ref()
                 .evaluate(render_fn);
         } else {
-            let mut cache_entry = PartialRenderingCachedData::new(
-                CachedItemBoundingBoxAndTransform::new::<T>(item_rc, window_adapter),
-            );
-            cache_entry
-                .tracker
-                .get_or_insert_with(|| Box::pin(PropertyTracker::default()))
-                .as_ref()
-                .evaluate(render_fn);
-            rendering_data.cache_index.set(cache.insert(cache_entry));
-            rendering_data.cache_generation.set(cache.generation());
-
-            unreachable!("compute_dirty_regions should have already computed the geometry")
+            // This item was created between the computation of the dirty region and the actual rendering.
+            // Register a dependency to the geometry since this wasn't done before
+            item_rc.geometry();
+            render_fn();
         }
     }
 
@@ -617,7 +608,7 @@ macro_rules! forward_rendering_call {
     (fn $fn:ident($Ty:ty) $(-> $Ret:ty)?) => {
         fn $fn(&mut self, obj: Pin<&$Ty>, item_rc: &ItemRc, size: LogicalSize) $(-> $Ret)? {
             let mut ret = None;
-            Self::do_rendering(&self.cache, &obj.cached_rendering_data, item_rc, &self.window_adapter, || {
+            Self::do_rendering(&self.cache, &obj.cached_rendering_data, item_rc, || {
                 ret = Some(self.actual_renderer.$fn(obj, item_rc, size));
             });
             ret.unwrap_or_default()
@@ -629,7 +620,7 @@ macro_rules! forward_rendering_call2 {
     (fn $fn:ident($Ty:ty) $(-> $Ret:ty)?) => {
         fn $fn(&mut self, obj: Pin<&$Ty>, item_rc: &ItemRc, size: LogicalSize, cache: &CachedRenderingData) $(-> $Ret)? {
             let mut ret = None;
-            Self::do_rendering(&self.cache, &cache, item_rc, &self.window_adapter, || {
+            Self::do_rendering(&self.cache, &cache, item_rc, || {
                 ret = Some(self.actual_renderer.$fn(obj, item_rc, size, &cache));
             });
             ret.unwrap_or_default()
@@ -641,7 +632,7 @@ impl<T: ItemRenderer + ItemRendererFeatures> ItemRenderer for PartialRenderer<'_
     fn filter_item(
         &mut self,
         item_rc: &ItemRc,
-        _window_adapter: &Rc<dyn WindowAdapter>,
+        window_adapter: &Rc<dyn WindowAdapter>,
     ) -> (bool, LogicalRect) {
         let item = item_rc.borrow();
 
@@ -652,7 +643,10 @@ impl<T: ItemRenderer + ItemRendererFeatures> ItemRenderer for PartialRenderer<'_
         let mut cache = self.cache.borrow_mut();
         let item_bounding_rect = match rendering_data.get_entry(&mut cache) {
             Some(PartialRenderingCachedData { data, tracker: _ }) => *data.bounding_rect(),
-            None => unreachable!("compute_dirty_regions should have already computed the geometry"),
+            None => {
+                // This item was created between the computation of the dirty region and the actual rendering.
+                item_rc.bounding_rect(&item_geometry, window_adapter)
+            }
         };
 
         let clipped_geom = self.get_current_clip().intersection(&item_bounding_rect);


Test patch:
diff --git a/api/rs/slint/tests/partial_renderer.rs b/api/rs/slint/tests/partial_renderer.rs
index fe9df14d576..eb53276143e 100644
--- a/api/rs/slint/tests/partial_renderer.rs
+++ b/api/rs/slint/tests/partial_renderer.rs
@@ -720,3 +720,80 @@ fn nowrap_text_change_doesnt_change_height() {
     }));
     assert!(!window.draw_if_needed(|_| { unreachable!() }));
 }
+
+#[test]
+fn create_item_tree_during_rendering() {
+    // This test has a `init` callback which will cause item tree to be changed during rendeiring,
+    // between the compute dirty region and the actual rendering.
+    slint::slint! {
+        export component Ui inherits Window {
+            in property <bool> cond1: false;
+            property <bool> cond2: false;
+            property <bool> cond3: false;
+
+            in property <length> foo: 5px;
+
+            if cond3: Rectangle {
+                x: 12px;
+                y: foo;
+                width: 10px;
+                height: 10px;
+                background: yellow;
+            }
+            if cond2: Rectangle {
+                x: 10px;
+                y: 10px;
+                width: 10px;
+                height: 10px;
+                background: red;
+                init => { cond3=true; }
+            }
+            if cond1: Rectangle {
+                x: 10px;
+                y: 15px;
+                width: 10px;
+                height: 10px;
+                background: blue;
+                init => { cond2=true; }
+            }
+            if cond2: Rectangle {
+                x: 12px;
+                y: 10px + foo;
+                width: 10px;
+                height: 10px;
+                background: green;
+            }
+        }
+    }
+
+    slint::platform::set_platform(Box::new(TestPlatform)).ok();
+    let ui = Ui::new().unwrap();
+    let window = WINDOW.with(|x| x.clone());
+    window.set_size(slint::PhysicalSize::new(180, 260));
+    ui.show().unwrap();
+    assert!(window.draw_if_needed(|renderer| {
+        do_test_render_region(renderer, 0, 0, 180, 260);
+    }));
+    assert!(!window.draw_if_needed(|_| { unreachable!() }));
+    ui.set_cond1(true);
+
+    assert!(window.draw_if_needed(|renderer| {
+        do_test_render_region(renderer, 10, 15, 22, 25);
+    }));
+    // FIXME: in this case, there is nothing done to trigger any redraw. Ideally this call shouldn't be necessary.
+    assert!(!window.draw_if_needed(|_| ()));
+    // So therefore force a redraw
+
+    ui.set_foo(4.0);
+
+    assert!(window.draw_if_needed(|renderer| {
+        do_test_render_region(renderer, 10, 4, 22, 25);
+    }));
+
+    assert!(!window.draw_if_needed(|_| { unreachable!() }));
+
+    ui.set_foo(3.0);
+    assert!(window.draw_if_needed(|renderer| {
+        do_test_render_region(renderer, 12, 3, 22, 24);
+    }));
+}