git.lucas.co / cce-cloud
cloud storage client
git clone https://git.lucas.co/cce-cloud.git

commitf86c1536ae7c327887fcd4b0268c27f97dd97dc4
parente1bae3d595
authorLucas Galante <lsgalante12@gmail.com>
date2026-10-07 15:29
refactor: register widgets by reference (UiContext::register_host)

register_widget(id, ptr) took a raw pointer in a safe function; cce-ui is
making it an unsafe fn now that every app registers through
register_host(&mut w), which takes the widget's own id and a live borrow.
Registration loops that existed only to hand the registry raw pointers
(and the unsafe blocks and self_ptr casts around them) are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

 src/main.rs | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index ea51b22..b7dac6a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2913,7 +2913,7 @@ impl PointerHandler for AppState {
                                     local_y: event.position.1 as f32,
                                 };
                                 let root = jl.id();
-                                st.ui_context.register_widget(root, jl.as_ptr_mut());
+                                st.ui_context.register_host(jl);
                                 if st.ui_context.propagate_event(&mv, root) {
                                     changed = true;
                                 }
@@ -2970,7 +2970,7 @@ impl PointerHandler for AppState {
                                         local_y: event.position.1 as f32,
                                     };
                                     let root = jl.id();
-                                    st.ui_context.register_widget(root, jl.as_ptr_mut());
+                                    st.ui_context.register_host(jl);
                                     if st.ui_context.propagate_event(&ev, root) {
                                         changed = true;
                                     }
@@ -3011,7 +3011,7 @@ impl PointerHandler for AppState {
                                         local_y: event.position.1 as f32,
                                     };
                                     let root = st.fuzzel.id();
-                                    st.ui_context.register_widget(root, st.fuzzel.as_ptr_mut());
+                                    st.ui_context.register_host(&mut st.fuzzel);
                                     st.ui_context.propagate_event(&ev, root)
                                 };
                                 if changed {
@@ -3080,7 +3080,7 @@ impl PointerHandler for AppState {
                                         local_y: event.position.1 as f32,
                                     };
                                     let root = jl.id();
-                                    st.ui_context.register_widget(root, jl.as_ptr_mut());
+                                    st.ui_context.register_host(jl);
                                     if st.ui_context.propagate_event(&ev, root) {
                                         changed = true;
                                     }
@@ -3185,7 +3185,7 @@ impl PointerHandler for AppState {
                             if let Some(jl) = &mut st.json_layout {
                                 let ev = cce_ui::widget::Event::MouseWheel { delta, x: cx, y: cy, local_x: cx, local_y: cy };
                                 let root = jl.id();
-                                st.ui_context.register_widget(root, jl.as_ptr_mut());
+                                st.ui_context.register_host(jl);
                                 if st.ui_context.propagate_event(&ev, root) {
                                     changed = true;
                                 }
@@ -3529,7 +3529,7 @@ impl AppState {
                 if let Some(jl) = &mut st.json_layout {
                     let kev = cce_ui::widget::Event::KeyInput(key_event.clone());
                     let root = jl.id();
-                    st.ui_context.register_widget(root, jl.as_ptr_mut());
+                    st.ui_context.register_host(jl);
                     if st.ui_context.propagate_event(&kev, root) {
                         widget_handled = true;
                         st.upload_vertices();
@@ -5095,7 +5095,7 @@ mod tests {
         // button lit up on the first stationary wiggle).
         let (x1, y1) = (layout.widgets[1].x, layout.widgets[1].y);
         let root = layout.id();
-        ctx.register_widget(root, layout.as_ptr_mut());
+        ctx.register_host(&mut layout);
         let mv = |x: f32, y: f32| cce_ui::widget::Event::PointerMove { x, y, local_x: x, local_y: y };
         ctx.propagate_event(&mv(x1 + 10.0, y1 + 5.0), root);
         ctx.propagate_event(&mv(x1 + 12.0, y1 + 5.0), root);