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

commite8b44fc2b7ca00c355afac206063ceb2f874da67
parent17257c8dc3
authorLucas Galante <[email protected]>
date2026-07-01 17:57
Add Delete key option to TreeList context menu

 src/widget/container/treelist.rs | 16 ++++++++++++++++
 src/widget/core.rs               |  3 +++
 src/widget/mod.rs                |  1 +
 3 files changed, 20 insertions(+)

diff --git a/src/widget/container/treelist.rs b/src/widget/container/treelist.rs
index 14660f8..fab1b2a 100644
--- a/src/widget/container/treelist.rs
+++ b/src/widget/container/treelist.rs
@@ -131,6 +131,7 @@ pub struct TreeList {
     pub children: Vec<*mut (dyn Element + 'static)>,
     pub last_scroll_y: f32,
     pub scrollbar_activity_timer: f32,
+    pub deleted_key_path: Option<String>,
 }
 
 impl TreeList {
@@ -150,6 +151,7 @@ impl TreeList {
             children: Vec::new(),
             last_scroll_y: 0.0,
             scrollbar_activity_timer: 0.0,
+            deleted_key_path: None,
         }
     }
 
@@ -188,6 +190,10 @@ impl TreeList {
         self.clicked_item.take()
     }
 
+    pub fn take_deleted_key_path(&mut self) -> Option<String> {
+        self.deleted_key_path.take()
+    }
+
     pub fn check_scroll_activity(&mut self, ctx: &mut UiContext) {
         if (self.scroll_box.scroll_y - self.last_scroll_y).abs() > 0.01 {
             self.scrollbar_activity_timer = 1.0;
@@ -338,6 +344,7 @@ impl Element for TreeList {
                                 path.clone(),
                                 "Copy Key".to_string(),
                                 "Copy Value".to_string(),
+                                "Delete".to_string(),
                             ];
                             let scroll_offset = crate::widget::hover_animation::get_scroll_offset();
                             ctx.show_context_menu(px, py - scroll_offset, options, 1, self.as_ptr_mut());
@@ -775,6 +782,15 @@ impl Element for TreeList {
         }
     }
 
+    fn delete_key(&mut self) {
+        if let Some(idx) = self.selected_key_idx {
+            if idx < self.flat_keys.len() {
+                let key_path = self.flat_keys[idx].0.clone();
+                self.deleted_key_path = Some(key_path);
+            }
+        }
+    }
+
     fn expand_node(&mut self) {
         if let Some(path) = self.right_clicked_section.clone() {
             self.collapsed_sections.remove(&path);
diff --git a/src/widget/core.rs b/src/widget/core.rs
index 5e29f3a..a351e84 100644
--- a/src/widget/core.rs
+++ b/src/widget/core.rs
@@ -552,6 +552,9 @@ pub mod context_menu {
                                         "Copy Value" => {
                                             target.copy_value();
                                         }
+                                        "Delete" => {
+                                            target.delete_key();
+                                        }
                                         "Expand" => {
                                             target.expand_node();
                                         }
diff --git a/src/widget/mod.rs b/src/widget/mod.rs
index 0d37273..08ba79b 100644
--- a/src/widget/mod.rs
+++ b/src/widget/mod.rs
@@ -299,6 +299,7 @@ pub trait Element {
     fn select_all(&mut self) {}
     fn copy_key(&self) {}
     fn copy_value(&self) {}
+    fn delete_key(&mut self) {}
     fn expand_node(&mut self) {}
     fn collapse_node(&mut self) {}
     fn expand_all_nodes(&mut self) {}