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

commitd7584553c252ca9d84c312e63e4545ed1555cb06
parent82b14e3a51
authorLucas Galante <[email protected]>
date2026-05-26 21:18
Update system configuration and interface modules

 src/main.rs | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/src/main.rs b/src/main.rs
index fda8edd..0d5f513 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4934,6 +4934,29 @@ fn geometry_to_spreadsheet_data(geom: &Geometry) -> (Vec<String>, Vec<Vec<String
     }
 }
 
+struct PressedKey {
+    logical_key: clear_ui::widget::Key,
+    text: Option<String>,
+    first_pressed: std::time::Instant,
+    last_repeated: std::time::Instant,
+}
+
+fn is_repeatable_key(key: &clear_ui::widget::Key) -> bool {
+    use clear_ui::widget::{Key, NamedKey};
+    match key {
+        Key::Named(NamedKey::Backspace) |
+        Key::Named(NamedKey::Delete) |
+        Key::Named(NamedKey::ArrowLeft) |
+        Key::Named(NamedKey::ArrowRight) |
+        Key::Named(NamedKey::ArrowUp) |
+        Key::Named(NamedKey::ArrowDown) |
+        Key::Named(NamedKey::Home) |
+        Key::Named(NamedKey::End) |
+        Key::Character(_) => true,
+        _ => false,
+    }
+}
+
 struct AppState {
     registry_state: RegistryState,
     compositor_state: CompositorState,
@@ -4952,6 +4975,7 @@ struct AppState {
     state: Option<State>,
     exit: bool,
     redraw: bool,
+    pressed_key: Option<PressedKey>,
 }
 
 impl CompositorHandler for AppState {
@@ -5311,8 +5335,28 @@ impl AppState {
                 text: event.utf8.clone(),
                 repeat: false,
                 ctrl: st.modifiers.ctrl,
+                shift: st.modifiers.shift,
             };
 
+            if state == clear_ui::widget::ElementState::Pressed {
+                if is_repeatable_key(&custom_event.logical_key) {
+                    self.pressed_key = Some(PressedKey {
+                        logical_key: custom_event.logical_key.clone(),
+                        text: custom_event.text.clone(),
+                        first_pressed: std::time::Instant::now(),
+                        last_repeated: std::time::Instant::now(),
+                    });
+                } else {
+                    self.pressed_key = None;
+                }
+            } else if state == clear_ui::widget::ElementState::Released {
+                if let Some(ref pk) = self.pressed_key {
+                    if pk.logical_key == custom_event.logical_key {
+                        self.pressed_key = None;
+                    }
+                }
+            }
+
             let ev = WindowEvent::KeyboardInput { event: custom_event };
             self.process_event(ev);
         }
@@ -5818,6 +5862,7 @@ fn main() {
         state: None,
         exit: false,
         redraw: true,
+        pressed_key: None,
     };
 
     // Perform a roundtrip to populate output_state with active output scales
@@ -6004,6 +6049,9 @@ fn main() {
         }
     }).unwrap();
 
+    const KEY_REPEAT_DELAY: std::time::Duration = std::time::Duration::from_millis(500);
+    const KEY_REPEAT_INTERVAL: std::time::Duration = std::time::Duration::from_millis(50);
+
     loop {
         let timeout = if app.redraw {
             std::time::Duration::from_millis(0)
@@ -6016,6 +6064,27 @@ fn main() {
             break;
         }
 
+        if let Some(ref mut pk) = app.pressed_key {
+            let now = std::time::Instant::now();
+            if now.duration_since(pk.first_pressed) >= KEY_REPEAT_DELAY {
+                if now.duration_since(pk.last_repeated) >= KEY_REPEAT_INTERVAL {
+                    pk.last_repeated = now;
+                    if let Some(st) = &mut app.state {
+                        let custom_event = clear_ui::widget::KeyEvent {
+                            state: clear_ui::widget::ElementState::Pressed,
+                            logical_key: pk.logical_key.clone(),
+                            text: pk.text.clone(),
+                            repeat: true,
+                            ctrl: st.modifiers.ctrl,
+                            shift: st.modifiers.shift,
+                        };
+                        let ev = WindowEvent::KeyboardInput { event: custom_event };
+                        app.process_event(ev);
+                    }
+                }
+            }
+        }
+
         if app.redraw {
             app.redraw = false;
             if let Some(state) = &mut app.state {