text editor
git clone https://git.lucas.co/cce-text-editor.git
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 | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index e3815e1..15bd41c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -355,11 +355,8 @@ impl Application for TextEditorApp {
// Widget text comes from the paint walk (Adapted::paint_self serves per-widget fonts).
if !self.widgets_registered {
self.widgets_registered = true;
- let self_ptr = self as *mut Self;
- unsafe {
- self.ui_context.register_widget(self.menu_dropdown.base().id(), (*self_ptr).menu_dropdown.as_ptr_mut());
- self.ui_context.register_widget(self.editor.base().id(), (*self_ptr).editor.as_ptr_mut());
- }
+ self.ui_context.register_host(&mut self.menu_dropdown);
+ self.ui_context.register_host(&mut self.editor);
}
if self.initial_focus {