git.lucas.co / cce-designer
graphic design tool
git clone https://git.lucas.co/cce-designer.git

commit2787f9b39c25333a6ae9f7737749f3f8d578d64f
parent6b9ee925f4
authorLucas Galante <[email protected]>
date2026-06-22 12:26
refactor: use cce-ui window as root base UI object

 src/app.rs    |  8 ++++++++
 src/render.rs | 66 +++++++++++++++++++++++++++++++++++++++++++++++------------
 2 files changed, 61 insertions(+), 13 deletions(-)

diff --git a/src/app.rs b/src/app.rs
index 388347a..9290dce 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -703,6 +703,7 @@ pub struct State {
     pub origin_size: f32,
     pub camera_pivot_size: f32,
 
+    pub root_window: cce_ui::widget::Window,
     pub fs_root: FsNode,
     pub node_templates: Vec<NodeTemplate>,
     pub current_path: Vec<usize>,
@@ -2712,6 +2713,9 @@ pub(crate) fn geometry_to_spreadsheet_data(geom: &Geometry) -> (Vec<String>, Vec
             shortcut_manager,
             pending_action: None,
             exit_requested: false,
+            root_window: cce_ui::widget::Window::new(0.0, 0.0, lw, lh)
+                .with_background([0.0, 0.0, 0.0, 0.0])
+                .with_border([0.0, 0.0, 0.0, 0.0], 0.0),
             widgets,
             positions,
             splitter_layout,
@@ -2910,6 +2914,9 @@ pub(crate) fn geometry_to_spreadsheet_data(geom: &Geometry) -> (Vec<String>, Vec
         state.upload_vertices();
         state.sync_cursor_and_selection();
         state.sync_parameters_pane();
+        for w in &mut state.widgets {
+            state.root_window.add_child(w.as_ptr_mut(), &mut state.ui_context);
+        }
         state
     }
 
@@ -3777,6 +3784,7 @@ pub(crate) fn geometry_to_spreadsheet_data(geom: &Geometry) -> (Vec<String>, Vec
             self.physical_height = height;
             self.width = width as f32 / self.scale as f32;
             self.height = height as f32 / self.scale as f32;
+            self.root_window.set_rect(0.0, 0.0, self.width, self.height);
             self.wgpu_adapter.resize(width, height);
 
             let (tex, view) = self.create_depth_texture();
diff --git a/src/render.rs b/src/render.rs
index e38ef5a..9376c1e 100644
--- a/src/render.rs
+++ b/src/render.rs
@@ -55,7 +55,7 @@ impl State {
         (tex, view)
     }
 
-    pub(crate) fn collect_vertices(&self, verts: &mut Vec<Vertex>) {
+    pub(crate) fn collect_vertices(&mut self, verts: &mut Vec<Vertex>) {
         verts.clear();
         let sw = self.width;
         let sh = self.height;
@@ -100,19 +100,27 @@ impl State {
             (self.has_any_open_menu(i), base_key)
         });
 
-        let mut visited = vec![false; self.widgets.len()];
+        self.ui_context.clear_hierarchy();
+        self.root_window.clear_children(&mut self.ui_context);
         for &i in &draw_order {
-            let w = &self.widgets[i];
-            if !w.visible() {
-                continue;
-            }
-            if let Some(parent_ptr) = w.parent(&self.ui_context) {
-                if self.find_widget_index(parent_ptr).is_some() {
-                    continue;
-                }
+            if self.widgets[i].visible() {
+                self.root_window.add_child(self.widgets[i].as_ptr_mut(), &mut self.ui_context);
             }
-            self.draw_widget_recursive(i, verts, sw, sh, clip, clip_circle_val, show_cursor, node_area_y, &mut visited);
         }
+
+        let mut visited = vec![false; self.widgets.len()];
+        self.draw_element_recursive(
+            &self.root_window,
+            verts,
+            sw,
+            sh,
+            [0.0, 0.0, 0.0],
+            show_cursor,
+            node_area_y,
+            &mut visited,
+            clip,
+            clip_circle_val,
+        );
     }
 
     pub(crate) fn draw_widget_recursive(
@@ -255,7 +263,18 @@ impl State {
                 self.draw_widget_recursive(child_idx, verts, sw, sh, clip, clip_circle_val, show_cursor, node_area_y, visited);
             } else {
                 unsafe {
-                    self.draw_element_recursive(&*child_ptr, verts, sw, sh, active_clip_circle);
+                    self.draw_element_recursive(
+                        &*child_ptr,
+                        verts,
+                        sw,
+                        sh,
+                        active_clip_circle,
+                        show_cursor,
+                        node_area_y,
+                        visited,
+                        clip,
+                        clip_circle_val,
+                    );
                 }
             }
         }
@@ -293,11 +312,21 @@ impl State {
         sw: f32,
         sh: f32,
         active_clip_circle: [f32; 3],
+        show_cursor: bool,
+        node_area_y: f32,
+        visited: &mut [bool],
+        clip: (f32, f32, f32, f32),
+        clip_circle_val: [f32; 3],
     ) {
         if !element.visible() {
             return;
         }
 
+        if let Some(idx) = self.find_widget_index(element.as_ptr()) {
+            self.draw_widget_recursive(idx, verts, sw, sh, clip, clip_circle_val, show_cursor, node_area_y, visited);
+            return;
+        }
+
         push_widget_vertices(element, sw, sh, active_clip_circle, verts);
 
         for (qx, qy, qw, qh, qc) in element.extra_quads() {
@@ -306,7 +335,18 @@ impl State {
 
         for child_ptr in element.children(&self.ui_context) {
             unsafe {
-                self.draw_element_recursive(&*child_ptr, verts, sw, sh, active_clip_circle);
+                self.draw_element_recursive(
+                    &*child_ptr,
+                    verts,
+                    sw,
+                    sh,
+                    active_clip_circle,
+                    show_cursor,
+                    node_area_y,
+                    visited,
+                    clip,
+                    clip_circle_val,
+                );
             }
         }
     }