From 14740d0cc13cb1dba9b333f1c21227216a88bd81 Mon Sep 17 00:00:00 2001 From: bunnie Date: Tue, 29 Apr 2025 03:01:29 +0800 Subject: [PATCH] add a numeric-priority mode to the OSK if the pre-populated field looks numeric, prioritize numbers over letters for the OSK. --- libs/ux-api/src/widgets/textentry.rs | 59 +++++++++++++++++++++++++ libs/ux-api/src/widgets/textentry/en.rs | 47 +++++++++++++++----- 2 files changed, 96 insertions(+), 10 deletions(-) diff --git a/libs/ux-api/src/widgets/textentry.rs b/libs/ux-api/src/widgets/textentry.rs index 049915741..8abbc9e39 100644 --- a/libs/ux-api/src/widgets/textentry.rs +++ b/libs/ux-api/src/widgets/textentry.rs @@ -47,6 +47,7 @@ pub struct TextEntry { osk_active: bool, osk_entry: String, osk_cursor: usize, + osk_is_numeric: bool, max_field_amount: u32, } @@ -66,6 +67,8 @@ impl Default for TextEntry { osk.add_item(col_num, row); } } + // set the cursor on 't' + osk.set_selected(1, 1).ok(); } _ => unimplemented!("OSK matrix not yet implemented for language target"), } @@ -75,6 +78,7 @@ impl Default for TextEntry { osk_entry: String::new(), osk_cursor: 0, osk_active: false, + osk_is_numeric: false, action_conn: Default::default(), action_opcode: Default::default(), validator: Default::default(), @@ -105,6 +109,41 @@ impl TextEntry { te } + fn set_osk_numeric(&mut self) { + self.osk_is_numeric = true; + self.osk.clear(); + match locales::LANG { + "en" => { + let osk_matrix = en::OSK_NUM_MATRIX; + for (col_num, col) in osk_matrix.iter().enumerate() { + for row in col { + self.osk.add_item(col_num, row); + } + } + self.osk.set_selected(1, 1).ok(); + } + _ => unimplemented!("OSK matrix not yet implemented for language target"), + } + } + + fn set_osk_regular(&mut self) { + self.osk_is_numeric = false; + self.osk.clear(); + match locales::LANG { + "en" => { + let osk_matrix = en::OSK_MATRIX; + for (col_num, col) in osk_matrix.iter().enumerate() { + for row in col { + self.osk.add_item(col_num, row); + } + } + // set the cursor on 't' + self.osk.set_selected(1, 1).ok(); + } + _ => unimplemented!("OSK matrix not yet implemented for language target"), + } + } + pub fn reset_action_payloads(&mut self, fields: u32, placeholders: Option<[Option<(String, bool)>; 10]>) { let mut payload = vec![TextEntryPayload::default(); fields as usize]; @@ -214,6 +253,26 @@ impl ActionApi for TextEntry { // selected a field to go into osk mode self.osk_entry = self.items.get_selected().to_owned(); self.osk_cursor = self.osk_entry.chars().count(); // park the cursor at the end + // check what entry type to use + let index = self.items.get_selected_index().1; + if let Some(placeholder) = &self.action_payloads[index].placeholder { + let is_float_chars = + placeholder.chars().all(|c| c.is_ascii_digit() || c == '.' || c == '-'); + if is_float_chars { + if !self.osk_is_numeric { + self.set_osk_numeric(); + } + } else { + if self.osk_is_numeric { + self.set_osk_regular(); + } + } + } else { + if self.osk_is_numeric { + self.set_osk_regular(); + } + } + self.osk_active = true; None } diff --git a/libs/ux-api/src/widgets/textentry/en.rs b/libs/ux-api/src/widgets/textentry/en.rs index 3b1b20f49..2b68424a8 100644 --- a/libs/ux-api/src/widgets/textentry/en.rs +++ b/libs/ux-api/src/widgets/textentry/en.rs @@ -28,19 +28,19 @@ Then format with ChatGPT using this exact query: Take this matrix of characters: -p b v k j x +p b v k g m e t a o i n -s h r d l c -u m w f g y +s h r d l u +c x w f j y q z . , ! ' " ? ( ) : @ / & = + ⬅ 1 2 3 4 5 6 7 8 9 0 ; - -P B V K J X +P B V K G M E T A O I N -S H R D L C -U M W F G Y +S H R D L U +C X W F J Y Q Z _ < > ~ * \ [ ] { } | ^ $ # % ` @@ -51,10 +51,37 @@ suitable for use as a pub const in a header file. */ pub const OSK_MATRIX: [[&'static str; 16]; 6] = [ - ["p", "e", "s", "u", "q", "'", "@", "1", "7", "P", "E", "S", "U", "Q", "*", "|"], - ["b", "t", "h", "m", "z", "\"", "/", "2", "8", "B", "T", "H", "M", "Z", "\\", "^"], + ["p", "e", "s", "c", "q", "'", "@", "1", "7", "P", "E", "S", "C", "Q", "*", "|"], + ["b", "t", "h", "x", "z", "\"", "/", "2", "8", "B", "T", "H", "X", "Z", "\\", "^"], ["v", "a", "r", "w", ".", "?", "&", "3", "9", "V", "A", "R", "W", "_", "[", "$"], ["k", "o", "d", "f", ",", "(", "=", "4", "0", "K", "O", "D", "F", "<", "]", "#"], - ["j", "i", "l", "g", " ", ")", "+", "5", ";", "J", "I", "L", "G", ">", "{", "%"], - ["x", "n", "c", "y", "!", ":", "⬅", "6", "-", "X", "N", "C", "Y", "~", "}", "`"], + ["g", "i", "l", "j", " ", ")", "+", "5", ";", "G", "I", "L", "J", ">", "{", "%"], + ["m", "n", "u", "y", "!", ":", "⬅", "6", "-", "M", "N", "U", "Y", "~", "}", "`"], +]; + +/* + 1 2 3 4 5 6 + 7 8 9 0 . - + ⬅ b v k g m + e t a o i n + s h r d l u + c p w f j y + q z x , ! + ' " ? ( ) : + @ / & = + ; + P B V K G M + E T A O I N + S H R D L U + C X W F J Y + Q Z _ < > ~ + * \ [ ] { } + | ^ $ # % ` +*/ +pub const OSK_NUM_MATRIX: [[&'static str; 16]; 6] = [ + ["1", "7", "⬅", "e", "s", "c", "q", "'", "@", "P", "E", "S", "C", "Q", "*", "|"], + ["2", "8", "b", "t", "h", "p", "z", "\"", "/", "B", "T", "H", "X", "Z", "\\", "^"], + ["3", "9", "v", "a", "r", "w", "x", "?", "&", "V", "A", "R", "W", "_", "[", "$"], + ["4", "0", "k", "o", "d", "f", ",", "(", "=", "K", "O", "D", "F", "<", "]", "#"], + ["5", ".", "g", "i", "l", "j", " ", ")", "+", "G", "I", "L", "J", ">", "{", "%"], + ["6", "-", "m", "n", "u", "y", "!", ":", ";", "M", "N", "U", "Y", "~", "}", "`"], ];