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

commitc4cd3517249fa94f0233d0f69136b5d91bb0889d
parent4f976461c7
authorLucas Galante <[email protected]>
date2026-05-28 17:42
feat: add password masking support to TextBox

 src/widget.rs | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/widget.rs b/src/widget.rs
index d9771d1..ec573f7 100644
--- a/src/widget.rs
+++ b/src/widget.rs
@@ -4781,6 +4781,7 @@ pub struct TextBox {
     pub children: Vec<*mut (dyn Widget + 'static)>,
     pub max_width: Option<f32>,
     pub width: Option<f32>,
+    pub is_password: bool,
 }
 
 impl TextBox {
@@ -4806,9 +4807,15 @@ impl TextBox {
             children: Vec::new(),
             max_width: Some(300.0),
             width: None,
+            is_password: false,
         }
     }
 
+    pub fn with_password(mut self, is_password: bool) -> Self {
+        self.is_password = is_password;
+        self
+    }
+
     pub fn with_label(mut self, label: &str) -> Self {
         self.label = Some(label.to_string());
         self
@@ -5463,11 +5470,14 @@ impl Widget for TextBox {
                 color: [0x83, 0x83, 0x8a],
             });
         }
-        let val_text = if self.editing {
+        let mut val_text = if self.editing {
             self.edit_buffer.clone()
         } else {
             self.text.clone()
         };
+        if self.is_password {
+            val_text = "•".repeat(val_text.chars().count());
+        }
         labels.push(TextLabel {
             text: val_text,
             x: self.x + 8.0,