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

commite050d6a4a1a8a0d56187f82164a30ede1ee6d45f
parentc711071264
authorLucas Galante <[email protected]>
date2026-07-03 01:37
Added Cear option to search TextBox context menu

 src/context.rs               | 10 ++++++++++
 src/widget/core.rs           |  3 +++
 src/widget/input/text_box.rs | 25 +++++++++++++++++++++++++
 src/widget/mod.rs            |  1 +
 4 files changed, 39 insertions(+)

diff --git a/src/context.rs b/src/context.rs
index 41f46cd..5d4afd2 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -803,6 +803,16 @@ impl UiContext {
 
         if name == "TextBox" {
             options.extend(vec!["Cut".to_string(), "Copy".to_string(), "Paste".to_string(), "Select All".to_string()]);
+            let is_search = unsafe {
+                if let Some(tb) = (*target).as_any().downcast_ref::<crate::widget::input::TextBox>() {
+                    tb.placeholder.as_deref() == Some("Search...")
+                } else {
+                    false
+                }
+            };
+            if is_search {
+                options.push("Cear".to_string());
+            }
         } else {
             options.extend(vec!["Copy".to_string(), "Paste".to_string()]);
         }
diff --git a/src/widget/core.rs b/src/widget/core.rs
index a351e84..9e852db 100644
--- a/src/widget/core.rs
+++ b/src/widget/core.rs
@@ -546,6 +546,9 @@ pub mod context_menu {
                                         "Select All" => {
                                             target.select_all();
                                         }
+                                        "Cear" => {
+                                            target.clear_text();
+                                        }
                                         "Copy Key" => {
                                             target.copy_key();
                                         }
diff --git a/src/widget/input/text_box.rs b/src/widget/input/text_box.rs
index ce479e2..418db06 100644
--- a/src/widget/input/text_box.rs
+++ b/src/widget/input/text_box.rs
@@ -605,6 +605,10 @@ impl Element for TextBox {
         self.select_all();
     }
 
+    fn clear_text(&mut self) {
+        self.set_value_string("");
+    }
+
     fn preferred_height(&self) -> Option<f32> {
         Some(crate::layout::textbox_height())
     }
@@ -1660,5 +1664,26 @@ mod tests {
         
         crate::layout::set_textbox_line_wrap(true);
     }
+
+    #[test]
+    fn test_search_textbox_cear_option() {
+        let mut dummy = crate::context::UiContext::new();
+        let mut tb = TextBox::new("Some Search query".to_string()).with_placeholder("Search...");
+        tb.set_rect(10.0, 10.0, 200.0, 30.0);
+
+        // Right click on textbox
+        let clicked = tb.mouse_input(MouseButton::Right, ElementState::Pressed, 50.0, 20.0, &mut dummy);
+        assert!(clicked);
+        assert!(dummy.is_context_menu_visible());
+
+        // Verify "Cear" option is in options
+        let opts = crate::widget::context_menu::options();
+        assert!(opts.contains(&"Cear".to_string()));
+
+        // Simulate choosing the "Cear" option
+        tb.clear_text();
+        assert_eq!(tb.text, "");
+        assert_eq!(tb.edit_buffer, "");
+    }
 }
 
diff --git a/src/widget/mod.rs b/src/widget/mod.rs
index af691e0..0eab028 100644
--- a/src/widget/mod.rs
+++ b/src/widget/mod.rs
@@ -297,6 +297,7 @@ pub trait Element {
         }
     }
     fn select_all(&mut self) {}
+    fn clear_text(&mut self) {}
     fn copy_key(&self) {}
     fn copy_value(&self) {}
     fn delete_key(&mut self) {}