git.lucas.co / cce-text-editor
text editor
git clone https://git.lucas.co/cce-text-editor.git

commitbf4047812d743f1348c5a7200631b8e6988022a0
parent3fe436e6ed
authorLucas Galante <lsgalante12@gmail.com>
date2026-10-07 22:08
refactor: hold widgets in Owned boxes (cce-ui Owned<W>)

The UiContext registry keeps raw pointers to registered widgets, and a
widget that moved while registered (its Vec reallocating, its struct
returned by value) left one pointing at the old address. Each widget
field is now an Owned<Adapted<..>> — a heap box whose allocation, not the
widget, carries the liveness token the registry watches — so the
registered address never moves and is dropped from the registry when the
box is freed. Field access is unchanged through Deref; construction
sites wrap in Owned::new.

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

 src/main.rs | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 15bd41c..77e2fb4 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,5 @@
 use wayland_client::QueueHandle;
+use cce_ui::widget::Owned;
 use cce_ui::cosmic_text::FontSystem;
 use cce_ui::engine::{Application, EngineState, LogicalPosition, LogicalSize, WindowSettings};
 use cce_ui::widget::{
@@ -45,10 +46,10 @@ struct TextEditorApp {
     keys: EditorKeys,
 
     // File menu dropdown
-    menu_dropdown: cce_ui::widget::Adapted<Dropdown>,
+    menu_dropdown: Owned<cce_ui::widget::Adapted<Dropdown>>,
     
     // Editor TextBox
-    editor: cce_ui::widget::Adapted<TextBox>,
+    editor: Owned<cce_ui::widget::Adapted<TextBox>>,
     
     // File state
     current_file_path: Option<std::path::PathBuf>,
@@ -250,8 +251,8 @@ impl Application for TextEditorApp {
 
         Self {
             keys: EditorKeys::load(),
-            menu_dropdown,
-            editor,
+            menu_dropdown: Owned::new(menu_dropdown),
+            editor: Owned::new(editor),
             current_file_path,
             width: 800,
             height: 600,