git.lucas.co / cce-ui
GPU-accelerated UI toolkit (Vulkan)
git clone https://git.lucas.co/cce-ui.git

commit577b17e7e804ccb34d1457cc3f75490ce92c121c
parentcd78866cfa
authorLucas Galante <[email protected]>
date2026-06-26 14:34
Register and link Paginator children in the layout phase to prevent hierarchy reset drag interference

 src/widget/container/backplate.rs | 26 ++++++++++++++++++++++++++
 src/widget/container/paginator.rs | 17 +++++++++++++++++
 2 files changed, 43 insertions(+)

diff --git a/src/widget/container/backplate.rs b/src/widget/container/backplate.rs
index 9ef6943..47c5321 100644
--- a/src/widget/container/backplate.rs
+++ b/src/widget/container/backplate.rs
@@ -373,4 +373,30 @@ mod tests {
         win.clear_children(&mut ctx);
         assert_eq!(win.children(&ctx).len(), 0);
     }
+
+    struct TestRenderTarget;
+    impl crate::layout::RenderTarget for TestRenderTarget {
+        fn rect(&mut self, _color: [f32; 4], _x: f32, _y: f32, _w: f32, _h: f32) {}
+        fn text(&mut self, _content: &str, _x: f32, _y: f32, _size: f32, _color: [f32; 4]) {}
+    }
+
+    #[test]
+    fn test_paginator_blocks_backplate_drag() {
+        let mut ctx = UiContext::new();
+        let mut win = Backplate::new(0.0, 0.0, 800.0, 600.0);
+        let mut paginator = Paginator::new(vec!["Page 1".to_string(), "Page 2".to_string()]);
+        
+        win.add_child(paginator.as_ptr_mut(), &mut ctx);
+        
+        // Let's set the rect
+        crate::layout::render_widget(&mut TestRenderTarget, &mut paginator, 0.0, 0.0, 54.0, 600.0, &mut ctx);
+        
+        // Let's tick to register children
+        ctx.tick(0.016);
+        ctx.clear_dirty(); // This triggers rebuild_spatial_grid()
+        
+        // Now, click in the sidebar at x=10, y=20
+        let is_movable = ctx.is_movable_backplate_at(10.0, 20.0);
+        assert!(!is_movable, "Clicking the sidebar should block backplate drag!");
+    }
 }
diff --git a/src/widget/container/paginator.rs b/src/widget/container/paginator.rs
index 2622fb3..b8d1d22 100644
--- a/src/widget/container/paginator.rs
+++ b/src/widget/container/paginator.rs
@@ -201,6 +201,23 @@ impl Element for Paginator {
         true
     }
 
+    fn layout(&mut self, origin: Point, constraints: LayoutConstraints, ctx: &mut UiContext) {
+        let size = self.measure(constraints, ctx);
+        self.set_rect(origin.x, origin.y, size.width, size.height);
+
+        let parent_id = self.base.id();
+
+        let menu_ptr = &mut self.sidebar_menu as *mut ButtonStrip;
+        ctx.register_widget(self.sidebar_menu.base.id(), menu_ptr);
+        ctx.link_ids(parent_id, self.sidebar_menu.base.id());
+
+        for plate in &mut self.pages {
+            let plate_ptr = plate as *mut Page;
+            ctx.register_widget(plate.base.base.id(), plate_ptr);
+            ctx.link_ids(parent_id, plate.base.base.id());
+        }
+    }
+
     fn set_rect(&mut self, x: f32, y: f32, w: f32, h: f32) {
         self.base.x = x;
         self.base.y = y;